| 1 |  |  | package flutterwave | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | import ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	"context" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	"net/http" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	"testing" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	"time" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	"github.com/NdoleStudio/flutterwave-go/internal/helpers" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	"github.com/NdoleStudio/flutterwave-go/internal/stubs" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	"github.com/araddon/dateparse" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	"github.com/google/uuid" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	"github.com/stretchr/testify/assert" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | ) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | func TestBillsService_CreatePayment(t *testing.T) { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | 	// Setup | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 	t.Parallel() | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 	// Arrange | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 	server := helpers.MakeTestServer(http.StatusOK, stubs.BillsCreateDStvPaymentResponse()) | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 	client := New(WithBaseURL(server.URL)) | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 	// Act | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 	data, response, err := client.Bills.CreatePayment(context.Background(), &BillsCreatePaymentRequest{ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 		Country:    "NG", | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 		Customer:   "7034504232", | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 		Amount:     100, | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 		Recurrence: "ONCE", | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 		Type:       "DStv", | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 		Reference:  uuid.New().String(), | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 		BillerName: "DStv", | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 	}) | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	// Assert | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 	assert.Nil(t, err) | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 	assert.Equal(t, &BillsCreatePaymentResponse{ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 		Status:  "success", | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 		Message: "Bill payment successful", | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 		Data: struct { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 			PhoneNumber string `json:"phone_number"` | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 			Amount      int    `json:"amount"` | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 			Network     string `json:"network"` | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 			FlwRef      string `json:"flw_ref"` | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 			TxRef       string `json:"tx_ref"` | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 		}{ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 			"+23490803840303", | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 			500, | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 			"9MOBILE", | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 			"CF-FLYAPI-20200311081921359990", | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 			"BPUSSD1583957963415840", | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 		}, | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 	}, data) | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 	assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 	assert.True(t, data.IsSuccessfull()) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 	// Teardown | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 	server.Close() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | func TestBillsService_Validate(t *testing.T) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	// Setup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	t.Parallel() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	// Arrange | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	server := helpers.MakeTestServer(http.StatusOK, stubs.BillsValidateDstvResponse()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	client := New(WithBaseURL(server.URL)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	// Act | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	data, response, err := client.Bills.Validate(context.Background(), "CB177", "BIL099", "08038291822") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	// Assert | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	assert.Nil(t, err) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	assert.Equal(t, &BillsValidateResponse{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		Status:  "success", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		Message: "Item validated successfully", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		Data: struct { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			ResponseCode    string      `json:"response_code"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			Address         interface{} `json:"address"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			ResponseMessage string      `json:"response_message"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			Name            string      `json:"name"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			BillerCode      string      `json:"biller_code"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			Customer        string      `json:"customer"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			ProductCode     string      `json:"product_code"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			Email           interface{} `json:"email"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			Fee             int         `json:"fee"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			Maximum         int         `json:"maximum"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			Minimum         int         `json:"minimum"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		}{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			"00", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			nil, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			"Successful", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			"MTN", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			"BIL099", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			"08038291822", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			"AT099", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			nil, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			100, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		}, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	}, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	assert.True(t, data.IsSuccessfull()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	// Teardown | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	server.Close() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | func TestBillsService_GetStatusVerbose(t *testing.T) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	// Setup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	t.Parallel() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	// Arrange | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	server := helpers.MakeTestServer(http.StatusOK, stubs.BillsGetStatusVerboseResponse()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	client := New(WithBaseURL(server.URL)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	// Act | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	data, response, err := client.Bills.GetStatusVerbose(context.Background(), "9300049404444") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	// Assert | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	assert.Nil(t, err) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 	transactionDate, err := dateparse.ParseAny("2020-03-11T20:19:21.27Z") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	assert.Nil(t, err) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	assert.Equal(t, &BillsStatusVerboseResponse{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		Status:  "success", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		Message: "Bill status fetch successful", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		Data: struct { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 			Currency        string      `json:"currency"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 			CustomerID      string      `json:"customer_id"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 			Frequency       string      `json:"frequency"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 			Amount          string      `json:"amount"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 			Product         string      `json:"product"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 			ProductName     string      `json:"product_name"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			Commission      int         `json:"commission"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 			TransactionDate time.Time   `json:"transaction_date"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			Country         string      `json:"country"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			TxRef           string      `json:"tx_ref"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 			Extra           interface{} `json:"extra"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 			ProductDetails  string      `json:"product_details"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 			Status          string      `json:"status"` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 		}{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 			"NGN", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			"+23490803840303", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 			"One Time", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 			"500.0000", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 			"AIRTIME", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 			"9MOBILE", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 			10, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 			transactionDate, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 			"NG", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 			"CF-FLYAPI-20200311081921359990", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 			nil, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 			"FLY-API-NG-AIRTIME-9MOBILE", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 			"successful", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		}, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	}, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	assert.True(t, data.IsSuccessfull()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 	// Teardown | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 	server.Close() | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 170 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 171 |  |  |  |