-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofframp.go
92 lines (76 loc) · 2.55 KB
/
offramp.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
package kotani
import (
"bytes"
"context"
"encoding/json"
"errors"
"math"
"net/http"
)
type (
OfframpCustomer struct {
PhoneNumber string `json:"phoneNumber"`
AccountName string `json:"accountName"`
Network Network `json:"networkProvider"`
}
OfframpRequestBody struct {
Chain Chain `json:"chain"`
Token Token `json:"token"`
Currency Currency `json:"currency"`
Amount float64 `json:"cryptoAmount"`
FromAddress string `json:"senderAddress"`
ReferenceID string `json:"referenceId"`
Customer OfframpCustomer `json:"mobileMoneyReceiver"`
}
OfframpResp struct {
CommonResponseFields
Data struct {
ReferenceID string `json:"referenceId"`
FiatAmount float64 `json:"fiatAmount"`
FiatTransactionAmount float64 `json:"fiatTransactionAmount"`
CryptoAmount float64 `json:"cryptoAmount"`
FiatCurrency string `json:"fiatCurrency"`
CustomerKey string `json:"customerKey"`
FiatWalletID string `json:"fiatWalletId"`
SenderAddress string `json:"senderAddress"`
TransactionHash string `json:"transactionHash"`
TransactionHashAmount float64 `json:"transactionHashAmount"`
Status string `json:"status"`
OnchainStatus string `json:"onchainStatus"`
Rate struct {
} `json:"rate"`
EscrowAddress string `json:"escrowAddress"`
} `json:"data"`
}
)
const offrampPath = "/offramp/"
var ErrNegativeAmount = errors.New("amount must be greater than 0")
func (kc *KotaniClient) Offramp(ctx context.Context, input OfframpRequestBody) (OfframpResp, error) {
offrampResp := OfframpResp{}
if math.Signbit(input.Amount) {
return offrampResp, ErrNegativeAmount
}
jsonRequestBody, err := json.Marshal(&input)
if err != nil {
return offrampResp, err
}
resp, err := kc.requestWithCtx(ctx, http.MethodPost, kc.endpoint+offrampPath, bytes.NewBuffer(jsonRequestBody))
if err != nil {
return offrampResp, err
}
if err := parseResponse(resp, &offrampResp); err != nil {
return offrampResp, err
}
return offrampResp, nil
}
func (kc *KotaniClient) GetOfframpStatus(ctx context.Context, referenceID string) (OfframpResp, error) {
offrampStatusResp := OfframpResp{}
resp, err := kc.requestWithCtx(ctx, http.MethodGet, kc.endpoint+offrampPath+referenceID, nil)
if err != nil {
return offrampStatusResp, err
}
if err := parseResponse(resp, &offrampStatusResp); err != nil {
return offrampStatusResp, err
}
return offrampStatusResp, nil
}