GoDoc example for CreatePayment

This commit is contained in:
Aliaksandr Pliutau 2016-03-07 13:00:22 +07:00
parent 172960ac0a
commit 8ad0c93758
3 changed files with 53 additions and 1 deletions

View File

@ -1,6 +1,7 @@
language: go language: go
go: go:
- 1.5 - 1.5
- 1.6
install: install:
- export PATH=$PATH:$HOME/gopath/bin - export PATH=$PATH:$HOME/gopath/bin
script: script:

2
doc.go
View File

@ -1,6 +1,6 @@
/* /*
Package paypalsdk provides a warepper to PayPal API (https://developer.paypal.com/webapps/developer/docs/api/). 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) c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
Then you can get an access token from PayPal: Then you can get an access token from PayPal:
accessToken, err := c.GetAccessToken() accessToken, err := c.GetAccessToken()

51
doc_test.go Normal file
View 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)
}
}