github.com/plutov/paypal/v4@v4.7.1/vault.go (about) 1 package paypal 2 3 import ( 4 "context" 5 "fmt" 6 ) 7 8 // StoreCreditCard func 9 // Endpoint: POST /v1/vault/credit-cards 10 func (c *Client) StoreCreditCard(ctx context.Context, cc CreditCard) (*CreditCard, error) { 11 req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/vault/credit-cards"), cc) 12 if err != nil { 13 return nil, err 14 } 15 16 response := &CreditCard{} 17 18 if err = c.SendWithAuth(req, response); err != nil { 19 return nil, err 20 } 21 22 return response, nil 23 } 24 25 // DeleteCreditCard func 26 // Endpoint: DELETE /v1/vault/credit-cards/credit_card_id 27 func (c *Client) DeleteCreditCard(ctx context.Context, id string) error { 28 req, err := c.NewRequest(ctx, "DELETE", fmt.Sprintf("%s/v1/vault/credit-cards/%s", c.APIBase, id), nil) 29 if err != nil { 30 return err 31 } 32 33 if err = c.SendWithAuth(req, nil); err != nil { 34 return err 35 } 36 37 return nil 38 } 39 40 // GetCreditCard func 41 // Endpoint: GET /v1/vault/credit-cards/credit_card_id 42 func (c *Client) GetCreditCard(ctx context.Context, id string) (*CreditCard, error) { 43 req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s/v1/vault/credit-cards/%s", c.APIBase, id), nil) 44 if err != nil { 45 return nil, err 46 } 47 48 response := &CreditCard{} 49 50 if err = c.SendWithAuth(req, response); err != nil { 51 return nil, err 52 } 53 54 return response, nil 55 } 56 57 // GetCreditCards func 58 // Endpoint: GET /v1/vault/credit-cards 59 func (c *Client) GetCreditCards(ctx context.Context, ccf *CreditCardsFilter) (*CreditCards, error) { 60 page := 1 61 if ccf != nil && ccf.Page > 0 { 62 page = ccf.Page 63 } 64 pageSize := 10 65 if ccf != nil && ccf.PageSize > 0 { 66 pageSize = ccf.PageSize 67 } 68 69 req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s/v1/vault/credit-cards?page=%d&page_size=%d", c.APIBase, page, pageSize), nil) 70 if err != nil { 71 return nil, err 72 } 73 74 response := &CreditCards{} 75 76 if err = c.SendWithAuth(req, response); err != nil { 77 return nil, err 78 } 79 80 return response, nil 81 } 82 83 // PatchCreditCard func 84 // Endpoint: PATCH /v1/vault/credit-cards/credit_card_id 85 func (c *Client) PatchCreditCard(ctx context.Context, id string, ccf []CreditCardField) (*CreditCard, error) { 86 req, err := c.NewRequest(ctx, "PATCH", fmt.Sprintf("%s/v1/vault/credit-cards/%s", c.APIBase, id), ccf) 87 if err != nil { 88 return nil, err 89 } 90 91 response := &CreditCard{} 92 93 if err = c.SendWithAuth(req, response); err != nil { 94 return nil, err 95 } 96 97 return response, nil 98 }