paypale/billing_test.go

108 lines
2.6 KiB
Go
Raw Normal View History

2017-07-27 16:46:02 +02:00
package paypalsdk_test
2017-07-20 11:07:11 +02:00
import (
2017-07-27 16:46:02 +02:00
"fmt"
pp "github.com/logpacker/PayPal-Go-SDK"
"time"
2017-07-20 11:07:11 +02:00
)
2017-08-24 16:43:41 +02:00
func BillingExample() {
2017-07-27 16:46:02 +02:00
plan := pp.BillingPlan{
2017-07-20 11:07:11 +02:00
Name: "Plan with Regular and Trial Payment Definitions",
Description: "Plan with regular and trial payment definitions.",
Type: "fixed",
2017-07-27 16:46:02 +02:00
PaymentDefinitions: []pp.PaymentDefinition{
pp.PaymentDefinition{
2017-07-20 11:07:11 +02:00
Name: "Regular payment definition",
Type: "REGULAR",
Frequency: "MONTH",
FrequencyInterval: "2",
2017-07-27 16:46:02 +02:00
Amount: pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "100",
Currency: "USD",
},
Cycles: "12",
2017-07-27 16:46:02 +02:00
ChargeModels: []pp.ChargeModel{
pp.ChargeModel{
2017-07-20 11:07:11 +02:00
Type: "SHIPPING",
2017-07-27 16:46:02 +02:00
Amount: pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "10",
Currency: "USD",
},
},
2017-07-27 16:46:02 +02:00
pp.ChargeModel{
2017-07-20 11:07:11 +02:00
Type: "TAX",
2017-07-27 16:46:02 +02:00
Amount: pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "12",
Currency: "USD",
},
},
},
},
2017-07-27 16:46:02 +02:00
pp.PaymentDefinition{
2017-07-20 11:07:11 +02:00
Name: "Trial payment definition",
Type: "trial",
Frequency: "week",
FrequencyInterval: "5",
2017-07-27 16:46:02 +02:00
Amount: pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "9.19",
Currency: "USD",
},
Cycles: "2",
2017-07-27 16:46:02 +02:00
ChargeModels: []pp.ChargeModel{
pp.ChargeModel{
2017-07-20 11:07:11 +02:00
Type: "SHIPPING",
2017-07-27 16:46:02 +02:00
Amount: pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "1",
Currency: "USD",
},
},
2017-07-27 16:46:02 +02:00
pp.ChargeModel{
2017-07-20 11:07:11 +02:00
Type: "TAX",
2017-07-27 16:46:02 +02:00
Amount: pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "2",
Currency: "USD",
},
},
},
},
},
2017-07-27 16:46:02 +02:00
MerchantPreferences: &pp.MerchantPreferences{
2017-08-24 16:43:41 +02:00
SetupFee: &pp.AmountPayout{
2017-07-20 11:07:11 +02:00
Value: "1",
Currency: "USD",
},
ReturnUrl: "http://www.paypal.com",
CancelUrl: "http://www.paypal.com/cancel",
AutoBillAmount: "YES",
InitialFailAmountAction: "CONTINUE",
MaxFailAttempts: "0",
},
}
2017-07-27 16:46:02 +02:00
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)
2017-07-20 11:07:11 +02:00
}