-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtransfer_test.go
146 lines (120 loc) · 3.36 KB
/
transfer_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
144
145
146
package paystack
import (
"testing"
)
func TestInitiateTransfer(t *testing.T) {
c.Transfer.EnableOTP()
recipient := &TransferRecipient{
Type: "Nuban",
Name: "Customer 1",
Description: "Demo customer",
AccountNumber: "0001234560",
BankCode: "058",
Currency: "NGN",
Metadata: map[string]interface{}{"job": "Plumber"},
}
recipient1, err := c.Transfer.CreateRecipient(recipient)
req := &TransferRequest{
Source: "balance",
Reason: "Delivery pickup",
Amount: 300,
Recipient: recipient1.RecipientCode,
}
transfer, err := c.Transfer.Initiate(req)
if err != nil {
t.Error(err)
}
if transfer.TransferCode == "" {
t.Errorf("Expected transfer code, got %+v", transfer.TransferCode)
}
// fetch transfer
trf, err := c.Transfer.Get(transfer.TransferCode)
if err != nil {
t.Error(err)
}
if trf.TransferCode == "" {
t.Errorf("Expected transfer code, got %+v", trf.TransferCode)
}
}
/* FAILS: Error message: Invalid amount passed
func TestBulkTransfer(t *testing.T) {
// You need to disable the Transfers OTP requirement to use this endpoint
c.Transfer.DisableOTP()
// retrieve the transfer recipient list
recipients, err := createDemoRecipients()
if err != nil {
t.Error(err)
}
transfer := &BulkTransfer{
Source: "balance",
Currency: "NGN",
Transfers: []map[string]interface{}{
{
"amount": 50000,
"recipient": recipients[0].RecipientCode,
},
{
"amount": 50000,
"recipient": recipients[1].RecipientCode,
},
},
}
_, err = c.Transfer.MakeBulkTransfer(transfer)
if err != nil {
t.Error(err)
}
}
*/
func TestTransferList(t *testing.T) {
// retrieve the transfer list
transfers, err := c.Transfer.List()
if err != nil {
t.Errorf("Expected Transfer list, got %d, returned error %v", len(transfers.Values), err)
}
}
func TestTransferRecipientList(t *testing.T) {
//fmt.Println("createDemoRecipients <<<<<<<")
//_, err := createDemoRecipients()
//if err != nil {
// t.Error(err)
//}
//fmt.Println("ListRecipients <<<<<<<")
// retrieve the transfer recipient list
recipients, err := c.Transfer.ListRecipients()
if err != nil || !(len(recipients.Values) > 0) || !(recipients.Meta.Total > 0) {
t.Errorf("Expected Recipients list, got %d, returned error %v", len(recipients.Values), err)
}
}
func createDemoRecipients() ([]*TransferRecipient, error) {
recipient1 := &TransferRecipient{
Type: "Nuban",
Name: "Customer 1",
Description: "Demo customer",
AccountNumber: "0001234560",
BankCode: "058",
Currency: "NGN",
Metadata: map[string]interface{}{"job": "Carpenter"},
}
recipient2 := &TransferRecipient{
Type: "Nuban",
Name: "Customer 2",
Description: "Demo customer",
AccountNumber: "0001234560",
BankCode: "058",
Currency: "NGN",
Metadata: map[string]interface{}{"job": "Chef"},
}
recipient3 := &TransferRecipient{
Type: "Nuban",
Name: "Customer 2",
Description: "Demo customer",
AccountNumber: "0001234560",
BankCode: "058",
Currency: "NGN",
Metadata: map[string]interface{}{"job": "Plumber"},
}
_, err := c.Transfer.CreateRecipient(recipient1)
_, err = c.Transfer.CreateRecipient(recipient2)
_, err = c.Transfer.CreateRecipient(recipient3)
return []*TransferRecipient{recipient1, recipient2, recipient3}, err
}