flutterwave_sdk 0.1.0

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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +32 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +34 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +1282 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/flutterwave_sdk.gemspec +28 -0
  14. data/lib/flutterwave_sdk/error.rb +15 -0
  15. data/lib/flutterwave_sdk/flutterwave_modules/base_endpoints.rb +5 -0
  16. data/lib/flutterwave_sdk/flutterwave_modules/util.rb +26 -0
  17. data/lib/flutterwave_sdk/flutterwave_objects/account_payment.rb +55 -0
  18. data/lib/flutterwave_sdk/flutterwave_objects/bank.rb +17 -0
  19. data/lib/flutterwave_sdk/flutterwave_objects/bank_transfer.rb +30 -0
  20. data/lib/flutterwave_sdk/flutterwave_objects/base/base.rb +109 -0
  21. data/lib/flutterwave_sdk/flutterwave_objects/base/card_base.rb +49 -0
  22. data/lib/flutterwave_sdk/flutterwave_objects/beneficiaries.rb +34 -0
  23. data/lib/flutterwave_sdk/flutterwave_objects/bills.rb +86 -0
  24. data/lib/flutterwave_sdk/flutterwave_objects/card.rb +55 -0
  25. data/lib/flutterwave_sdk/flutterwave_objects/misc.rb +37 -0
  26. data/lib/flutterwave_sdk/flutterwave_objects/mobile_money.rb +49 -0
  27. data/lib/flutterwave_sdk/flutterwave_objects/otp.rb +22 -0
  28. data/lib/flutterwave_sdk/flutterwave_objects/payment_plan.rb +42 -0
  29. data/lib/flutterwave_sdk/flutterwave_objects/preauthorise.rb +26 -0
  30. data/lib/flutterwave_sdk/flutterwave_objects/qr.rb +28 -0
  31. data/lib/flutterwave_sdk/flutterwave_objects/settlements.rb +17 -0
  32. data/lib/flutterwave_sdk/flutterwave_objects/subaccount.rb +40 -0
  33. data/lib/flutterwave_sdk/flutterwave_objects/subscriptions.rb +25 -0
  34. data/lib/flutterwave_sdk/flutterwave_objects/tokenized_charge.rb +61 -0
  35. data/lib/flutterwave_sdk/flutterwave_objects/transactions.rb +47 -0
  36. data/lib/flutterwave_sdk/flutterwave_objects/transfer.rb +46 -0
  37. data/lib/flutterwave_sdk/flutterwave_objects/ussd_payment.rb +27 -0
  38. data/lib/flutterwave_sdk/flutterwave_objects/virtual_account_number.rb +34 -0
  39. data/lib/flutterwave_sdk/flutterwave_objects/virtual_card.rb +66 -0
  40. data/lib/flutterwave_sdk/version.rb +3 -0
  41. data/lib/flutterwave_sdk.rb +126 -0
  42. metadata +88 -0
