forked from RevenueMonster/rm-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_payment_checkout_create.go
133 lines (115 loc) · 3.83 KB
/
api_payment_checkout_create.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
123
124
125
126
127
128
129
130
131
132
133
package sdk
import (
"errors"
"fmt"
)
// RequestExtraInfoExtraFee :
type RequestExtraInfoExtraFee struct {
Type string `json:"type"`
ReferenceID string `json:"referenceId"`
Amount uint64 `json:"amount"`
Source string `json:"source"`
}
// RequestAmountBreakdown :
type RequestAmountBreakdown struct {
Type string `json:"type"`
IsDiscountAllowed bool `json:"isDiscountAllowed"`
Label string `json:"label"`
Amount uint64 `json:"amount"`
}
// RequestInHousePromo :
type RequestInHousePromo struct {
Label string `json:"label"`
UniqueID string `json:"uniqueId"`
Source string `json:"source"`
Amount uint64 `json:"amount"`
}
// RequestCustomer :
type RequestCustomer struct {
UserID string `json:"userId"`
Email string `json:"email" validate:"omitempty,email"`
CountryCode string `json:"countryCode"`
PhoneNumber string `json:"phoneNumber"`
}
// RequestCreatePaymentCheckout :
type RequestCreatePaymentCheckout struct {
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"`
AmountBreakdown []RequestAmountBreakdown `json:"amountBreakdown"`
} `json:"order"`
Method []string `json:"method"`
ExcludeMethod []string `json:"excludeMethod"`
Type string `json:"type"`
StoreID string `json:"storeId"`
RedirectURL string `json:"redirectUrl"`
NotifyURL string `json:"notifyUrl"`
LayoutVersion string `json:"layoutVersion"`
ExtraInfo struct {
ExtraFee []RequestExtraInfoExtraFee `json:"extraFee"`
} `json:"extraInfo"`
Customer RequestCustomer `json:"customer"`
Voucher struct {
Code string `json:"code"`
} `json:"voucher"`
Source string `json:"source"`
InHousePromo []RequestInHousePromo `json:"inHousePromo"`
ExpiresInSeconds int64 `json:"expiresInSeconds"`
}
// ResponseCreatePaymentCheckout :
type ResponseCreatePaymentCheckout struct {
Item struct {
CheckoutID string `json:"checkoutId"`
URL string `json:"url"`
} `json:"item"`
Code string `json:"code"`
Err *Error `json:"error"`
}
// CreatePaymentCheckout :
func (c Client) CreatePaymentCheckout(request RequestCreatePaymentCheckout) (*ResponseCreatePaymentCheckout, error) {
if c.err != nil {
return nil, c.err
}
if request.ExpiresInSeconds <= 0 {
request.ExpiresInSeconds = 600
}
method := pathAPICreatePaymentCheckoutURL.method
requestURL := c.prepareAPIURL(pathAPICreatePaymentCheckoutURL)
response := new(ResponseCreatePaymentCheckout)
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
}
// ResponseGetQRCodeByCheckoutID :
type ResponseGetQRCodeByCheckoutID struct {
Item struct {
QRCodeImageBase64 string `json:"qrCodeImageBase64"`
URL string `json:"url"`
} `json:"item"`
Code string `json:"code"`
Err *Error `json:"error"`
}
// GetQRCodeByCheckoutID :
func (c Client) GetQRCodeByCheckoutID(checkoutID, walletMethod string) (*ResponseGetQRCodeByCheckoutID, error) {
if c.err != nil {
return nil, c.err
}
method := pathAPIGetQRCodeByCheckoutIDURL.method
requestURL := c.prepareAPIURL(pathAPIGetQRCodeByCheckoutIDURL)
response := new(ResponseGetQRCodeByCheckoutID)
if err := c.httpAPI(method, fmt.Sprintf("%s?checkoutId=%s&method=%s", requestURL, checkoutID, walletMethod), nil, response); err != nil {
return nil, err
}
if response.Err != nil {
return response, errors.New(response.Err.Message)
}
return response, nil
}