|
1
|
|
|
package flutterwave |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
"net/http" |
|
6
|
|
|
"testing" |
|
7
|
|
|
|
|
8
|
|
|
"github.com/NdoleStudio/flutterwave-go/internal/helpers" |
|
9
|
|
|
"github.com/NdoleStudio/flutterwave-go/internal/stubs" |
|
10
|
|
|
"github.com/google/uuid" |
|
11
|
|
|
"github.com/stretchr/testify/assert" |
|
12
|
|
|
) |
|
13
|
|
|
|
|
14
|
|
|
func TestBillsService_CreatePayment(t *testing.T) { |
|
15
|
|
|
// Setup |
|
16
|
|
|
t.Parallel() |
|
17
|
|
|
|
|
18
|
|
|
// Arrange |
|
19
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.BillsCreateDStvPaymentResponse()) |
|
20
|
|
|
client := New(WithBaseURL(server.URL)) |
|
21
|
|
|
|
|
22
|
|
|
// Act |
|
23
|
|
|
data, response, err := client.Bills.CreatePayment(context.Background(), &BillsCreatePaymentRequest{ |
|
24
|
|
|
Country: "NG", |
|
25
|
|
|
Customer: "7034504232", |
|
26
|
|
|
Amount: 100, |
|
27
|
|
|
Recurrence: "ONCE", |
|
28
|
|
|
Type: "DSTV", |
|
29
|
|
|
Reference: uuid.New().String(), |
|
30
|
|
|
BillerName: "DSTV", |
|
31
|
|
|
}) |
|
32
|
|
|
|
|
33
|
|
|
// Assert |
|
34
|
|
|
assert.Nil(t, err) |
|
35
|
|
|
|
|
36
|
|
|
assert.Equal(t, &BillsCreatePaymentResponse{ |
|
37
|
|
|
Status: "success", |
|
38
|
|
|
Message: "Bill payment successful", |
|
39
|
|
|
Data: struct { |
|
40
|
|
|
PhoneNumber string `json:"phone_number"` |
|
41
|
|
|
Amount int `json:"amount"` |
|
42
|
|
|
Network string `json:"network"` |
|
43
|
|
|
FlwRef string `json:"flw_ref"` |
|
44
|
|
|
TxRef string `json:"tx_ref"` |
|
45
|
|
|
}{ |
|
46
|
|
|
"+23490803840303", |
|
47
|
|
|
500, |
|
48
|
|
|
"9MOBILE", |
|
49
|
|
|
"CF-FLYAPI-20200311081921359990", |
|
50
|
|
|
"BPUSSD1583957963415840", |
|
51
|
|
|
}, |
|
52
|
|
|
}, data) |
|
53
|
|
|
|
|
54
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
55
|
|
|
|
|
56
|
|
|
// Teardown |
|
57
|
|
|
server.Close() |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
func TestBillsService_Validate(t *testing.T) { |
|
61
|
|
|
// Setup |
|
62
|
|
|
t.Parallel() |
|
63
|
|
|
|
|
64
|
|
|
// Arrange |
|
65
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.BillsValidateDstvResponse()) |
|
66
|
|
|
client := New(WithBaseURL(server.URL)) |
|
67
|
|
|
|
|
68
|
|
|
// Act |
|
69
|
|
|
data, response, err := client.Bills.Validate(context.Background(), "CB177", "BIL099", "08038291822") |
|
70
|
|
|
|
|
71
|
|
|
// Assert |
|
72
|
|
|
assert.Nil(t, err) |
|
73
|
|
|
|
|
74
|
|
|
assert.Equal(t, &BillsValidateResponse{ |
|
75
|
|
|
Status: "success", |
|
76
|
|
|
Message: "Item validated successfully", |
|
77
|
|
|
Data: struct { |
|
78
|
|
|
ResponseCode string `json:"response_code"` |
|
79
|
|
|
Address interface{} `json:"address"` |
|
80
|
|
|
ResponseMessage string `json:"response_message"` |
|
81
|
|
|
Name string `json:"name"` |
|
82
|
|
|
BillerCode string `json:"biller_code"` |
|
83
|
|
|
Customer string `json:"customer"` |
|
84
|
|
|
ProductCode string `json:"product_code"` |
|
85
|
|
|
Email interface{} `json:"email"` |
|
86
|
|
|
Fee int `json:"fee"` |
|
87
|
|
|
Maximum int `json:"maximum"` |
|
88
|
|
|
Minimum int `json:"minimum"` |
|
89
|
|
|
}{ |
|
90
|
|
|
"00", |
|
91
|
|
|
nil, |
|
92
|
|
|
"Successful", |
|
93
|
|
|
"MTN", |
|
94
|
|
|
"BIL099", |
|
95
|
|
|
"08038291822", |
|
96
|
|
|
"AT099", |
|
97
|
|
|
nil, |
|
98
|
|
|
100, |
|
99
|
|
|
0, |
|
100
|
|
|
0, |
|
101
|
|
|
}, |
|
102
|
|
|
}, data) |
|
103
|
|
|
|
|
104
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
|
105
|
|
|
|
|
106
|
|
|
// Teardown |
|
107
|
|
|
server.Close() |
|
108
|
|
|
} |
|
109
|
|
|
|