forked from plutov/paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
billing_test.go
108 lines (105 loc) · 2.48 KB
/
billing_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package paypalsdk_test
import (
"fmt"
"time"
pp "github.com/logpacker/PayPal-Go-SDK"
)
func BillingExample() {
plan := pp.BillingPlan{
Name: "Plan with Regular and Trial Payment Definitions",
Description: "Plan with regular and trial payment definitions.",
Type: "fixed",
PaymentDefinitions: []pp.PaymentDefinition{
pp.PaymentDefinition{
Name: "Regular payment definition",
Type: "REGULAR",
Frequency: "MONTH",
FrequencyInterval: "2",
Amount: pp.AmountPayout{
Value: "100",
Currency: "USD",
},
Cycles: "12",
ChargeModels: []pp.ChargeModel{
pp.ChargeModel{
Type: "SHIPPING",
Amount: pp.AmountPayout{
Value: "10",
Currency: "USD",
},
},
pp.ChargeModel{
Type: "TAX",
Amount: pp.AmountPayout{
Value: "12",
Currency: "USD",
},
},
},
},
pp.PaymentDefinition{
Name: "Trial payment definition",
Type: "trial",
Frequency: "week",
FrequencyInterval: "5",
Amount: pp.AmountPayout{
Value: "9.19",
Currency: "USD",
},
Cycles: "2",
ChargeModels: []pp.ChargeModel{
pp.ChargeModel{
Type: "SHIPPING",
Amount: pp.AmountPayout{
Value: "1",
Currency: "USD",
},
},
pp.ChargeModel{
Type: "TAX",
Amount: pp.AmountPayout{
Value: "2",
Currency: "USD",
},
},
},
},
},
MerchantPreferences: &pp.MerchantPreferences{
SetupFee: &pp.AmountPayout{
Value: "1",
Currency: "USD",
},
ReturnURL: "http://www.paypal.com",
CancelURL: "http://www.paypal.com/cancel",
AutoBillAmount: "YES",
InitialFailAmountAction: "CONTINUE",
MaxFailAttempts: "0",
},
}
c, err := pp.NewClient("clientID", "secretID", pp.APIBaseSandBox)
if err != nil {
panic(err)
}
_, err = c.GetAccessToken()
if err != nil {
panic(err)
}
planResp, err := c.CreateBillingPlan(plan)
if err != nil {
panic(err)
}
err = c.ActivatePlan(planResp.ID)
fmt.Println(err)
agreement := pp.BillingAgreement{
Name: "Fast Speed Agreement",
Description: "Agreement for Fast Speed Plan",
StartDate: pp.JSONTime(time.Now().Add(time.Hour * 24)),
Plan: pp.BillingPlan{ID: planResp.ID},
Payer: pp.Payer{
PaymentMethod: "paypal",
},
}
resp, err := c.CreateBillingAgreement(agreement)
fmt.Println(err, resp)
}