flutterwave 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ module Flutterwave
2
+ class BankAPI
3
+ attr_accessor :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ # https://www.flutterwave.com/documentation/banks-enquiry/
10
+ def list
11
+ response = post(
12
+ Flutterwave::Utils::Constants::BANK[:list_url]
13
+ )
14
+
15
+ all_banks = response['data']
16
+ all_banks.keys.inject([]) do |list, code|
17
+ list << Bank.new(code, all_banks[code])
18
+ end
19
+ end
20
+
21
+ def find_by_code(code)
22
+ list.detect do |bank|
23
+ bank.code == code
24
+ end
25
+ end
26
+
27
+ def find_by_name(name_match)
28
+ list.detect do |bank|
29
+ !(bank.name.downcase =~ /#{name_match.downcase}/).nil?
30
+ end
31
+ end
32
+
33
+ def post(url, data = {})
34
+ Flutterwave::Utils::NetworkManager.post(url, data)
35
+ end
36
+ end
37
+
38
+ class Bank
39
+ attr_accessor :code, :name
40
+
41
+ def initialize(code, name)
42
+ @code = code
43
+ @name = name
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ module Flutterwave
2
+ class BIN
3
+ include Flutterwave::Helpers
4
+ attr_accessor :client, :options
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # https://www.flutterwave.com/documentation/compliance/ - Verify Card BIN API
11
+ def check(options = {})
12
+ @options = options
13
+
14
+ request_params = {
15
+ card6: encrypt(:card6)
16
+ }
17
+
18
+ response = post(
19
+ Flutterwave::Utils::Constants::BIN[:check_url],
20
+ request_params
21
+ )
22
+
23
+ Flutterwave::Response.new(response)
24
+ end
25
+
26
+ def encrypt(key)
27
+ plain_text = options[key].to_s
28
+ raise Flutterwave::Utils::MissingKeyError.new(
29
+ "#{key.capitalize} key required!"
30
+ ) if plain_text.empty?
31
+
32
+ encrypt_data(plain_text, client.api_key)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,74 @@
1
+ module Flutterwave
2
+ class BVN
3
+ include Flutterwave::Helpers
4
+ attr_accessor :client, :options
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # https://www.flutterwave.com/documentation/compliance/ - Verify (request a user enter their BVN for verification)
11
+ def verify(options = {})
12
+ @options = options
13
+
14
+ request_params = {
15
+ otpoption: encrypt(:otpoption),
16
+ bvn: encrypt(:bvn),
17
+ merchantid: client.merchant_key
18
+ }
19
+
20
+ response = post(
21
+ Flutterwave::Utils::Constants::BVN[:verify_url],
22
+ request_params
23
+ )
24
+
25
+ Flutterwave::Response.new(response)
26
+ end
27
+
28
+ # https://www.flutterwave.com/documentation/compliance/ - Resend OTP
29
+ def resend(options = {})
30
+ @options = options
31
+
32
+ request_params = {
33
+ validateoption: encrypt(:validateoption),
34
+ transactionreference: encrypt(:transactionreference),
35
+ merchantid: client.merchant_key
36
+ }
37
+
38
+ response = post(
39
+ Flutterwave::Utils::Constants::BVN[:resend_url],
40
+ request_params
41
+ )
42
+
43
+ Flutterwave::Response.new(response)
44
+ end
45
+
46
+ # https://www.flutterwave.com/documentation/compliance/ - Validate (This is used to validate the OTP entered by the user)
47
+ def validate(options = {})
48
+ @options = options
49
+
50
+ request_params = {
51
+ otp: encrypt(:otp),
52
+ transactionreference: encrypt(:transactionreference),
53
+ bvn: encrypt(:bvn),
54
+ merchantid: client.merchant_key
55
+ }
56
+
57
+ response = post(
58
+ Flutterwave::Utils::Constants::BVN[:validate_url],
59
+ request_params
60
+ )
61
+
62
+ Flutterwave::Response.new(response)
63
+ end
64
+
65
+ def encrypt(key)
66
+ plain_text = options[key].to_s
67
+ raise Flutterwave::Utils::MissingKeyError.new(
68
+ "#{key.capitalize} key required!"
69
+ ) if plain_text.empty?
70
+
71
+ encrypt_data(plain_text, client.api_key)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,272 @@
1
+ require 'flutterwave/response'
2
+
3
+ module Flutterwave
4
+ class Card
5
+ include Flutterwave::Helpers
6
+ attr_accessor :client, :options
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ # https://www.flutterwave.com/documentation/card-payments-with-preauth/#tokenize
13
+ def tokenize(options = {})
14
+ @options = options
15
+ options[:country] ||= 'NG'
16
+
17
+ request_params = {
18
+ validateoption: encrypt(:validateoption),
19
+ authmodel: encrypt(:authmodel),
20
+ cardno: encrypt(:cardno),
21
+ cvv: encrypt(:cvv),
22
+ country: encrypt(:country),
23
+ expirymonth: encrypt(:expirymonth),
24
+ expiryyear: encrypt(:expiryyear),
25
+ merchantid: client.merchant_key
26
+ }
27
+
28
+ request_params[:bvn] = encrypt(:bvn) if options[:authmodel] == 'BVN'
29
+
30
+ response = post(
31
+ Flutterwave::Utils::Constants::CARD[:tokenize_url],
32
+ request_params
33
+ )
34
+
35
+ Flutterwave::Response.new(response)
36
+ end
37
+
38
+ # https://www.flutterwave.com/documentation/card-payments-with-preauth/#preauthorize
39
+ def preauthorize(options = {})
40
+ @options = options
41
+ options[:country] ||= 'NG'
42
+
43
+ request_params = {
44
+ amount: encrypt(:amount),
45
+ currency: encrypt(:currency),
46
+ chargetoken: encrypt(:chargetoken),
47
+ country: encrypt(:country),
48
+ merchantid: client.merchant_key
49
+ }
50
+
51
+ response = post(
52
+ Flutterwave::Utils::Constants::CARD[:preauthorize_url],
53
+ request_params
54
+ )
55
+
56
+ Flutterwave::Response.new(response)
57
+ end
58
+
59
+ # https://www.flutterwave.com/documentation/card-payments-with-preauth/#capture
60
+ def capture(options = {})
61
+ @options = options
62
+ options[:country] ||= 'NG'
63
+
64
+ request_params = {
65
+ amount: encrypt(:amount),
66
+ currency: encrypt(:currency),
67
+ country: encrypt(:country),
68
+ trxreference: encrypt(:trxreference),
69
+ trxauthorizeid: encrypt(:trxauthorizeid),
70
+ chargetoken: encrypt(:chargetoken),
71
+ merchantid: client.merchant_key
72
+ }
73
+
74
+ response = post(
75
+ Flutterwave::Utils::Constants::CARD[:capture_url],
76
+ request_params
77
+ )
78
+
79
+ Flutterwave::Response.new(response)
80
+ end
81
+
82
+ # https://www.flutterwave.com/documentation/card-payments-with-preauth/#refund
83
+ def refund(options = {})
84
+ @options = options
85
+ options[:country] ||= 'NG'
86
+
87
+ request_params = {
88
+ amount: encrypt(:amount),
89
+ currency: encrypt(:currency),
90
+ country: encrypt(:country),
91
+ trxreference: encrypt(:trxreference),
92
+ trxauthorizeid: encrypt(:trxauthorizeid),
93
+ merchantid: client.merchant_key
94
+ }
95
+
96
+ response = post(
97
+ Flutterwave::Utils::Constants::CARD[:refund_url],
98
+ request_params
99
+ )
100
+
101
+ Flutterwave::Response.new(response)
102
+ end
103
+
104
+ # https://www.flutterwave.com/documentation/card-payments-with-preauth/#void
105
+ def void(options = {})
106
+ @options = options
107
+ options[:country] ||= 'NG'
108
+
109
+ request_params = {
110
+ amount: encrypt(:amount),
111
+ currency: encrypt(:currency),
112
+ country: encrypt(:country),
113
+ trxreference: encrypt(:trxreference),
114
+ trxauthorizeid: encrypt(:trxauthorizeid),
115
+ merchantid: client.merchant_key
116
+ }
117
+
118
+ response = post(
119
+ Flutterwave::Utils::Constants::CARD[:void_url],
120
+ request_params
121
+ )
122
+
123
+ Flutterwave::Response.new(response)
124
+ end
125
+
126
+ # https://www.flutterwave.com/documentation/card-enquiry/ - Card Enquiry
127
+ def enquiry(options = {})
128
+ @options = options
129
+
130
+ request_params = {
131
+ cardno: encrypt(:cardno),
132
+ cvv: encrypt(:cvv),
133
+ expirymonth: encrypt(:expirymonth),
134
+ expiryyear: encrypt(:expiryyear),
135
+ pin: encrypt(:pin),
136
+ trxreference: encrypt(:trxreference),
137
+ merchantid: client.merchant_key
138
+ }
139
+
140
+ response = post(
141
+ Flutterwave::Utils::Constants::CARD[:enquiry_url],
142
+ request_params
143
+ )
144
+
145
+ Flutterwave::Response.new(response)
146
+ end
147
+
148
+ # https://www.flutterwave.com/documentation/card-enquiry/ - Validate
149
+ def validate_enquiry(options = {})
150
+ @options = options
151
+
152
+ request_params = {
153
+ otp: encrypt(:otp),
154
+ otptransactionidentifier: encrypt(:otptransactionidentifier),
155
+ trxreference: encrypt(:trxreference),
156
+ merchantid: client.merchant_key
157
+ }
158
+
159
+ response = post(
160
+ Flutterwave::Utils::Constants::CARD[:validate_enquiry_url],
161
+ request_params
162
+ )
163
+
164
+ Flutterwave::Response.new(response)
165
+ end
166
+
167
+ # https://www.flutterwave.com/documentation/card-payments/#tokenize-and-charge
168
+ def charge(options = {})
169
+ @options = options
170
+ options[:country] ||= 'NG'
171
+
172
+ request_params = {
173
+ amount: encrypt(:amount),
174
+ authmodel: encrypt(:authmodel),
175
+ cardno: encrypt(:cardno),
176
+ currency: encrypt(:currency),
177
+ custid: encrypt(:custid),
178
+ country: encrypt(:country),
179
+ cvv: encrypt(:cvv),
180
+ expirymonth: encrypt(:expirymonth),
181
+ expiryyear: encrypt(:expiryyear),
182
+ narration: encrypt(:narration),
183
+ merchantid: client.merchant_key
184
+ }
185
+
186
+ request_params[:pin] = encrypt(:pin) if options[:authmodel] == 'PIN'
187
+
188
+ request_params[:bvn] = encrypt(:bvn) if options[:authmodel] == 'BVN'
189
+
190
+ request_params[:responseurl] = encrypt(:responseurl) if
191
+ options[:authmodel] == 'VBVSECURECODE'
192
+
193
+ request_params[:cardtype] = encrypt(:cardtype) if options[:cardtype]
194
+
195
+ response = post(
196
+ Flutterwave::Utils::Constants::CARD[:charge_url],
197
+ request_params
198
+ )
199
+
200
+ Flutterwave::Response.new(response)
201
+ end
202
+
203
+ # https://www.flutterwave.com/documentation/card-payments/#validate
204
+ def validate_charge(options = {})
205
+ @options = options
206
+
207
+ request_params = {
208
+ otp: encrypt(:otp),
209
+ otptransactionidentifier: encrypt(:otptransactionidentifier),
210
+ merchantid: client.merchant_key
211
+ }
212
+
213
+ response = post(
214
+ Flutterwave::Utils::Constants::CARD[:validate_charge_url],
215
+ request_params
216
+ )
217
+
218
+ Flutterwave::Response.new(response)
219
+ end
220
+
221
+ # https://www.flutterwave.com/documentation/card-payments/#recurrent-charge
222
+ def recurrent_charge(options = {})
223
+ @options = options
224
+ options[:country] ||= 'NG'
225
+
226
+ request_params = {
227
+ amount: encrypt(:amount),
228
+ currency: encrypt(:currency),
229
+ custid: encrypt(:custid),
230
+ country: encrypt(:country),
231
+ narration: encrypt(:narration),
232
+ chargetoken: encrypt(:chargetoken),
233
+ merchantid: client.merchant_key
234
+ }
235
+
236
+ request_params[:cardtype] = encrypt(:cardtype) if options[:cardtype]
237
+
238
+ response = post(
239
+ Flutterwave::Utils::Constants::CARD[:charge_url],
240
+ request_params
241
+ )
242
+
243
+ Flutterwave::Response.new(response)
244
+ end
245
+
246
+ # https://www.flutterwave.com/documentation/check-transaction-status/
247
+ def verify(options = {})
248
+ @options = options
249
+
250
+ request_params = {
251
+ trxreference: encrypt(:trxreference),
252
+ merchantid: client.merchant_key
253
+ }
254
+
255
+ response = post(
256
+ Flutterwave::Utils::Constants::CARD[:verify_url],
257
+ request_params
258
+ )
259
+
260
+ Flutterwave::Response.new(response)
261
+ end
262
+
263
+ def encrypt(key)
264
+ plain_text = options[key].to_s
265
+ raise Flutterwave::Utils::MissingKeyError.new(
266
+ "#{key.capitalize} key required!"
267
+ ) if plain_text.empty?
268
+
269
+ encrypt_data(plain_text, client.api_key)
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,31 @@
1
+ require 'flutterwave/utils/helpers'
2
+ require 'flutterwave/utils/missing_key_error'
3
+ require 'flutterwave/bvn'
4
+ require 'flutterwave/bin'
5
+ require 'flutterwave/ip'
6
+ require 'flutterwave/bank'
7
+ require 'flutterwave/card'
8
+ require 'flutterwave/account'
9
+ require 'flutterwave/ach'
10
+ require 'flutterwave/pay'
11
+
12
+ module Flutterwave
13
+ class Client
14
+ attr_accessor :merchant_key, :api_key, :bvn, :bin, :ip, :bank,
15
+ :card, :account, :ach, :pay
16
+
17
+ def initialize(merchant_key, api_key)
18
+ @merchant_key = merchant_key
19
+ @api_key = api_key
20
+
21
+ @bvn = Flutterwave::BVN.new(self)
22
+ @bin = Flutterwave::BIN.new(self)
23
+ @ip = Flutterwave::IP.new(self)
24
+ @bank = Flutterwave::BankAPI.new(self)
25
+ @card = Flutterwave::Card.new(self)
26
+ @account = Flutterwave::Account.new(self)
27
+ @ach = Flutterwave::ACH.new(self)
28
+ @pay = Flutterwave::Pay.new(self)
29
+ end
30
+ end
31
+ end