paypale/example_test.go

60 lines
1.3 KiB
Go
Raw Permalink Normal View History

2019-08-21 15:50:20 +02:00
package paypal_test
2016-03-07 07:00:22 +01:00
2021-01-03 10:28:52 +01:00
import (
"context"
"github.com/plutov/paypal/v4"
)
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
2019-08-21 15:50:20 +02:00
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
2016-03-07 07:00:22 +01:00
if err != nil {
panic(err)
}
2016-12-22 06:12:47 +01:00
// Retrieve access token
2021-01-03 10:28:52 +01:00
_, err = c.GetAccessToken(context.Background())
2016-03-07 07:00:22 +01:00
if err != nil {
panic(err)
}
}
func ExampleClient_CreatePayout_Venmo() {
// Initialize client
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
if err != nil {
panic(err)
}
// Retrieve access token
2021-01-03 10:28:52 +01:00
_, err = c.GetAccessToken(context.Background())
if err != nil {
panic(err)
}
// Set payout item with Venmo wallet
payout := paypal.Payout{
SenderBatchHeader: &paypal.SenderBatchHeader{
SenderBatchID: "Payouts_2018_100007",
EmailSubject: "You have a payout!",
EmailMessage: "You have received a payout! Thanks for using our service!",
},
Items: []paypal.PayoutItem{
{
RecipientType: "EMAIL",
RecipientWallet: paypal.VenmoRecipientWallet,
Receiver: "receiver@example.com",
Amount: &paypal.AmountPayout{
Value: "9.87",
Currency: "USD",
},
Note: "Thanks for your patronage!",
SenderItemID: "201403140001",
},
},
}
c.CreatePayout(context.Background(), payout)
}