forked from RevenueMonster/rm-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_customer_token.go
97 lines (82 loc) · 2.69 KB
/
api_customer_token.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package sdk
import (
"errors"
"strings"
"time"
)
type CustomerToken struct {
ID string `json:"id"`
Label string `json:"label"`
Provider string `json:"provider"`
Token string `json:"token"`
Country string `json:"country"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Address struct {
AddressLine1 string `json:"addressLine1"`
AddressLine2 string `json:"addressLine2"`
PostCode string `json:"postCode"`
City string `json:"city"`
State string `json:"state"`
Country string `json:"country"`
} `json:"address"`
Card struct {
Name string `json:"name"`
Method string `json:"method"`
Fundingtype string `json:"fundingtype"`
LastFourNo string `json:"lastFourNo"`
ExpMonth int `json:"expMonth"`
ExpYear int `json:"ExpYear"`
IsCvcCheck bool `json:"isCvcCheck"`
} `json:"card"`
}
type RequestGetPaymentCheckoutCustomerToken struct {
CustomerID string
}
type ResponseGetPaymentCheckoutCustomerToken struct {
Item []CustomerToken `json:"item"`
Code string `json:"code"`
Err *Error `json:"error"`
}
// GetPaymentCheckoutCustomerToken :
func (c Client) GetPaymentCheckoutCustomerToken(request RequestGetPaymentCheckoutCustomerToken) (*ResponseGetPaymentCheckoutCustomerToken, error) {
if c.err != nil {
return nil, c.err
}
method := pathAPIGetPaymentCheckoutCustomerToken.method
requestURL := c.prepareAPIURL(pathAPIGetPaymentCheckoutCustomerToken)
requestURL = strings.ReplaceAll(requestURL, "{customer_id}", request.CustomerID)
response := new(ResponseGetPaymentCheckoutCustomerToken)
if err := c.httpAPI(method, requestURL, nil, response); err != nil {
return nil, err
}
if response.Err != nil {
return response, errors.New(response.Err.Message)
}
return response, nil
}
type RequestDeletePaymentCheckoutCustomerToken struct {
CustomerID string
Token string
}
type ResponseDeletePaymentCheckoutCustomerToken struct {
Code string `json:"code"`
Err *Error `json:"error"`
}
// DeletePaymentCheckoutCustomerToken :
func (c Client) DeletePaymentCheckoutCustomerToken(request RequestDeletePaymentCheckoutCustomerToken) error {
if c.err != nil {
return c.err
}
method := pathAPIDeletePaymentCheckoutCustomerToken.method
requestURL := c.prepareAPIURL(pathAPIDeletePaymentCheckoutCustomerToken)
requestURL = strings.ReplaceAll(requestURL, "{customer_id}", request.CustomerID)
response := new(ResponseGetPaymentCheckoutCustomerToken)
if err := c.httpAPI(method, requestURL, map[string]string{"token": request.Token}, response); err != nil {
return err
}
if response.Err != nil {
return errors.New(response.Err.Message)
}
return nil
}