paypale/vault.go

99 lines
2.3 KiB
Go
Raw Permalink Normal View History

2019-08-21 15:50:20 +02:00
package paypal
2016-12-19 06:55:00 +01:00
import (
2021-01-03 10:28:52 +01:00
"context"
2016-12-19 06:55:00 +01:00
"fmt"
)
// StoreCreditCard func
// Endpoint: POST /v1/vault/credit-cards
2021-01-03 10:28:52 +01:00
func (c *Client) StoreCreditCard(ctx context.Context, cc CreditCard) (*CreditCard, error) {
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/vault/credit-cards"), cc)
2016-12-19 06:55:00 +01:00
if err != nil {
return nil, err
}
2019-06-16 04:39:08 +02:00
response := &CreditCard{}
2017-11-23 03:15:11 +01:00
2019-06-16 04:39:08 +02:00
if err = c.SendWithAuth(req, response); err != nil {
2016-12-19 06:55:00 +01:00
return nil, err
}
2019-06-16 04:39:08 +02:00
return response, nil
2016-12-19 06:55:00 +01:00
}
// DeleteCreditCard func
// Endpoint: DELETE /v1/vault/credit-cards/credit_card_id
2021-01-03 10:28:52 +01:00
func (c *Client) DeleteCreditCard(ctx context.Context, id string) error {
req, err := c.NewRequest(ctx, "DELETE", fmt.Sprintf("%s/v1/vault/credit-cards/%s", c.APIBase, id), nil)
2016-12-19 06:55:00 +01:00
if err != nil {
return err
2016-12-19 06:55:00 +01:00
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, nil); err != nil {
return err
2016-12-19 06:55:00 +01:00
}
return nil
2016-12-19 06:55:00 +01:00
}
// GetCreditCard func
// Endpoint: GET /v1/vault/credit-cards/credit_card_id
2021-01-03 10:28:52 +01:00
func (c *Client) GetCreditCard(ctx context.Context, id string) (*CreditCard, error) {
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s/v1/vault/credit-cards/%s", c.APIBase, id), nil)
2016-12-19 06:55:00 +01:00
if err != nil {
return nil, err
}
2019-06-16 04:39:08 +02:00
response := &CreditCard{}
2017-11-23 03:15:11 +01:00
2019-06-16 04:39:08 +02:00
if err = c.SendWithAuth(req, response); err != nil {
2016-12-19 06:55:00 +01:00
return nil, err
}
2019-06-16 04:39:08 +02:00
return response, nil
2016-12-19 06:55:00 +01:00
}
// GetCreditCards func
// Endpoint: GET /v1/vault/credit-cards
2021-01-03 10:28:52 +01:00
func (c *Client) GetCreditCards(ctx context.Context, ccf *CreditCardsFilter) (*CreditCards, error) {
2016-12-19 06:55:00 +01:00
page := 1
if ccf != nil && ccf.Page > 0 {
page = ccf.Page
}
pageSize := 10
if ccf != nil && ccf.PageSize > 0 {
pageSize = ccf.PageSize
}
2021-01-03 10:28:52 +01:00
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s/v1/vault/credit-cards?page=%d&page_size=%d", c.APIBase, page, pageSize), nil)
2016-12-19 06:55:00 +01:00
if err != nil {
return nil, err
}
2019-06-16 04:39:08 +02:00
response := &CreditCards{}
2017-11-23 03:15:11 +01:00
2019-06-16 04:39:08 +02:00
if err = c.SendWithAuth(req, response); err != nil {
2016-12-19 06:55:00 +01:00
return nil, err
}
2019-06-16 04:39:08 +02:00
return response, nil
2016-12-19 06:55:00 +01:00
}
// PatchCreditCard func
// Endpoint: PATCH /v1/vault/credit-cards/credit_card_id
2021-01-03 10:28:52 +01:00
func (c *Client) PatchCreditCard(ctx context.Context, id string, ccf []CreditCardField) (*CreditCard, error) {
req, err := c.NewRequest(ctx, "PATCH", fmt.Sprintf("%s/v1/vault/credit-cards/%s", c.APIBase, id), ccf)
2016-12-19 06:55:00 +01:00
if err != nil {
return nil, err
}
2019-06-16 04:39:08 +02:00
response := &CreditCard{}
2017-11-23 03:15:11 +01:00
2019-06-16 04:39:08 +02:00
if err = c.SendWithAuth(req, response); err != nil {
2016-12-19 06:55:00 +01:00
return nil, err
}
2019-06-16 04:39:08 +02:00
return response, nil
2016-12-19 06:55:00 +01:00
}