forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscription_integration_test.go
94 lines (81 loc) · 1.81 KB
/
subscription_integration_test.go
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
87
88
89
90
91
92
93
94
package braintree
import (
"testing"
)
// This test will fail unless you set up your Braintree sandbox account correctly. See TESTING.md for details.
func TestSubscription(t *testing.T) {
customer, err := testGateway.Customer().Create(&Customer{
FirstName: "Lionel",
LastName: "Barrow",
Company: "Braintree",
Email: "[email protected]",
Phone: "312.555.1234",
Fax: "614.555.5678",
Website: "http://www.example.com",
CreditCard: &CreditCard{
Number: testCreditCards["visa"].Number,
ExpirationDate: "05/14",
},
})
if err != nil {
t.Fatal(err)
}
t.Log(customer)
g := testGateway.Subscription()
token := customer.CreditCards.CreditCard[0].Token
if token == "" {
t.Fatal("invalid payment method token")
} else {
t.Log(token)
}
// Create
sub, err := g.Create(&Subscription{
PaymentMethodToken: token,
PlanId: "test_plan",
Options: &SubscriptionOptions{
ProrateCharges: true,
RevertSubscriptionOnProrationFailure: true,
StartImmediately: true,
},
})
t.Log("sub1", sub)
if err != nil {
t.Fatal(err)
}
if sub.Id == "" {
t.Fatal("invalid subscription id")
}
// Update
sub2, err := g.Update(&Subscription{
Id: sub.Id,
PlanId: "test_plan_2",
Options: &SubscriptionOptions{
ProrateCharges: true,
RevertSubscriptionOnProrationFailure: true,
StartImmediately: true,
},
})
t.Log("sub2", sub2)
if err != nil {
t.Fatal(err)
}
if sub2.Id != sub.Id {
t.Fatal(sub2.Id)
}
if x := sub2.PlanId; x != "test_plan_2" {
t.Fatal(x)
}
// Find
sub3, err := g.Find(sub.Id)
if err != nil {
t.Fatal(err)
}
if sub3.Id != sub2.Id {
t.Fatal(sub3.Id)
}
// Cancel
_, err = g.Cancel(sub2.Id)
if err != nil {
t.Fatal(err)
}
}