forked from Chapa-Et/chapa-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapa_test.go
147 lines (121 loc) · 4.23 KB
/
chapa_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
147
package chapa
import (
"testing"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
)
func TestChapa(t *testing.T) {
var request *PaymentRequest
t.Run("chap API", func(t *testing.T) {
InitConfig()
paymentProvider := New()
t.Run("can prompt payment from users", func(t *testing.T) {
request = &PaymentRequest{
Amount: decimal.NewFromInt(10),
Currency: "ETB",
FirstName: "chap",
LastName: "ET",
Email: "[email protected]",
CallbackURL: "https://webhook.site/077164d6-29cb-40df-ba29-8a00e59a7e60",
TransactionRef: RandomString(20),
Customization: map[string]interface{}{
"title": "title",
"description": "description",
"logo": "https://company.com/logo",
},
}
response, err := paymentProvider.PaymentRequest(request)
assert.NoError(t, err)
assert.Equal(t, "success", response.Status)
assert.Equal(t, "Hosted Link", response.Message)
assert.Contains(t, response.Data.CheckoutURL, "https://checkout.chapa.co/checkout/payment")
})
t.Run("can verify transactions", func(t *testing.T) {
response, err := paymentProvider.Verify(request.TransactionRef) // a paid txn
assert.NoError(t, err)
assert.Equal(t, "success", response.Status)
assert.Equal(t, "Payment details fetched successfully", response.Message)
// assert.NotZero(t, response.Data.Charge) // uncomment this for live mode
})
t.Run("can get transactions", func(t *testing.T) {
response, err := paymentProvider.GetTransactions()
assert.NoError(t, err)
assert.Equal(t, "success", response.Status)
assert.Equal(t, "Transactions retrieved successfully", response.Message)
})
t.Run("can get banks", func(t *testing.T) {
response, err := paymentProvider.GetBanks()
assert.NoError(t, err)
assert.Equal(t, "Banks retrieved", response.Message)
})
t.Run("cannot verify unpaid transaction", func(t *testing.T) {
request := &PaymentRequest{
TransactionRef: RandomString(20),
}
response, err := paymentProvider.Verify(request.TransactionRef)
assert.NoError(t, err)
assert.Equal(t, "Invalid transaction reference", response.Message)
})
t.Run("successful bank transfer", func(t *testing.T) {
request := &BankTransfer{
AccountName: "Leul Abay Ejigu",
AccountNumber: "1000212482106",
Amount: 10,
Currency: "ETB",
Reference: "3241342142sfdd",
BankCode: "946",
}
response, err := paymentProvider.TransferToBank(request)
assert.NoError(t, err)
assert.Equal(t, "success", response.Status)
// update below assertion on live mode
assert.Equal(t, "Transfer queued successfully in Test Mode.", response.Message)
assert.NotEmpty(t, response.Data)
})
t.Run("invalid input bank transfer", func(t *testing.T) {
request := &BankTransfer{
AccountNumber: "34264263",
Amount: 10,
Currency: "ETB",
Reference: "3264063st01",
BankCode: "32735b19-bb36-4cd7-b226-fb7451cd98f0",
}
response, err := paymentProvider.TransferToBank(request)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid input")
assert.Nil(t, response)
})
t.Run("successful bulk transfer", func(t *testing.T) {
bulkData := BulkData{
AccountName: "Leul Abay Ejigu",
AccountNumber: "1000212482106",
Amount: 10,
Reference: "3241342142sfdd",
BankCode: "946",
}
request := &BulkTransferRequest{
Title: "Transfer to leul",
Currency: "ETB",
BulkData: []BulkData{bulkData},
}
response, err := paymentProvider.BulkTransfer(request)
assert.NoError(t, err)
assert.Equal(t, "success", response.Status)
// update below assertion on live mode
// assert.Equal(t, "Bulk transfer queued successfully", response.Message)
assert.Equal(t, "Bulk Transfer queued successfully in Test Mode.", response.Message)
assert.NotEmpty(t, response.Data)
})
t.Run("invalid input for bulk transfer", func(t *testing.T) {
request := &BulkTransferRequest{
Title: "",
Currency: "ETB",
BulkData: []BulkData{},
}
response, err := paymentProvider.BulkTransfer(request)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid input")
assert.Nil(t, response)
})
})
}