-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokopay.go
73 lines (60 loc) · 1.59 KB
/
tokopay.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
package Tokopay
import (
"github.com/pycodeDev/go-tokopay/entity"
"github.com/pycodeDev/go-tokopay/lib"
)
func GetInfoMerchant(param entity.ParamInfoMerchant) (entity.OutputInfoMerchant, error) {
var d entity.OutputInfoMerchant
merchant_id := param.MerchantId
secret := param.Secret
idr := param.Idr
merchant, err := lib.NewTokopayImpl(entity.TokopayCreden{
MERCHANTID: merchant_id,
SECRETKEY: secret,
}).GetInfo()
if err != nil {
return d, err
}
if idr {
d.Balance = lib.ToIDR(lib.StringToInt(merchant.Saldo))
d.BalanceHold = lib.ToIDR(lib.StringToInt(merchant.SaldoHold))
} else {
d.Balance = merchant.Saldo
d.BalanceHold = merchant.SaldoHold
}
d.MerchantName = merchant.NamaToko
return d, nil
}
func OrderSimple(param entity.ParamOrderSimple) (entity.OutputOrderSimple, error) {
var d entity.OutputOrderSimple
merchant_id := param.MerchantId
secret := param.Secret
idr := param.Idr
method := param.Method
ref_id := param.RefId
nominal := param.Nominal
order, err := lib.NewTokopayImpl(entity.TokopayCreden{
MERCHANTID: merchant_id,
SECRETKEY: secret,
}).Order(entity.TokopayOrderSimple{
Method: method,
RefId: ref_id,
Nominal: nominal,
})
if err != nil {
return d, err
}
if idr {
d.TotalBayar = lib.ToIDR(lib.StringToInt(order.TotalBayar))
d.TotalDiterima = lib.ToIDR(lib.StringToInt(order.TotalDiterima))
} else {
d.TotalBayar = order.TotalBayar
d.TotalDiterima = order.TotalDiterima
}
d.Data = order.Data
d.PanduanPembayaran = order.PanduanPembayaran
d.PayUrl = order.PayUrl
d.Status = order.Status
d.TrxId = order.TrxId
return d, nil
}