paypale/example_test.go

52 lines
1.1 KiB
Go
Raw Permalink Normal View History

2016-03-07 07:00:22 +01:00
package paypalsdk_test
2016-03-07 07:12:38 +01:00
import paypalsdk "github.com/logpacker/PayPal-Go-SDK"
2016-03-07 07:00:22 +01:00
2016-03-07 07:12:38 +01:00
func Example() {
2016-03-07 07:00:22 +01:00
// Initialize client
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
if err != nil {
panic(err)
}
2016-12-22 06:12:47 +01:00
// Retrieve access token
2016-03-07 07:00:22 +01:00
_, err = c.GetAccessToken()
if err != nil {
panic(err)
}
// Create credit card payment
p := paypalsdk.Payment{
Intent: "sale",
Payer: &paypalsdk.Payer{
PaymentMethod: "credit_card",
2016-12-22 06:16:22 +01:00
FundingInstruments: []paypalsdk.FundingInstrument{{
2016-03-07 07:00:22 +01:00
CreditCard: &paypalsdk.CreditCard{
Number: "4111111111111111",
Type: "visa",
ExpireMonth: "11",
ExpireYear: "2020",
CVV2: "777",
FirstName: "John",
LastName: "Doe",
},
}},
},
2016-12-22 06:16:22 +01:00
Transactions: []paypalsdk.Transaction{{
2016-03-07 07:00:22 +01:00
Amount: &paypalsdk.Amount{
Currency: "USD",
Total: "7.00",
},
Description: "My Payment",
}},
RedirectURLs: &paypalsdk.RedirectURLs{
ReturnURL: "http://...",
CancelURL: "http://...",
},
}
_, err = c.CreatePayment(p)
if err != nil {
panic(err)
}
}