forked from RevenueMonster/rm-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_payment_checkout.go
122 lines (105 loc) · 3.66 KB
/
api_payment_checkout.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package sdk
import (
"errors"
"fmt"
"time"
)
// RequestCreatePaymentCheckoutByMethod :
type RequestCreatePaymentCheckoutByMethod struct {
Method string `json:"method"`
CheckoutID string `json:"checkoutId"`
Type string `json:"type"`
Fpx *RequestCreatePaymentCheckoutFpx `json:"fpx"`
Gobiz *RequestCreatePaymentCheckoutGobiz `json:"gobiz"`
Card *RequestCreatePaymentCheckoutCard `json:"card"`
}
type RequestCreatePaymentCheckoutFpx struct {
BankCode string `json:"bankCode"`
}
type RequestCreatePaymentCheckoutGobiz struct {
Type string `json:"type"`
}
type RequestCreatePaymentCheckoutCard struct {
IsToken bool `json:"isToken"`
IsSave bool `json:"isSave"`
No string `json:"no"`
CVC string `json:"cvc"`
Name string `json:"name"`
Month uint32 `json:"month"`
Year uint32 `json:"year"`
CountryCode string `json:"countryCode"`
}
// ResponseCreatePaymentCheckoutByMethod :
type ResponseCreatePaymentCheckoutByMethod struct {
Item struct {
URL string `json:"url"`
Data string `json:"data"`
QRCode struct {
Data string `json:"data"`
Base64Image string `json:"base64Image"`
} `json:"qrcode"`
Type string `json:"type"`
Transaction *PaymentTransaction `json:"transaction"`
} `json:"item"`
Code string `json:"code"`
Err *Error `json:"error"`
}
// CreatePaymentCheckoutByMethod :
func (c Client) CreatePaymentCheckoutByMethod(request RequestCreatePaymentCheckoutByMethod) (*ResponseCreatePaymentCheckoutByMethod, error) {
if c.err != nil {
return nil, c.err
}
method := pathAPICreatePaymentCheckoutByMethodURL.method
requestURL := c.prepareAPIURL(pathAPICreatePaymentCheckoutByMethodURL)
response := new(ResponseCreatePaymentCheckoutByMethod)
if err := c.httpAPI(method, requestURL, request, response); err != nil {
return nil, err
}
if response.Err != nil {
return response, errors.New(response.Err.Message)
}
return response, nil
}
// ResponseGetOnlineTransactionByCheckoutID :
type ResponseGetOnlineTransactionByCheckoutID struct {
Item struct {
ID string `json:"id"`
Order struct {
ID string `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
AdditionalData string `json:"additionalData"`
CurrencyType string `json:"currencyType"`
Amount uint64 `json:"amount"`
} `json:"order"`
Type string `json:"type"`
TransactionID string `json:"transactionId"`
Platform string `json:"platform"`
Method []string `json:"method"`
RedirectURL string `json:"redirectUrl"`
NotifyURL string `json:"notifyUrl"`
StartDateTime time.Time `json:"startAt"`
EndDateTime time.Time `json:"endAt"`
Status string `json:"status"`
CreatedDateTime time.Time `json:"createdAt"`
UpdatedDateTime time.Time `json:"updatedAt"`
} `json:"item"`
Code string `json:"code"`
Err *Error `json:"error"`
}
// GetOnlineTransactionByCheckoutID :
func (c Client) GetOnlineTransactionByCheckoutID(checkoutID string) (*ResponseGetOnlineTransactionByCheckoutID, error) {
if c.err != nil {
return nil, c.err
}
method := pathAPIGetOnlineTransactionByCheckoutIDURL.method
requestURL := c.prepareAPIURL(pathAPIGetOnlineTransactionByCheckoutIDURL)
response := new(ResponseGetOnlineTransactionByCheckoutID)
if err := c.httpAPI(method, fmt.Sprintf("%s?checkoutId=%s", requestURL, checkoutID), nil, response); err != nil {
return nil, err
}
if response.Err != nil {
return response, errors.New(response.Err.Message)
}
return response, nil
}