mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
a3977a8e74
* created billing agreements file * CreateBillingAgreementToken created with new types * updated formatting * error to return nil * removed new line * added test
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
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
|
|
}
|