github.com/plutov/paypal/v4@v4.7.1/example_test.go (about)

     1  package paypal_test
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/plutov/paypal/v4"
     7  )
     8  
     9  func Example() {
    10  	// Initialize client
    11  	c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	// Retrieve access token
    17  	_, err = c.GetAccessToken(context.Background())
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  }
    22  
    23  func ExampleClient_CreatePayout_Venmo() {
    24  	// Initialize client
    25  	c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  
    30  	// Retrieve access token
    31  	_, err = c.GetAccessToken(context.Background())
    32  	if err != nil {
    33  		panic(err)
    34  	}
    35  
    36  	// Set payout item with Venmo wallet
    37  	payout := paypal.Payout{
    38  		SenderBatchHeader: &paypal.SenderBatchHeader{
    39  			SenderBatchID: "Payouts_2018_100007",
    40  			EmailSubject:  "You have a payout!",
    41  			EmailMessage:  "You have received a payout! Thanks for using our service!",
    42  		},
    43  		Items: []paypal.PayoutItem{
    44  			{
    45  				RecipientType:   "EMAIL",
    46  				RecipientWallet: paypal.VenmoRecipientWallet,
    47  				Receiver:        "receiver@example.com",
    48  				Amount: &paypal.AmountPayout{
    49  					Value:    "9.87",
    50  					Currency: "USD",
    51  				},
    52  				Note:         "Thanks for your patronage!",
    53  				SenderItemID: "201403140001",
    54  			},
    55  		},
    56  	}
    57  
    58  	c.CreatePayout(context.Background(), payout)
    59  }