PlanTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Test\Integration;
  3. require_once dirname(__DIR__) . '/Setup.php';
  4. use Test\Setup;
  5. use Test\Helper;
  6. use Braintree;
  7. class PlanTest extends Setup
  8. {
  9. public function testAll_withNoPlans_returnsEmptyArray()
  10. {
  11. Helper::testMerchantConfig();
  12. $plans = Braintree\Plan::all();
  13. $this->assertEquals($plans, []);
  14. self::integrationMerchantConfig();
  15. }
  16. public function testAll_returnsAllPlans()
  17. {
  18. $newId = strval(rand());
  19. $params = [
  20. "id" => $newId,
  21. "billingDayOfMonth" => "1",
  22. "billingFrequency" => "1",
  23. "currencyIsoCode" => "USD",
  24. "description" => "some description",
  25. "name" => "php test plan",
  26. "numberOfBillingCycles" => "1",
  27. "price" => "1.00",
  28. "trialPeriod" => "false"
  29. ];
  30. $http = new Braintree\Http(Braintree\Configuration::$global);
  31. $path = Braintree\Configuration::$global->merchantPath() . '/plans/create_plan_for_tests';
  32. $http->post($path, ["plan" => $params]);
  33. $addOnParams = [
  34. "kind" => "add_on",
  35. "plan_id" => $newId,
  36. "amount" => "1.00",
  37. "name" => "add_on_name"
  38. ];
  39. $http = new Braintree\Http(Braintree\Configuration::$global);
  40. $path = Braintree\Configuration::$global->merchantPath() . '/modifications/create_modification_for_tests';
  41. $http->post($path, ['modification' => $addOnParams]);
  42. $discountParams = [
  43. "kind" => "discount",
  44. "plan_id" => $newId,
  45. "amount" => "1.00",
  46. "name" => "discount_name"
  47. ];
  48. $http = new Braintree\Http(Braintree\Configuration::$global);
  49. $path = Braintree\Configuration::$global->merchantPath() . '/modifications/create_modification_for_tests';
  50. $http->post($path, ["modification" => $discountParams]);
  51. $plans = Braintree\Plan::all();
  52. foreach ($plans as $plan)
  53. {
  54. if ($plan->id == $newId)
  55. {
  56. $actualPlan = $plan;
  57. }
  58. }
  59. $this->assertNotNull($actualPlan);
  60. $this->assertEquals($params["billingDayOfMonth"], $actualPlan->billingDayOfMonth);
  61. $this->assertEquals($params["billingFrequency"], $actualPlan->billingFrequency);
  62. $this->assertEquals($params["currencyIsoCode"], $actualPlan->currencyIsoCode);
  63. $this->assertEquals($params["description"], $actualPlan->description);
  64. $this->assertEquals($params["name"], $actualPlan->name);
  65. $this->assertEquals($params["numberOfBillingCycles"], $actualPlan->numberOfBillingCycles);
  66. $this->assertEquals($params["price"], $actualPlan->price);
  67. $addOn = $actualPlan->addOns[0];
  68. $this->assertEquals($addOnParams["name"], $addOn->name);
  69. $discount = $actualPlan->discounts[0];
  70. $this->assertEquals($discountParams["name"], $discount->name);
  71. }
  72. public function testGatewayAll_returnsAllPlans()
  73. {
  74. $newId = strval(rand());
  75. $params = [
  76. "id" => $newId,
  77. "billingDayOfMonth" => "1",
  78. "billingFrequency" => "1",
  79. "currencyIsoCode" => "USD",
  80. "description" => "some description",
  81. "name" => "php test plan",
  82. "numberOfBillingCycles" => "1",
  83. "price" => "1.00",
  84. "trialPeriod" => "false"
  85. ];
  86. $http = new Braintree\Http(Braintree\Configuration::$global);
  87. $path = Braintree\Configuration::$global->merchantPath() . '/plans/create_plan_for_tests';
  88. $http->post($path, ["plan" => $params]);
  89. $gateway = new Braintree\Gateway([
  90. 'environment' => 'development',
  91. 'merchantId' => 'integration_merchant_id',
  92. 'publicKey' => 'integration_public_key',
  93. 'privateKey' => 'integration_private_key'
  94. ]);
  95. $plans = $gateway->plan()->all();
  96. foreach ($plans as $plan)
  97. {
  98. if ($plan->id == $newId)
  99. {
  100. $actualPlan = $plan;
  101. }
  102. }
  103. $this->assertNotNull($actualPlan);
  104. $this->assertEquals($params["billingDayOfMonth"], $actualPlan->billingDayOfMonth);
  105. $this->assertEquals($params["billingFrequency"], $actualPlan->billingFrequency);
  106. $this->assertEquals($params["currencyIsoCode"], $actualPlan->currencyIsoCode);
  107. $this->assertEquals($params["description"], $actualPlan->description);
  108. $this->assertEquals($params["name"], $actualPlan->name);
  109. $this->assertEquals($params["numberOfBillingCycles"], $actualPlan->numberOfBillingCycles);
  110. $this->assertEquals($params["price"], $actualPlan->price);
  111. }
  112. }