paypale/billing_test.go

110 lines
2.4 KiB
Go
Raw Normal View History

2019-08-21 15:50:20 +02:00
package paypal_test
2017-10-03 05:30:39 +02:00
import (
"fmt"
"time"
)
func BillingExample() {
2019-08-21 15:50:20 +02:00
plan := BillingPlan{
2017-10-03 05:30:39 +02:00
Name: "Plan with Regular and Trial Payment Definitions",
Description: "Plan with regular and trial payment definitions.",
Type: "fixed",
2019-08-21 15:50:20 +02:00
PaymentDefinitions: []PaymentDefinition{
2019-08-19 15:33:46 +02:00
{
2017-10-03 05:30:39 +02:00
Name: "Regular payment definition",
Type: "REGULAR",
Frequency: "MONTH",
FrequencyInterval: "2",
2019-08-21 15:50:20 +02:00
Amount: AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "100",
Currency: "USD",
},
Cycles: "12",
2019-08-21 15:50:20 +02:00
ChargeModels: []ChargeModel{
2019-08-19 15:33:46 +02:00
{
2017-10-03 05:30:39 +02:00
Type: "SHIPPING",
2019-08-21 15:50:20 +02:00
Amount: AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "10",
Currency: "USD",
},
},
2019-08-19 15:33:46 +02:00
{
2017-10-03 05:30:39 +02:00
Type: "TAX",
2019-08-21 15:50:20 +02:00
Amount: AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "12",
Currency: "USD",
},
},
},
},
2019-08-19 15:33:46 +02:00
{
2017-10-03 05:30:39 +02:00
Name: "Trial payment definition",
Type: "trial",
Frequency: "week",
FrequencyInterval: "5",
2019-08-21 15:50:20 +02:00
Amount: AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "9.19",
Currency: "USD",
},
Cycles: "2",
2019-08-21 15:50:20 +02:00
ChargeModels: []ChargeModel{
2019-08-19 15:33:46 +02:00
{
2017-10-03 05:30:39 +02:00
Type: "SHIPPING",
2019-08-21 15:50:20 +02:00
Amount: AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "1",
Currency: "USD",
},
},
2019-08-19 15:33:46 +02:00
{
2017-10-03 05:30:39 +02:00
Type: "TAX",
2019-08-21 15:50:20 +02:00
Amount: AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "2",
Currency: "USD",
},
},
},
},
},
2019-08-21 15:50:20 +02:00
MerchantPreferences: &MerchantPreferences{
SetupFee: &AmountPayout{
2017-10-03 05:30:39 +02:00
Value: "1",
Currency: "USD",
},
ReturnURL: "http://www.paypal.com",
CancelURL: "http://www.paypal.com/cancel",
AutoBillAmount: "YES",
InitialFailAmountAction: "CONTINUE",
MaxFailAttempts: "0",
},
}
2019-08-21 15:50:20 +02:00
c, err := NewClient("clientID", "secretID", APIBaseSandBox)
2017-10-03 05:30:39 +02:00
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)
2019-08-21 15:50:20 +02:00
agreement := BillingAgreement{
2017-10-03 05:30:39 +02:00
Name: "Fast Speed Agreement",
Description: "Agreement for Fast Speed Plan",
2019-08-21 15:50:20 +02:00
StartDate: JSONTime(time.Now().Add(time.Hour * 24)),
Plan: BillingPlan{ID: planResp.ID},
Payer: Payer{
2017-10-03 05:30:39 +02:00
PaymentMethod: "paypal",
},
}
resp, err := c.CreateBillingAgreement(agreement)
fmt.Println(err, resp)
2019-01-14 06:06:05 +01:00
2019-08-21 15:50:20 +02:00
bps, err := c.ListBillingPlans(BillingPlanListParams{Status: "ACTIVE"})
2019-01-14 06:06:05 +01:00
fmt.Println(err, bps)
2017-10-03 05:30:39 +02:00
}