forked from go-packages/paypal
GoDoc example for CreatePayment
This commit is contained in:
parent
172960ac0a
commit
8ad0c93758
|
@ -1,6 +1,7 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.5
|
||||
- 1.6
|
||||
install:
|
||||
- export PATH=$PATH:$HOME/gopath/bin
|
||||
script:
|
||||
|
|
2
doc.go
2
doc.go
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Package paypalsdk provides a warepper to PayPal API (https://developer.paypal.com/webapps/developer/docs/api/).
|
||||
The first thing you do is to create a Client (you can select API base URL using paypalsdk contsnts).
|
||||
The first thing you do is to create a Client (you can select API base URL using paypalsdk contants).
|
||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
||||
Then you can get an access token from PayPal:
|
||||
accessToken, err := c.GetAccessToken()
|
||||
|
|
51
doc_test.go
Normal file
51
doc_test.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package paypalsdk_test
|
||||
|
||||
import "github.com/logpacker/PayPal-Go-SDK"
|
||||
|
||||
func ExampleCreatePayment() {
|
||||
// Initialize client
|
||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Retreive access token
|
||||
_, err = c.GetAccessToken()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create credit card payment
|
||||
p := paypalsdk.Payment{
|
||||
Intent: "sale",
|
||||
Payer: &paypalsdk.Payer{
|
||||
PaymentMethod: "credit_card",
|
||||
FundingInstruments: []paypalsdk.FundingInstrument{paypalsdk.FundingInstrument{
|
||||
CreditCard: &paypalsdk.CreditCard{
|
||||
Number: "4111111111111111",
|
||||
Type: "visa",
|
||||
ExpireMonth: "11",
|
||||
ExpireYear: "2020",
|
||||
CVV2: "777",
|
||||
FirstName: "John",
|
||||
LastName: "Doe",
|
||||
},
|
||||
}},
|
||||
},
|
||||
Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user