data/README.md ADDED
@@ -0,0 +1,1282 @@
1
+ <p align="center">
2
+ <img title="Flutterwave" height="200" src="https://flutterwave.com/images/logo/full.svg" width="50%"/>
3
+ </p>
4
+
5
+ # Flutterwave v3 Ruby Library
6
+
7
+ This is a Ruby gem for easy integration of Flutterwave V3 API for various applications written in Ruby language from [Flutterwave](https://rave.flutterwave.com/). See [Here](https://developer.flutterwave.com/reference) for Flutterwave V3 API Docs.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'flutterwave_sdk'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install flutterwave_sdk
24
+
25
+ ## Usage
26
+
27
+ ## Instantiate Flutterwave Object
28
+ To use [Flutterwave Ruby SDK](https://ravesandbox.flutterwave.com), you need to instantiate the RaveRuby class with your [API](https://dashboard.flutterwave.com/dashboard/settings/apis) keys which are your public, secret and encryption keys. We recommend that you store your API keys in your environment variable named `FLUTTERWAVE_PUBLIC_KEY`, `FLUTTERWAVE_SECRET_KEY` and `FLUTTERWAVE_ENCRYPTION_KEY`. Instantiating your flutterwave object after adding your API keys in your environment is as illustrated below:
29
+
30
+ ```ruby
31
+ payment = Flutterwave.new
32
+ ```
33
+ This throws a `FLUTTERWAVEBadKeyError` if no key is found in the environment variable or invalid public or secret key is found.
34
+
35
+ #### Instantiate FLutterwave object in sandbox without environment variable:
36
+
37
+ You can instantiate your Flutterwave object by setting your public, secret and encryption keys by passing them as an argument of the `Flutterwave` class just as displayed below:
38
+
39
+ ```ruby
40
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxx-X", "FLWSECK-xxxxxxxxx-X", "xxxxxxxxxxx")
41
+ ```
42
+
43
+ #### `NOTE:` It is best practice to always set your API keys to your environment variable for security purpose. Please be warned not use this package without setting your API keys in your environment variables in production.
44
+
45
+ #### To instantiate Flutterwave object in production with environment variable:
46
+
47
+ Simply use it as displayed below:
48
+
49
+ ```ruby
50
+ Payment = Flutterwave.new("YOUR_FLUTTERWAVE_LIVE_PUBLIC_KEY", "YOUR_FLUTTERWAVE_LIVE_SECRET_KEY", "YOUR_ENCRYPTION_KEY", true)
51
+ ```
52
+
53
+ ### Flutterwave Objects
54
+ - [Card.new(payment)](#cardnewpayment)
55
+ - [AccountPayment.new(payment)](#accountpaymentnewpayment)
56
+ - [Bank.new(payment)](#banknewpayment)
57
+ - [Bills.new(payment)](#billsnewpayment)
58
+ - [BankTransfer.new(payment)](banktransfernewpayment)
59
+ - [Beneficiaries.new(payment)](#beneficiariesnewpayment)
60
+ - [USSD.new(payment)](#ussdnewpayment)
61
+ - [Transfer.new(payment)](#transfernewpayment)
62
+ - [VirtualCard.new(payment)](#virtualcardnewpayment)
63
+ - [TokenizedCharge.new(payment)](#tokenizedchargenewpayment)
64
+ - [Settlements.new(payment)](#settlementsnewpayment)
65
+ - [QR.new(payment)](#qrnewpayment)
66
+ - [Transactions.new(payment)](#transactionsnewpayment)
67
+ - [VirtualAccountNumber.new(payment)](#virtualaccountnumbernewpayment)
68
+ - [Subscriptions.new(payment)](#subscriptionsnewpayment)
69
+ - [OTP.new(payment)](#otpnewpayment)
70
+ - [Subaccount.new(payment)](#subaccountnewpayment)
71
+ - [PaymentPlan.new(payment)](#paymentplannewpayment)
72
+ - [MobileMoney.new(payment)](#mobilemoneynewpayment)
73
+ - [Misc.new(payment)](#miscnewpayment)
74
+ - [Preauth.new(payment)](preauthnewpayment)
75
+
76
+ ## Card.new(payment)
77
+
78
+ > <mark>NB - Flutterwave's direct card charge endpoint requires PCI-DSS compliance </mark>
79
+
80
+ > To charge cards, you will need to be PCI DSS compliant. If you are, you can proceed to charge cards.
81
+ Alternatively, you can use any of our other payment methods such as Standard, Inline or SDKs which do not require processing card details directly and do not also require payload encryption.
82
+
83
+
84
+ To perform account transactions, instantiate the card object and pass Flutterwave object as its argument.
85
+ #### Its functions includes:
86
+
87
+ - .initiate_charge
88
+ - .validate_charge
89
+ - .verify_charge
90
+
91
+
92
+ ## Full Account Transaction Flow
93
+
94
+ ```ruby
95
+ require './flutterwave_sdk'
96
+
97
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
98
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxx-X", "FLWSECK-xxxxxxxxx-X", "xxxxxxxxxxxxxxxxxxxxxxx")
99
+
100
+ # This is used to perform card charge
101
+
102
+ payload = {
103
+
104
+ "card_number" => "5531886652142950",
105
+ "cvv" => "564",
106
+ "expiry_month" => "09",
107
+ "expiry_year" => "22",
108
+ "currency" => "NGN",
109
+ "amount" => "10",
110
+ "email" => "xxxxxxxxxx@gmail.com",
111
+ "fullname" => "Test Name",
112
+ "tx_ref" => "MC-3243e-if-12",
113
+ "redirect_url" => "https://webhook.site/399"
114
+
115
+ }
116
+ charge_card = Card.new(payment)
117
+
118
+ response = charge_card.initiate_charge(payload)
119
+ puts response
120
+
121
+ # update payload with suggested auth
122
+ if response["meta"]["authorization"]["mode"]
123
+ suggested_auth = response["meta"]["authorization"]["mode"]
124
+ auth_arg = charge_card.get_auth_type(suggested_auth)
125
+ if auth_arg == :pin
126
+ updated_payload = charge_card.update_payload(suggested_auth, payload, pin: { "pin" => "3310"} )
127
+ elsif auth_arg == :address
128
+ updated_payload = charge_card.update_payload(suggested_auth, payload, address:{ "zipcode"=> "07205", "city"=> "Hillside", "address"=> "470 Mundet PI", "state"=> "NJ", "country"=> "US"})
129
+ end
130
+
131
+ # perform the second charge after payload is updated with suggested auth
132
+ response = charge_card.initiate_charge(updated_payload)
133
+ print response
134
+
135
+ # perform validation if it is required
136
+ if response["data"]["status"] == "pending" || "success-pending-validation"
137
+ response = charge_card.validate_charge(response["data"]["flw_ref"], "12345")
138
+ print response
139
+ end
140
+ else
141
+ # You can handle the get the auth url from this response and load it for the customer to complete the transaction if an auth url is returned in the response.
142
+ print response
143
+ end
144
+
145
+ # verify charge
146
+ response = charge_card.verify_charge(response["data"]["id"])
147
+ print response
148
+
149
+ ```
150
+
151
+ ## AccountPayment.new(payment)
152
+ #### Its functions includes:
153
+
154
+ - .initiate_charge
155
+ - .validate_charge
156
+ - .verify_charge
157
+
158
+ ## Full Account Transaction Flow
159
+
160
+ ```ruby
161
+ require './flutterwave_sdk'
162
+
163
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
164
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxx-X", "FLWSECK-xxxxxxx-X", "xxxxxxx")
165
+
166
+ payload = {
167
+ "tx_ref" => "MC-1585230ew9v505010",
168
+ "amount" => "100",
169
+ "account_bank" => "044",
170
+ "account_number" => "0690000037",
171
+ "currency" => "NGN",
172
+ "email" => "xxxxxxx@gmail.com",
173
+ "phone_number" => "09000000000",
174
+ "fullname" => "Test Name"
175
+ }
176
+
177
+ account_payment_ng = AccountPayment.new(payment)
178
+
179
+ response = account_payment_ng.initiate_charge(payload)
180
+ print response
181
+
182
+ #validate payment with OTP
183
+ if response["data"]["meta"]["authorization"]["mode"] == "otp"
184
+ response = account_payment_ng.validate_charge(response["data"]["flw_ref"], "12345")
185
+ print response
186
+ else
187
+ print response
188
+
189
+ end
190
+
191
+ #verify transaction
192
+ response = account_payment_ng.verify_charge(response["data"]["tx_ref"])
193
+
194
+ print response
195
+
196
+ ```
197
+
198
+
199
+ ## Bank.new(payment)
200
+ #### Its functions includes:
201
+
202
+ - .get_all_banks
203
+ - .get_bank_branch
204
+
205
+ ## See the full flow below
206
+
207
+ ```ruby
208
+
209
+ require './flutterwave_sdk'
210
+
211
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
212
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxx-X", "FLWSECK-xxxxxxxxxx-X", "xxxxxxxxx")
213
+ bank = Bank.new(payment)
214
+
215
+ #get all banks
216
+ response = bank.get_all_banks("NG")
217
+ print response
218
+
219
+ # get bank branches
220
+ response = bank.get_bank_branch(280)
221
+ print response
222
+
223
+ ```
224
+
225
+ ## Bills.new(payment)
226
+ #### Its functions includes:
227
+
228
+ - .create_bill_payment
229
+ - .create_bulk_bill_payments
230
+ - .get_status_of_a_bill_payment
231
+ - .update_bills_order
232
+ - .validate_bill_service
233
+ - .get_bill_categories
234
+ - .get_bill_payment_agencies
235
+ - .get_amount_for_a_product
236
+ - .get_bill_payments
237
+ - .get_products_under_an_agency
238
+ - .create_order_using_billing_code_and_productid
239
+
240
+ ## See full flow below
241
+
242
+ ```ruby
243
+ require './flutterwave_sdk'
244
+
245
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
246
+ payment = Flutterwave.new("FLWPUBK_TEST-3xxxxxxxxxx-X", "FLWSECK_TEST-xxxxxxxxx-X", "xxxxxxxxxxxxx")
247
+ bill = Bills.new(payment)
248
+
249
+
250
+ # Create a bill payment
251
+ payload = {
252
+ "country" => "NG",
253
+ "customer" => "+23490803840303",
254
+ "amount" => 500,
255
+ "recurrence" => "ONCE",
256
+ "type" => "AIRTIME",
257
+ "reference" => "ifunaya-0987654"
258
+ }
259
+
260
+ response = bill.create_bill_payment(payload)
261
+ print response
262
+
263
+ #bulk bill payments
264
+ payload = {
265
+ "bulk_reference" => "edf-12de5223d2f32",
266
+ "callback_url" => "https://webhook.site/5f9a659a-11a2-4925-89cf-8a59ea6a019a",
267
+ "bulk_data" => [
268
+ {
269
+ "country" => "NG",
270
+ "customer" => "+23490803840303",
271
+ "amount" => 500,
272
+ "recurrence" => "WEEKLY",
273
+ "type" => "AIRTIME",
274
+ "reference" => "930049200929"
275
+ },
276
+ {
277
+ "country" => "NG",
278
+ "customer" => "+23490803840304",
279
+ "amount" =>500,
280
+ "recurrence" => "ONCE",
281
+ "type": "AIRTIME",
282
+ "reference" => "930004912332"
283
+ }
284
+ ]
285
+ }
286
+
287
+ response = bill.create_bulk_bill_payments(payload)
288
+ print response
289
+
290
+
291
+ #get the status of a bill payment
292
+ response = bill.get_status_of_a_bill_payment("BPUSSD1591303717500102")
293
+ print response
294
+
295
+ #get billers categories
296
+ response = bill.get_bill_categories
297
+ print response
298
+ ```
299
+
300
+ ## BankTransfer.new(payment)
301
+ #### Its functions includes:
302
+
303
+ - .initiate_charge
304
+ - .verify_charge
305
+
306
+ ## See full flow below
307
+
308
+ ```ruby
309
+
310
+ require './flutterwave_sdk'
311
+
312
+ # This is a FLutterwave object which is expecting public, secret and encrption keys
313
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxx-X", "FLWSECK-xxxxxxxxx-X", "xxxxxxxxxxx")
314
+
315
+ payload = {
316
+ "tx_ref" => "MC-158523095056793",
317
+ "amount" => "1500",
318
+ "email" => "xxxxxxxxx@gmail.com",
319
+ "phone_number" => "054709929220",
320
+ "currency" => "NGN",
321
+ "duration" => 2,
322
+ "frequency" => 5,
323
+ "narration" => "All star college salary for May",
324
+ "is_permanent" => 1
325
+ }
326
+
327
+ bank_transfer = BankTransfer.new(payment)
328
+
329
+ response = bank_transfer.initiate_charge(payload)
330
+
331
+ print response
332
+
333
+ # verify transaction
334
+ response = bank_transfer.verify_charge(response["data"]["tx_ref"])
335
+
336
+ print response
337
+ ```
338
+
339
+ ## Beneficiaries.new(payment)
340
+ #### Its functions includes:
341
+
342
+ - .create_beneficiary
343
+ - .list_beneficiaries
344
+ - .fetch_beneficiary
345
+ - .delete_beneficiary
346
+
347
+ ## See full flow below
348
+
349
+ ```ruby
350
+ require './flutterwave_sdk'
351
+
352
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
353
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxx-X", "FLWSECK-xxxxxxxx-X", "xxxxxxxxxx")
354
+ Beneficiary = Beneficiaries.new(payment)
355
+
356
+ #create a beneficiary
357
+ payload = {
358
+ "account_number" => "0690000032",
359
+ "account_bank" => "044"
360
+ }
361
+
362
+ response = Beneficiary.create_beneficiary(payload)
363
+ print response
364
+
365
+ #list beneficiaries
366
+
367
+ response = Beneficiary.list_beneficiaries
368
+
369
+ print response
370
+
371
+
372
+ #fetch beneficiary
373
+ response = Beneficiary.fetch_beneficiary(7369)
374
+ print response
375
+
376
+
377
+ #delete beneficiary
378
+ response = Beneficiary.delete_beneficiary(7369)
379
+ print response
380
+
381
+ ```
382
+
383
+ ## USSD.new(payment)
384
+ #### Its functions includes:
385
+
386
+ - .initiate_charge
387
+ - .verify_charge
388
+
389
+ ## See full flow below
390
+
391
+ ```ruby
392
+
393
+ require './flutterwave_sdk'
394
+
395
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
396
+ payment = Flutterwave.new("FLWPUBK-xxxxxxx-X", "FLWSECK-xxxxxxx-X", "xxxxxx")
397
+
398
+ payload = {
399
+ "tx_ref" => "MC-15852309v5050w34",
400
+ "account_bank" => "044",
401
+ "amount" => "1500",
402
+ "currency" => "NGN",
403
+ "email" => "xxxxxxxxxxxxx@gmail.com",
404
+ "phone_number" => "054709929220",
405
+ "fullname" => "Test Name"
406
+
407
+ }
408
+
409
+ ussd = USSD.new(payment)
410
+
411
+ response = ussd.initiate_charge(payload)
412
+ print response
413
+
414
+
415
+ # verify transactioin with the id
416
+ response = ussd.verify_charge(283516336)
417
+ print response
418
+
419
+ ```
420
+
421
+ ## Transfer.new(payment)
422
+ #### Its functions includes:
423
+
424
+ - .transfer_fee
425
+ - .initiate_transfer
426
+ - .initiate_bulk_transfer
427
+ - .get_all_transfers
428
+ - .get_a_transfer
429
+
430
+ ## See full flow below
431
+
432
+ ```ruby
433
+
434
+
435
+ require './flutterwave_sdk'
436
+
437
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
438
+ payment = Flutterwave.new("FLWPUBK-xxxxxxx-X", "FLWSECK-xxxxxxx-X", "xxxxxxxxx")
439
+
440
+ transfer = Transfer.new(payment)
441
+ payload = {
442
+ "account_bank" => "044",
443
+ "account_number" => "0690000040",
444
+ "amount" => 5000,
445
+ "narration" => "Akhlm Pstmn Trnsfr xx007",
446
+ "currency" => "NGN",
447
+ "reference" => "eightm-pstmnpyt-rfxx007_P0MCKDU_1",
448
+ "callback_url" => "https://webhook.site/b3e505b0-fe02-430e-a538-22bbbce8ce0d",
449
+ "debit_currency" => "NGN"
450
+ }
451
+
452
+ response = transfer.initiate_transfer(payload)
453
+ print response
454
+
455
+
456
+ # get transfer fee
457
+ currency = "NGN"
458
+ amount = "5000"
459
+ response = transfer.transfer_fee(currency, amount)
460
+ print response
461
+
462
+ #get all transfers
463
+ response = transfer.get_all_transfers
464
+ print response
465
+
466
+ #get a transfer
467
+ response = transfer.get_a_transfer(125445)
468
+ print response
469
+
470
+ ```
471
+
472
+ ## VirtualCard.new(payment)
473
+ #### Its functions includes:
474
+
475
+ - .create_virtual_card
476
+ - .get_all_virtual_cards
477
+ - .get_virtual_card
478
+ - .fund_virtual_card
479
+ - .terminate_virtual_card
480
+ - .get_virtual_card_transactions
481
+ - .withdraw_from_virtual_card
482
+ - .block_unblock_virtual_card
483
+
484
+
485
+ ## See full flow below
486
+
487
+ ```ruby
488
+
489
+ require './flutterwave_sdk'
490
+
491
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
492
+ payment = Flutterwave.new("FLWPUBK_TEST-xxxxxxxx-X", "FLWSECK_TEST-xxxxxx-X", "xxxxxxxxx")
493
+ virtual_card = VirtualCard.new(payment)
494
+
495
+
496
+ create virtual card
497
+ payload = {"currency" => "NGN",
498
+ "amount" => 20000,
499
+ "billing_name" => "Test Name",
500
+ "billing_address" => "2014 Forest Hills Drive",
501
+ "billing_city" => "Node",
502
+ "billing_state" => "Javascript",
503
+ "billing_postal_code" => "000009",
504
+ "billing_country" => "NG",
505
+ "callback_url" => "https://your-callback-url.com/"
506
+ }
507
+
508
+ response = virtual_card.create_virtual_card(payload)
509
+
510
+ print response
511
+
512
+
513
+ #get all virtual cards
514
+ response = virtual_card.get_all_virtual_cards
515
+ print response
516
+
517
+
518
+ #get a virtual card
519
+ response = virtual_card.get_virtual_card("594715a6-ae77-483c-811e-19057aedacff")
520
+ print response
521
+
522
+
523
+ #fund a virtual card
524
+ payload = {
525
+ "debit_currency" => "NGN",
526
+ "amount" => 4000
527
+ }
528
+
529
+ id = "594715a6-ae77-483c-811e-19057aedacff"
530
+ response = virtual_card.fund_virtual_card(id, payload)
531
+ print response
532
+
533
+ #get virtual card transactions
534
+ from = "2019-01-01"
535
+ to = "2020-01-13"
536
+ index = 0
537
+ size = 1
538
+
539
+ response = virtual_card.get_virtual_card_transactions("594715a6-ae77-483c-811e-19057aedacff", from, to, index, size)
540
+
541
+
542
+ #withdraw from a virtual card
543
+ payload = {
544
+ "amount" => "1000"
545
+ }
546
+
547
+ id = "594715a6-ae77-483c-811e-19057aedacff"
548
+
549
+ response = virtual_card.withdraw_from_virtual_card(id,payload)
550
+ print response
551
+
552
+ #block/unblock virtualcard
553
+ id = "594715a6-ae77-483c-811e-19057aedacff"
554
+ status_action = "unblock"
555
+ response = virtual_card.block_unblock_virtual_card(id,status_action)
556
+ print response
557
+
558
+ ```
559
+
560
+ ## TokenizedCharge.new(payment)
561
+ #### Its functions includes:
562
+
563
+ - .tokenized_charge
564
+ - .verify_tokenized_charge
565
+ - .update_token
566
+ - .bulk_tokenized_charge
567
+ - .bulk_tokenized_charge_status
568
+ - .bulk_tokenized_charge_transactions
569
+
570
+ ## See full flow below
571
+
572
+ ```ruby
573
+ require './flutterwave_sdk'
574
+
575
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
576
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxxx-X", "FLWSECK-xxxxxxxxxx-X", "xxxxxxxxxxxxx")
577
+
578
+ # This is used to perform card charge
579
+ payload = {
580
+ "token" => "flw-t1nf-264db944ee46d0a2627573a496f5432c-m03k",
581
+ "currency" => "NGN",
582
+ "country" => "NG",
583
+ "amount" => "10",
584
+ "email" => "user@example.com",
585
+ "first_name" => "Test",
586
+ "last_name" => "Name",
587
+ "ip" => "pstmn",
588
+ "narration" => "testing charge with token"
589
+ }
590
+
591
+ charge_with_token = TokenizedCharge.new(payment)
592
+ response = charge_with_token.tokenized_charge(payload)
593
+ print response
594
+
595
+ # Verify tokenized transaction
596
+ response = charge_with_token.verify_tokenized_charge(response["data"]["tx_ref"])
597
+ print response
598
+
599
+
600
+ #update token
601
+ payload = {
602
+ "email" => "user@example.com",
603
+ "first_name" => "Test",
604
+ "last_name" => "Name",
605
+ "phone_number" => "09000000000000"
606
+ }
607
+ charge_with_token = TokenizedCharge.new(payment)
608
+
609
+ token = "flw-t1nf-264db944ee46d0a2627573a496f5432c-m03k"
610
+
611
+ response = charge_with_token.update_token(payload, token)
612
+ print response
613
+
614
+
615
+ #bulk tokenized charge
616
+
617
+ payload = {
618
+ "title" => "test",
619
+ "retry_strategy" => {
620
+ "retry_interval" => 120,
621
+ "retry_amount_variable" => 60,
622
+ "retry_attempt_variable" => 2,
623
+ },
624
+ "bulk_data" => [
625
+ {
626
+ "token" => "flw-t1nf-264db944ee46d0a2627573a496f5432c-m03k",
627
+ "currency" => "NGN",
628
+ "country" => "NG",
629
+ "amount" => "10",
630
+ "email" => "user@example.com",
631
+ "first_name" => "Test",
632
+ "last_name" => "Name",
633
+ "ip" => "pstmn",
634
+ "narration" => "testing charge with token",
635
+ },
636
+ {
637
+ "token" => "flw-t1nf-264db944ee46d0a2627573a496f5432c-m03k",
638
+ "currency" => "NGN",
639
+ "country" => "NG",
640
+ "amount" => "10",
641
+ "email" => "user@example.com",
642
+ "first_name" => "Test",
643
+ "last_name" => "Name",
644
+ "ip" => "pstmn",
645
+ "narration" => "testing charge with token"
646
+ }
647
+ ]
648
+ }
649
+
650
+ charge_with_token = TokenizedCharge.new(payment)
651
+ response = charge_with_token.bulk_tokenized_charge(payload)
652
+
653
+ print response
654
+
655
+
656
+ #get status of bulk tokenized charges
657
+ id = 175
658
+ charge_with_token = TokenizedCharge.new(payment)
659
+ response = charge_with_token.bulk_tokenized_charge_status(id)
660
+ print response
661
+
662
+
663
+ #fetch bulk tokenized transactions
664
+ id = 175
665
+ charge_with_token = TokenizedCharge.new(payment)
666
+ response = charge_with_token.bulk_tokenized_charge_transactions(id)
667
+ print response
668
+
669
+ ```
670
+
671
+ ## Settlements.new(payment)
672
+ #### Its functions includes:
673
+
674
+ - .get_settlements
675
+ - .get_settlement
676
+
677
+ ## See full flow below
678
+
679
+ ```ruby
680
+ require './flutterwave_sdk'
681
+
682
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
683
+ payment = Flutterwave.new("FLWPUBK_TEST-xxxxxxxxx-X", "FLWSECK_TEST-xxxxxxxxxx-X", "xxxxxxxxxxxxx")
684
+ settlement = Settlements.new(payment)
685
+
686
+
687
+ # get all settlements
688
+ response = settlement.get_settlements
689
+ print response
690
+
691
+
692
+ #get a settlment
693
+ response =settlement.get_settlement(63016)
694
+ print response
695
+
696
+ ```
697
+
698
+ ## QR.new(payment)
699
+ #### Its functions includes:
700
+
701
+ - .initiate_charge
702
+ - .verify_charge
703
+
704
+ ## See full flow below
705
+
706
+ ```ruby
707
+
708
+ require './flutterwave_sdk'
709
+
710
+ # This is a FLutterwave object which is expecting public, secret and encrption keys
711
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxx-X", "FLWSECK-xxxxxxxxxxxxxxx-X", "xxxxxxxxxxxxxxxx")
712
+
713
+ payload = {
714
+ "tx_ref" => "MC-15852309v5050w34",
715
+ "amount" => "1500",
716
+ "currency" => "NGN",
717
+ "email" => "xxxxxxxxxxxx@gmail.com",
718
+ "phone_number" => "090000000000",
719
+ "fullname" => "Test name"
720
+
721
+ }
722
+
723
+ qr = QR.new(payment)
724
+
725
+ response = qr.initiate_charge(payload)
726
+ print response
727
+
728
+ # verify QR transaction
729
+ response = qr.verify_charge(response["data"]["tx_ref"])
730
+ print response
731
+
732
+ ```
733
+
734
+ ## Transactions.new(payment)
735
+ #### Its functions includes:
736
+
737
+ - .transaction_fee
738
+ - .get_transactions
739
+ - .verify_transaction
740
+ - .transactions_events
741
+ - .initiate_a_refund
742
+ - .resend_transaction_webhook
743
+
744
+ ## see full flow below
745
+
746
+ ```ruby
747
+
748
+ require './flutterwave_sdk'
749
+
750
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
751
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxx-X", "FLWSECK-xxxxxxxxxxxxxxxxxx-X", "xxxxxxxxxxxxxxx")
752
+
753
+ fee = Transactions.new(payment)
754
+ currency = "NGN"
755
+ amount = "1000"
756
+ response = fee.transaction_fee(currency, amount)
757
+ print response
758
+
759
+
760
+ # get Transactions
761
+ fee = Transactions.new(payment)
762
+ response = fee.get_transactions
763
+ print response
764
+
765
+ # get transaction events
766
+ fee = Transactions.new(payment)
767
+ response = fee.transactions_events(1321548)
768
+ print response
769
+
770
+ # initiate a refund
771
+ payload = {
772
+ "amount" => "5"
773
+ }
774
+ # id = 1321548
775
+ fee = Transactions.new(payment)
776
+ response = fee.initiate_a_refund(payload, 1321548)
777
+ print response
778
+
779
+ #resend transaction webhook
780
+ payload = {
781
+ "id" => 1321548
782
+ }
783
+ fee = Transactions.new(payment)
784
+ response = fee.resend_transactions_webhook(payload)
785
+ print response
786
+
787
+ ```
788
+
789
+ ## VirtualAccountNumber.new(payment)
790
+ #### Its functions includes:
791
+
792
+ - .create_virtual_account_number
793
+ - .create_bulk_virtual_account_number
794
+ - .get_bulk_virtual_account_number
795
+ - .get_virtual_account_number
796
+
797
+ # see full flow below
798
+
799
+ ```ruby
800
+
801
+ require './flutterwave_sdk'
802
+
803
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
804
+ payment = Flutterwave.new("FLWPUBK_TEST-xxxxxxxx-X", "FLWSECK_TEST-xxxxxxxxxx-X", "xxxxxxxxx")
805
+ account_number = VirtualAccountNumber.new(payment)
806
+
807
+
808
+ # #create virtual account number
809
+ payload = {
810
+ "email" => "xxxxxxxxxx@gmail.com",
811
+ "duration" => 5,
812
+ "frequency" => 5,
813
+ "is_permanent" => true,
814
+ "tx_ref" => "jhn-Test-10192029920"
815
+ }
816
+
817
+ response = account_number.create_virtual_account_number(payload)
818
+ print response
819
+
820
+ #bulk account number
821
+ payload = {
822
+ "email" => "xxxxxxxxx@gmail.com",
823
+ "duration" => 5,
824
+ "accounts" => 5,
825
+ "is_permanent" => true,
826
+ "tx_ref" => "jhn-Test-10192029920"
827
+ }
828
+
829
+ response = account_number.create_bulk_virtual_account_number(payload)
830
+ print response
831
+
832
+
833
+ # get bulk virtual account number
834
+ response = account_number.get_bulk_virtual_account_number("-RND_1071591303048505")
835
+ print response
836
+
837
+ # Get a virtual account number
838
+ response = account_number.get_virtual_account_number("URF_1591302653177_6055335")
839
+ print response
840
+
841
+ ```
842
+
843
+ ## Subscriptions.new(payment)
844
+ #### Its functions includes:
845
+
846
+ - .get_all_subscriptions
847
+ - .cancel_subscription
848
+ - .activate_subscription
849
+
850
+ # see full flow below
851
+
852
+ ```ruby
853
+ require './flutterwave_sdk'
854
+
855
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
856
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxx-X", "FLWSECK-xxxxxxxxxx-X", "xxxxxxxxxxx")
857
+ subscription = Subscriptions.new(payment)
858
+
859
+ #get all subscriptions
860
+ response = subscription.get_all_subscriptions
861
+ print response
862
+
863
+ #cancel subscription
864
+ response = subscription.cancel_subscription(247490)
865
+ print response
866
+
867
+ #activate subcription
868
+ response = subscription.activate_subscription(247490)
869
+ print response
870
+
871
+ ```
872
+
873
+ ## OTP.new(payment)
874
+ #### Its functions includes:
875
+
876
+ - .create_otp
877
+ - .validate_otp
878
+
879
+ # see full flow below
880
+
881
+ ```ruby
882
+ require './flutterwave_sdk'
883
+
884
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
885
+ payment = Flutterwave.new("FLWPUBK_TEST-xxxxxxxxxxxxxx-X", "FLWSECK_TEST-xxxxxxxxxxxx-X", "xxxxxxxxx")
886
+ otp = OTP.new(payment)
887
+
888
+ payload = {
889
+ "length" => 7,
890
+ "customer" => { "name" => "Test", "email" => "xxxxxxxxxxx@gmail.com", "phone" => "2348131149273" },
891
+ "sender" => "Test Name",
892
+ "send" => true,
893
+ "medium" => ["email", "whatsapp"],
894
+ "expiry" => 5
895
+ }
896
+
897
+ response = otp.create_otp(payload)
898
+ print response
899
+
900
+ #validate otp
901
+ payload = {
902
+ "otp" => 481208
903
+ }
904
+
905
+ reference = "CF-BARTER-20190420022611377491"
906
+ response = otp.validate_otp(reference, payload)
907
+ print response
908
+
909
+ ```
910
+
911
+ ## Subaccount.new(payment)
912
+ #### Its functions includes:
913
+
914
+ - .create_subaccount
915
+ - .fetch_subaccounts
916
+ - .fetch_subaccount
917
+ - .update_subaccount
918
+ - .delete_subaccount
919
+
920
+ ## see full flow below
921
+
922
+ ```ruby
923
+ require './flutterwave_sdk'
924
+
925
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
926
+ payment = Flutterwave.new("FLWPUBK_TEST-xxxxxxxx-X", "FLWSECK_TEST-xxxxxxxx-X", "xxxxxx")
927
+ subaccount = Subaccount.new(payment)
928
+
929
+ #create subaccount
930
+ payload = {
931
+ "account_bank" => "044",
932
+ "account_number" => "0690000036",
933
+ "business_name" => "Test Name",
934
+ "business_email" => "xxxxxx@gmail.com",
935
+ "business_contact" => "Anonymous",
936
+ "business_contact_mobile" => "090890382",
937
+ "business_mobile" => "09087930450",
938
+ "country" => "NG",
939
+ "split_type" => "percentage",
940
+ "split_value" => 0.5
941
+ }
942
+
943
+ reponse = subaccount.create_subaccount(payload)
944
+ print reponse
945
+
946
+ #fetch all subaccounts
947
+ reponse = subaccount.fetch_subaccounts
948
+ print reponse
949
+
950
+
951
+ #fetch a sub account
952
+ reponse = subaccount.fetch_subaccount(5740)
953
+ print reponse
954
+
955
+
956
+ #update subaccount
957
+ payload = {
958
+ "business_email" => "xxxxx@gmail.com"
959
+ }
960
+ id = 5740
961
+ reponse = subaccount.update_subaccount(id, payload)
962
+ print reponse
963
+
964
+
965
+ #delete subaccount
966
+ reponse = subaccount.delete_subaccount(5740)
967
+ print reponse
968
+
969
+ ```
970
+
971
+ ## PaymentPlan.new(payment)
972
+ #### Its functions includes:
973
+
974
+ - .create_payment_plan
975
+ - .get_payment_plans
976
+ - .get_a_payment_plan
977
+ - .update_payment_plan
978
+ - .cancel_payment_plan
979
+
980
+ ## see full flow below
981
+
982
+ ```ruby
983
+ require './flutterwave_sdk'
984
+
985
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
986
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxx-X", "FLWSECK-xxxxxxxxxx-X", "xxxxxxxxxxxxx")
987
+ payment_plan = PaymentPlan.new(payment)
988
+
989
+ #create payment plan
990
+ payload = {
991
+ "amount" => 5000,
992
+ "name" => "the akhlm postman plan 2",
993
+ "interval" => "monthly",
994
+ "duration" => 48
995
+ }
996
+
997
+ response = payment_plan.create_payment_plan(payload)
998
+ print response
999
+
1000
+
1001
+ #get payment plans
1002
+ response = payment_plan.get_payment_plans
1003
+ print response
1004
+
1005
+ #get a payment plan
1006
+ response = payment_plan.get_a_payment_plan(5981)
1007
+ print response
1008
+
1009
+ #update a payment plan
1010
+ payload = {
1011
+ "name" => "Test name",
1012
+ "status" => "active"
1013
+ }
1014
+
1015
+ response = payment_plan.update_payment_plan(5981, payload)
1016
+ print response
1017
+
1018
+ #cancel payment plan
1019
+ response = payment_plan.cancel_payment_plan(5981)
1020
+ print response
1021
+
1022
+ ```
1023
+
1024
+ ## MobileMoney.new(payment)
1025
+ #### Its functions includes:
1026
+
1027
+ - .initiate_charge
1028
+ - .verify_charge
1029
+
1030
+ ## see full flow below
1031
+
1032
+ ```ruby
1033
+ require './flutterwave_sdk'
1034
+
1035
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
1036
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxxxxxxx-X", "FLWSECK-xxxxxxxxxxxx-X", "xxxxxxxxxx")
1037
+
1038
+ # This is used to perform Mpesa transaction
1039
+ payload = {
1040
+ "tx_ref" => "khlm-158943942o3",
1041
+ "amount" => "50",
1042
+ "currency" => "KES",
1043
+ "email" => "johnmadakin@gmail.com",
1044
+ "phone_number" => "054709929220",
1045
+ "fullname" => "John Madakin",
1046
+ "client_ip" => "154.123.220.1",
1047
+ "device_fingerprint" => "62wd23423rq32dskd4323qew1"
1048
+
1049
+ }
1050
+
1051
+ charge_mpesa = MobileMoney.new(payment)
1052
+
1053
+ response = charge_mpesa.initiate_charge(payload)
1054
+ print response
1055
+
1056
+ #verify transaction
1057
+ response = charge_mpesa.verify_charge(response["data"]["tx_ref"])
1058
+ print response
1059
+
1060
+
1061
+ #zambia test
1062
+
1063
+ payload = {
1064
+ "tx_ref" => "MC-158523s09v5050e8",
1065
+ "amount" => "1500",
1066
+ "currency" => "ZMW",
1067
+ "network" => "MTN",
1068
+ "email" => "xxxxxxxxxx@gmail.com",
1069
+ "phone_number" => "054709929220",
1070
+ "fullname" => "Test Name"
1071
+ }
1072
+
1073
+ charge_zambia = MobileMoney.new(payment)
1074
+
1075
+ response = charge_zambia.initiate_charge(payload)
1076
+ print response
1077
+
1078
+ #verify transaction
1079
+ response = charge_zambia.verify_charge(response["data"]["tx_ref"])
1080
+ print response
1081
+
1082
+
1083
+ # # Ghana mobile money test
1084
+ payload = {
1085
+ "tx_ref" => "MC-158523s09v5050e8",
1086
+ "amount" => "150",
1087
+ "currency" => "GHS",
1088
+ "voucher" => "143256743",
1089
+ "network" => "MTN",
1090
+ "email" => "xxxxx@gmail.com",
1091
+ "phone_number" => "054709929220",
1092
+ "fullname": "Test Name"
1093
+ }
1094
+
1095
+ charge_ghana = MobileMoney.new(payment)
1096
+
1097
+ #initiate transaction
1098
+ response = charge_ghana.initiate_charge(payload)
1099
+ print response
1100
+
1101
+ #verify transaction
1102
+ response = charge_ghana.verify_charge(response["data"]["tx_ref"])
1103
+ print response
1104
+
1105
+
1106
+ # Rwanda mobile money test
1107
+
1108
+ payload = {
1109
+ "tx_ref" => "MC-158523s09v5050e8",
1110
+ "amount" => "1500",
1111
+ "currency" => "RWF",
1112
+ "network" => "MTN",
1113
+ "email" => "xxxxx@gmail.com",
1114
+ "phone_number" => "054709929220",
1115
+ "fullname" => "Test Name"
1116
+ }
1117
+
1118
+ charge_rwanda = MobileMoney.new(payment)
1119
+
1120
+ response = charge_rwanda.initiate_charge(payload)
1121
+ print response
1122
+
1123
+ # verify transaction
1124
+ response = charge_rwanda.verify_charge(response["data"]["tx_ref"])
1125
+ print response
1126
+
1127
+
1128
+ #uganda test
1129
+
1130
+ payload = {
1131
+ "tx_ref" => "MC-1585230950500",
1132
+ "amount" => "1500",
1133
+ "email" => "xxxxxxxx@gmail.com",
1134
+ "phone_number" => "054709929220",
1135
+ "currency" => "UGX",
1136
+ "redirect_url" => "https://rave-webhook.herokuapp.com/receivepayment",
1137
+ "network" => "MTN"
1138
+
1139
+ }
1140
+
1141
+ charge_uganda = MobileMoney.new(payment)
1142
+
1143
+ response = charge_uganda.initiate_charge(payload)
1144
+ print response
1145
+
1146
+ response = charge_uganda.verify_charge(response["data"]["tx_ref"])
1147
+ print response
1148
+
1149
+ # franco phone
1150
+ payload = {
1151
+ "tx_ref" => "MC-1585230950501",
1152
+ "amount" => "1500",
1153
+ "email" => "xxxxxx@gmail.com",
1154
+ "phone_number" => "054709929220",
1155
+ "currency" => "XAF",
1156
+ "redirect_url" => "https://rave-webhook.herokuapp.com/receivepayment"
1157
+
1158
+ }
1159
+
1160
+ charge_franco = MobileMoney.new(payment)
1161
+
1162
+ response = charge_franco.initiate_charge(payload)
1163
+ print response
1164
+
1165
+
1166
+ response = charge_franco.verify_charge(response["data"]["tx_ref"])
1167
+ print response
1168
+ ```
1169
+
1170
+ ## Misc.new(payment)
1171
+ #### Its functions includes:
1172
+
1173
+ _ .get_all_wallet_balance
1174
+ - .get_balance_per_currency
1175
+ - .resolve_account
1176
+ - .resolve_bvn
1177
+ - .resolve_card_bin
1178
+
1179
+ ## see full flow below
1180
+
1181
+ ```ruby
1182
+ require './flutterwave_sdk'
1183
+
1184
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
1185
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxxx-X", "FLWSECK-xxxxx-X", "xxxxxxxxxxxxxxx")
1186
+ misc = Misc.new(payment)
1187
+
1188
+ #get all wallet balance
1189
+ response = misc.get_all_wallet_balance
1190
+ print response
1191
+
1192
+
1193
+ #get balance per cuurency
1194
+ response = misc.get_balance_per_currency("NGN")
1195
+ print response
1196
+
1197
+ #resolve account
1198
+ payload = {
1199
+ "account_number" => "0690000032",
1200
+ "account_bank" => "044"
1201
+ }
1202
+ response = misc.resolve_account(payload)
1203
+
1204
+ print response
1205
+
1206
+ #resolve bvn
1207
+ response = misc.resolve_bvn("12345678901")
1208
+ print response
1209
+
1210
+
1211
+ #resolve card bin
1212
+ response = misc.resolve_card_bin(553188)
1213
+ print response
1214
+
1215
+ ```
1216
+
1217
+ ## Preauth.new(payment)
1218
+ #### Its functions includes:
1219
+
1220
+ - .capture_preauth
1221
+ - .void_preauth
1222
+ - .refund_preauth
1223
+
1224
+ ## see full flow below
1225
+
1226
+ ```ruby
1227
+ require './flutterwave_sdk'
1228
+
1229
+ # This is a Flutterwave object which is expecting public, secret and encrption keys
1230
+ payment = Flutterwave.new("FLWPUBK-xxxxxxxxx-X", "xxxxxxxxxxxxxx", "xxxxxxxxxxxxxx")
1231
+
1232
+ # This is used to perform preauth capture
1233
+
1234
+ auth = Preauth.new(payment)
1235
+
1236
+ payload = {
1237
+ "amount" => "50"
1238
+ }
1239
+
1240
+ flw_ref = "FLW-MOCK-d6b76a67a639dc124917b8957baa5278"
1241
+
1242
+ repsonse = auth.capture_preauth(flw_ref, payload)
1243
+ print response
1244
+
1245
+
1246
+ #Void
1247
+ response = auth.void_preauth(flw_ref)
1248
+ print response
1249
+
1250
+
1251
+ #Refund
1252
+ payload = {
1253
+ "amount" => "30"
1254
+ }
1255
+
1256
+ flw_ref = "FLW-MOCK-d6b76a67a639dc124917b8957baa5278"
1257
+
1258
+ response = auth.refund_preauth(flw_ref, payload)
1259
+ print response
1260
+
1261
+
1262
+ ```
1263
+
1264
+
1265
+ ## Development
1266
+
1267
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
1268
+
1269
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
1270
+
1271
+ ## Contributing
1272
+
1273
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Iphytech/flutterwave_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Iphytech/flutterwave_sdk/blob/master/CODE_OF_CONDUCT.md).
1274
+
1275
+
1276
+ ## License
1277
+
1278
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1279
+
1280
+ ## Code of Conduct
1281
+
1282
+ Everyone interacting in the FlutterwaveSdk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Iphytech/flutterwave_sdk/blob/master/CODE_OF_CONDUCT.md).