-
Notifications
You must be signed in to change notification settings - Fork 13
/
compound_test.go
143 lines (124 loc) · 3.66 KB
/
compound_test.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
134
135
136
137
138
139
140
141
142
143
package tinkoff_test
import (
"context"
"errors"
"strconv"
"testing"
"time"
"github.com/nikita-vanyasin/tinkoff"
)
func TestCallsChain(t *testing.T) {
c := helperCreateClient(t)
// create new payment
orderID := strconv.FormatInt(time.Now().UnixNano(), 10)
initReq := prepareInitRequests(orderID)
initRes, err := c.Init(initReq)
assertNotError(t, err)
assertEq(t, true, initRes.Success)
assertEq(t, tinkoff.StatusNew, initRes.Status)
assertNotEmptyString(t, initRes.OrderID)
assertNotEmptyString(t, initRes.PaymentURL)
// get QR for payment (payload)
gqr := &tinkoff.GetQRRequest{
PaymentID: initRes.PaymentID,
DataType: tinkoff.QRTypePayload,
}
resQR, err := c.GetQR(gqr)
assertNotError(t, err)
assertNotEmptyString(t, resQR.Data)
// get QR for payment (SVG)
gqr = &tinkoff.GetQRRequest{
PaymentID: initRes.PaymentID,
DataType: tinkoff.QRTypeImage,
}
resQR, err = c.GetQR(gqr)
assertNotError(t, err)
assertNotEmptyString(t, resQR.Data)
// cancel it
req := &tinkoff.CancelRequest{
PaymentID: initRes.PaymentID,
Amount: 60000,
Receipt: &tinkoff.Receipt{
Email: "[email protected]",
Items: []*tinkoff.ReceiptItem{
{
Price: 60000,
Quantity: "1",
Amount: 60000,
Name: "Product #1",
Tax: tinkoff.VATNone,
},
},
Taxation: tinkoff.TaxationUSNIncome,
Payments: &tinkoff.ReceiptPayments{
Electronic: 60000,
},
},
}
cancelRes, err := c.Cancel(req)
assertNotError(t, err)
assertEq(t, true, cancelRes.Success)
assertEq(t, tinkoff.StatusCanceled, cancelRes.Status)
assertEq(t, initRes.PaymentID, cancelRes.PaymentID)
assertEq(t, orderID, cancelRes.OrderID)
// get state
stateRes, err := c.GetState(&tinkoff.GetStateRequest{PaymentID: initRes.PaymentID})
assertNotError(t, err)
assertEq(t, true, stateRes.Success)
assertEq(t, initRes.PaymentID, stateRes.PaymentID)
assertEq(t, tinkoff.StatusCanceled, cancelRes.Status)
resendRes, err := c.Resend()
assertNotError(t, err)
verySmallTimeoutCtx, cancel := context.WithTimeout(context.Background(), 100*time.Nanosecond)
defer cancel()
_, err = c.ResendWithContext(verySmallTimeoutCtx)
assertEq(t, context.DeadlineExceeded, errors.Unwrap(err))
assertEq(t, 0, resendRes.Count)
}
func prepareInitRequests(orderID string) *tinkoff.InitRequest {
return &tinkoff.InitRequest{
Amount: 60000,
OrderID: orderID,
CustomerKey: "123",
Description: "some really useful product",
PayType: tinkoff.PayTypeOneStep,
RedirectDueDate: tinkoff.Time(time.Now().Add(4 * time.Hour * 24)), // ссылка истечет через 4 дня
Receipt: &tinkoff.Receipt{
Email: "[email protected]",
Items: []*tinkoff.ReceiptItem{
{
Price: 60000,
Quantity: "1",
Amount: 60000,
Name: "Product #1",
Tax: tinkoff.VATNone,
PaymentMethod: tinkoff.PaymentMethodFullPayment,
PaymentObject: tinkoff.PaymentObjectIntellectualActivity,
},
},
Taxation: tinkoff.TaxationUSNIncome,
Payments: &tinkoff.ReceiptPayments{
Electronic: 60000,
},
},
Data: map[string]string{
"custom data field 1": "aasd6da78dasd9",
"custom data field 2": "0",
},
}
}
func TestSBPPayTest(t *testing.T) {
c := helperCreateClient(t)
orderID := strconv.FormatInt(time.Now().UnixNano(), 10)
initReq := prepareInitRequests(orderID)
initRes, err := c.Init(initReq)
assertNotError(t, err)
// Init SBP transaction
sbp, err := c.SBPPayTestWithContext(context.Background(), &tinkoff.SBPPayTestRequest{
PaymentID: initRes.PaymentID,
IsDeadlineExpired: true,
IsRejected: false,
})
assertNotError(t, err)
assertEq(t, true, sbp.Success)
}