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