-
Notifications
You must be signed in to change notification settings - Fork 5
/
payment_method.go
76 lines (67 loc) · 2.92 KB
/
payment_method.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package zooz
import (
"context"
"encoding/json"
"fmt"
)
// PaymentMethodClient is a client for work with PaymentMethod entity.
// https://developers.paymentsos.com/docs/api#/reference/payment-methods
type PaymentMethodClient struct {
Caller Caller
}
// PaymentMethod is a entity model.
type PaymentMethod struct {
Type string `json:"type"`
TokenType string `json:"token_type"`
PassLuhnValidation bool `json:"pass_luhn_validation"`
Token string `json:"token"`
Created json.Number `json:"created"`
Customer string `json:"customer"`
AdditionalDetails AdditionalDetails `json:"additional_details"`
BinNumber json.Number `json:"bin_number"`
Vendor string `json:"vendor"`
Issuer string `json:"issuer"`
CardType string `json:"card_type"`
Level string `json:"level"`
CountryCode string `json:"country_code"`
HolderName string `json:"holder_name"`
ExpirationDate string `json:"expiration_date"`
Last4Digits string `json:"last_4_digits"`
IdentityDocument *IdentityDocument `json:"identity_document"`
BillingAddress *Address `json:"billing_address"`
}
// IdentityDocument represents some identity document.
type IdentityDocument struct {
Type string `json:"type"`
Number string `json:"number"`
}
// New creates new PaymentMethod entity.
func (c *PaymentMethodClient) New(ctx context.Context, idempotencyKey string, customerID string, token string) (*PaymentMethod, error) {
paymentMethod := &PaymentMethod{}
if err := c.Caller.Call(ctx, "POST", c.tokenPath(customerID, token), map[string]string{headerIdempotencyKey: idempotencyKey}, nil, paymentMethod); err != nil {
return nil, err
}
return paymentMethod, nil
}
// Get returns PaymentMethod entity by customer ID and token.
func (c *PaymentMethodClient) Get(ctx context.Context, customerID string, token string) (*PaymentMethod, error) {
paymentMethod := &PaymentMethod{}
if err := c.Caller.Call(ctx, "GET", c.tokenPath(customerID, token), nil, nil, paymentMethod); err != nil {
return nil, err
}
return paymentMethod, nil
}
// GetList returns list of PaymentMethods for given customer.
func (c *PaymentMethodClient) GetList(ctx context.Context, customerID string) ([]PaymentMethod, error) {
var paymentMethods []PaymentMethod
if err := c.Caller.Call(ctx, "GET", c.paymentMethodsPath(customerID), nil, nil, &paymentMethods); err != nil {
return nil, err
}
return paymentMethods, nil
}
func (c *PaymentMethodClient) paymentMethodsPath(customerID string) string {
return fmt.Sprintf("%s/%s/payment-methods", customersPath, customerID)
}
func (c *PaymentMethodClient) tokenPath(customerID, token string) string {
return fmt.Sprintf("%s/%s", c.paymentMethodsPath(customerID), token)
}