SubscriptionHelper.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Test\Integration;
  3. use Braintree;
  4. class SubscriptionHelper
  5. {
  6. public static function addOnDiscountPlan()
  7. {
  8. return [
  9. 'description' => "Plan for integration tests -- with add-ons and discounts",
  10. 'id' => "integration_plan_with_add_ons_and_discounts",
  11. 'price' => '9.99',
  12. 'trial_period' => true,
  13. 'trial_duration' => 2,
  14. 'trial_duration_unit' => 'day'
  15. ];
  16. }
  17. public static function billingDayOfMonthPlan()
  18. {
  19. return [
  20. 'description' => 'Plan for integration tests -- with billing day of month',
  21. 'id' => 'integration_plan_with_billing_day_of_month',
  22. 'numberOfBillingCycles' => 5,
  23. 'price' => '8.88',
  24. 'trial_period' => false
  25. ];
  26. }
  27. public static function trialPlan()
  28. {
  29. return [
  30. 'description' => 'Plan for integration tests -- with trial',
  31. 'id' => 'integration_trial_plan',
  32. 'numberOfBillingCycles' => 12,
  33. 'price' => '43.21',
  34. 'trial_period' => true,
  35. 'trial_duration' => 2,
  36. 'trial_duration_unit' => 'day'
  37. ];
  38. }
  39. public static function triallessPlan()
  40. {
  41. return [
  42. 'description' => 'Plan for integration tests -- without a trial',
  43. 'id' => 'integration_trialless_plan',
  44. 'numberOfBillingCycles' => 12,
  45. 'price' => '12.34',
  46. 'trial_period' => false
  47. ];
  48. }
  49. public static function createCreditCard()
  50. {
  51. $customer = Braintree\Customer::createNoValidate([
  52. 'creditCard' => [
  53. 'number' => '5105105105105100',
  54. 'expirationDate' => '05/2010'
  55. ]
  56. ]);
  57. return $customer->creditCards[0];
  58. }
  59. public static function createSubscription()
  60. {
  61. $plan = self::triallessPlan();
  62. $result = Braintree\Subscription::create([
  63. 'paymentMethodToken' => self::createCreditCard()->token,
  64. 'price' => '54.99',
  65. 'planId' => $plan['id']
  66. ]);
  67. return $result->subscription;
  68. }
  69. public static function compareModificationsById($left, $right)
  70. {
  71. return strcmp($left->id, $right->id);
  72. }
  73. public static function sortModificationsById(&$modifications)
  74. {
  75. usort($modifications, ['Test\Integration\SubscriptionHelper', 'compareModificationsById']);
  76. }
  77. }