-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding functions for requesting billing agreement token (#203)
* created billing agreements file * CreateBillingAgreementToken created with new types * updated formatting * error to return nil * removed new line * added test
- Loading branch information
1 parent
021cc68
commit a3977a8
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package paypal | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// CreateBillingAgreementToken - Use this call to create a billing agreement | ||
// Endpoint: POST /v1/billing-agreements/agreement-tokens | ||
func (c *Client) CreateBillingAgreementToken( | ||
ctx context.Context, | ||
name string, | ||
description string, | ||
startDate string, | ||
payer *Payer, | ||
plan *BillingPlan, | ||
) (*BillingAgreementToken, error) { | ||
type createBARequest struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
StartDate string `json:"start_date"` | ||
Payer *Payer `json:"payer"` | ||
Plan *BillingPlan `json:"plan"` | ||
} | ||
|
||
billingAgreementToken := &BillingAgreementToken{} | ||
|
||
req, err := c.NewRequest( | ||
ctx, | ||
"POST", | ||
fmt.Sprintf("%s%s", c.APIBase, "/v1/billing-agreements/agreement-tokens"), | ||
createBARequest{Name: name, Description: description, StartDate: startDate, Payer: payer, Plan: plan}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err = c.SendWithAuth(req, billingAgreementToken); err != nil { | ||
return billingAgreementToken, err | ||
} | ||
|
||
return billingAgreementToken, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters