From 8ad0c9375866392412052af83bec360dff80c320 Mon Sep 17 00:00:00 2001 From: Aliaksandr Pliutau Date: Mon, 7 Mar 2016 13:00:22 +0700 Subject: [PATCH] GoDoc example for CreatePayment --- .travis.yml | 1 + doc.go | 2 +- doc_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 doc_test.go diff --git a/.travis.yml b/.travis.yml index b87eb9d..1fcace3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: go go: - 1.5 + - 1.6 install: - export PATH=$PATH:$HOME/gopath/bin script: diff --git a/doc.go b/doc.go index 4170a81..e273d57 100644 --- a/doc.go +++ b/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() diff --git a/doc_test.go b/doc_test.go new file mode 100644 index 0000000..d884f00 --- /dev/null +++ b/doc_test.go @@ -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) + } +}