rave_ruby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59d0de78eb5d5fc35c6ea80ceca8b1537b9ed12e88a70a948fdc39a81892f9d0
4
- data.tar.gz: 4fa81aa9c64f6cedba27045a6722b7badd908c993fbce452920eb43bed17128d
3
+ metadata.gz: e0bcdac759e9365153ee35f5508ef69b1e483da33379a780ab3e3a57a28c2950
4
+ data.tar.gz: 32251e36bb561cfa4dc177dafe2b1db68b6743980ac6c9128736d4116fbe5d88
5
5
  SHA512:
6
- metadata.gz: 23c10ff6b2e46282cfae2b1536a4440ab6a685c6605d6585d1bb1095cb8cd31a692e4cb6e30d6e5314b4fa0346438190aac90f5d70e2ff39d01462f407ec8ec7
7
- data.tar.gz: aabec004b41770acfd5d3b3a472cf6a2a7d133a784e44f12b8f6d6fdb117889cd2060b6d089b9a85764313dfb649fecaba3e789a86db8ced90ce566b6b21183b
6
+ metadata.gz: 5ade21a39b8321638abba7899fad1b6115adb1b813c385ac416bb4904c54712c76ae33c64b35877ed3bd1d350d13e76437794056141ff0ad2583c05fc1b14c10
7
+ data.tar.gz: 4b73d8c3120d25ffd81c3d9890aa364dea6580d99d5d7a75df04e2a7856fe4a80f281a5c1fc8c536f944c575d86457261b3b482a5fb22969d661a9e23d968f49
data/.gitignore CHANGED
@@ -19,5 +19,6 @@ preauth_test.rb
19
19
  sub_account_test.rb
20
20
  subscriptionTest.rb
21
21
  uganda_mobile_money_test.rb
22
+ zambia_mobile_money_test.rb
22
23
  payment_plan_test.rb
23
24
  env.rb
data/README.md CHANGED
@@ -67,6 +67,7 @@ rave = RaveRuby.new("YOUR_RAVE_LIVE_PUBLIC_KEY", "YOUR_RAVE_LIVE_SECRET_KEY", tr
67
67
  - [Subscription.new(rave)](#subscriptionnewrave)
68
68
  - [Transfer.new(rave)](#transfernewrave)
69
69
  - [UgandaMobileMoney.new(rave)](#ugandamobilemoneynewrave)
70
+ - [ZambiaMobileMoney.new(rave)](#zambiamobilemoneynewrave)
70
71
  - [Ussd.new(rave)](#ussdnewrave)
71
72
  - [ListBanks.new(rave)](#listbanksnewrave)
72
73
 
@@ -1298,18 +1299,20 @@ It returns this response in ruby hash. A sample response:
1298
1299
 
1299
1300
  ```ruby
1300
1301
  {
1301
- "error"=>false, "status"=>"success", "message"=>"SUBSCRIPTIONS-FETCHED", "data"=>{"page_info"=>{"total"=>0, "current_page"=>0, "total_pages"=>0}, "plansubscriptions"=>[]}, "plansubscriptions"=>[]
1302
+ "error"=>false, "status"=>"success", "message"=>"SUBSCRIPTIONS-FETCHED", "data"=>{"page_info"=>{"total"=>6, "current_page"=>1, "total_pages"=>1}, "plansubscriptions"=>[{"id"=>1785, "amount"=>100, "customer"=>{"id"=>83207, "customer_email"=>"horozex@ace-mail.net"}, "plan"=>1296, "status"=>"cancelled",
1303
+ "date_created"=>"2019-02-06T21:03:21.000Z"}, {"id"=>1726, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-29T08:58:38.000Z"}, {"id"=>1724, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-28T17:16:46.000Z"}, {"id"=>1720,
1304
+ "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-26T17:15:36.000Z"}, {"id"=>1719, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-26T15:13:07.000Z"}, {"id"=>1533, "amount"=>100, "customer"=>{"id"=>73332, "customer_email"=>"jolaosoyusuf16@gmail.com"}, "plan"=>1296, "status"=>"active", "date_created"=>"2018-12-29T11:47:45.000Z"}]}, "plansubscriptions"=>[{"id"=>1785, "amount"=>100, "customer"=>{"id"=>83207, "customer_email"=>"horozex@ace-mail.net"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-02-06T21:03:21.000Z"}, {"id"=>1726, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-29T08:58:38.000Z"}, {"id"=>1724, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-28T17:16:46.000Z"}, {"id"=>1720, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-26T17:15:36.000Z"}, {"id"=>1719, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"cancelled", "date_created"=>"2019-01-26T15:13:07.000Z"}, {"id"=>1533, "amount"=>100, "customer"=>{"id"=>73332, "customer_email"=>"jolaosoyusuf16@gmail.com"}, "plan"=>1296, "status"=>"active", "date_created"=>"2018-12-29T11:47:45.000Z"}]
1302
1305
  }
1303
1306
  ```
1304
1307
 
1305
- ### `.fetch_subscription("subscription_id", "subscription_email")`
1308
+ ### `.fetch_subscription(transaction_id)`
1306
1309
 
1307
- This function is called to fetch a single subscription taking the subscription id and subscription email as its arguments.
1310
+ This function is called to fetch a single subscription by taking the transaction id from a successful charge or verify response as its arguments.
1308
1311
 
1309
1312
  #### Sample fetch_subscription call:
1310
1313
 
1311
1314
  ```ruby
1312
- response = subscription.fetch_subscription("1", "test@test.com")
1315
+ response = subscription.fetch_subscription("426082")
1313
1316
  ```
1314
1317
  #### which returns:
1315
1318
 
@@ -1317,42 +1320,72 @@ It returns this response in ruby hash. A sample response:
1317
1320
 
1318
1321
  ```ruby
1319
1322
  {
1320
- "error"=>false, "status"=>"success", "message"=>"SUBSCRIPTIONS-FETCHED", "data"=>{"page_info"=>{"total"=>0, "current_page"=>0, "total_pages"=>0}, "plansubscriptions"=>[]}
1323
+ "error"=>false, "status"=>"success", "message"=>"SUBSCRIPTIONS-FETCHED", "data"=>{"page_info"=>{"total"=>1, "current_page"=>1, "total_pages"=>1}, "plansubscriptions"=>[{"id"=>1794, "amount"=>100, "customer"=>{"id"=>51655, "customer_email"=>"user@gmail.com"}, "plan"=>1296, "status"=>"active", "date_created"=>"2019-02-07T16:04:34.000Z"}]}
1321
1324
  }
1322
1325
  ```
1323
1326
 
1324
- ### `.activate_subscription("subscription_id")`
1327
+ ### `.activate_subscription(transaction_id)`
1325
1328
 
1326
- This function is called to activate a subscription taking the subscription id as its argument.
1329
+ This function is called to activate a subscription by taking the transaction id from a successful charge or verify response as its arguments.
1327
1330
 
1328
1331
  #### Sample activate_subscription call:
1329
1332
 
1330
1333
  ```ruby
1331
- response = subscription.activate_subscription(1533)
1334
+ response = subscription.activate_subscription(426082)
1332
1335
  ```
1333
1336
  #### which returns:
1334
1337
 
1335
1338
  It returns this response in ruby hash. A sample response:
1336
1339
 
1337
1340
  ```ruby
1338
-
1341
+ {
1342
+ "error"=>false,
1343
+ "status"=> "success",
1344
+ "message"=> "SUBSCRIPTION-ACTIVATED",
1345
+ "data"=> {
1346
+ "id"=> 1794,
1347
+ "amount"=> 100,
1348
+ "customer"=> {
1349
+ "id"=> 51655,
1350
+ "customer_email"=> "user@gmail.com"
1351
+ },
1352
+ "plan"=> 1296,
1353
+ "status"=> "active",
1354
+ "date_created"=> "2019-02-07T16:04:34.000Z"
1355
+ }
1356
+ }
1339
1357
  ```
1340
1358
 
1341
- ### `.cancel_subscription("subscription_id")`
1359
+ ### `.cancel_subscription(transaction_id)`
1342
1360
 
1343
- This function is called to cancel a subscription taking the subscription id as its argument.
1361
+ This function is called to cancel a subscription by taking the transaction id from a successful charge or verify response as its arguments.
1344
1362
 
1345
1363
  #### Sample cancel_subscription call:
1346
1364
 
1347
1365
  ```ruby
1348
- response = subscription.cancel_subscription(1533)
1366
+ response = subscription.cancel_subscription(426082)
1349
1367
  ```
1350
1368
  #### which returns:
1351
1369
 
1352
1370
  It returns this response in ruby hash. A sample response:
1353
1371
 
1354
1372
  ```ruby
1355
-
1373
+ {
1374
+ "error"=>false,
1375
+ "status" => "success",
1376
+ "message"=> "SUBSCRIPTION-CANCELLED",
1377
+ "data"=> {
1378
+ "id"=> 1794,
1379
+ "amount"=> 100,
1380
+ "customer"=> {
1381
+ "id"=> 51655,
1382
+ "customer_email"=> "user@gmail.com"
1383
+ },
1384
+ "plan"=> 1296,
1385
+ "status"=> "cancelled",
1386
+ "date_created"=> "2019-02-07T16:04:34.000Z"
1387
+ }
1388
+ }
1356
1389
  ```
1357
1390
 
1358
1391
  ### Full Subscription Flow
@@ -1366,7 +1399,7 @@ rave = RaveRuby.new("FLWPUBK-xxxxxxxxxxxxxxxxxxxxx-X", "FLWSECK-xxxxxxxxxxxxxxxx
1366
1399
  subscription = Subscription.new(rave)
1367
1400
  response = subscription.list_all_subscription
1368
1401
  print response
1369
- response = subscription.fetch_subscription("1", "test@test.com")
1402
+ response = subscription.fetch_subscription("1")
1370
1403
  print response
1371
1404
  response = subscription.activate_subscription(1533)
1372
1405
  print response
@@ -1712,6 +1745,109 @@ print response
1712
1745
 
1713
1746
  ```
1714
1747
 
1748
+ ## `ZambiaMobileMoney.new(rave)`
1749
+
1750
+ To perform zambia mobile money transactions, instantiate the zambia mobile money object and pass rave object as its argument.
1751
+
1752
+ Its functions includes:
1753
+
1754
+ - `.initiate_charge`
1755
+ - `.verify_charge`
1756
+
1757
+ ### `.initiate_charge(payload)`
1758
+
1759
+ This function is called to initiate zambia mobile money transaction. The payload should be a ruby hash with uganda mobile money details. Its parameters should include the following:
1760
+
1761
+ - `amount`,
1762
+
1763
+ - `email`,
1764
+
1765
+ - `phonenumber`,
1766
+
1767
+ - `network`,
1768
+
1769
+ You can also add your custom transaction reference `(txRef)`, if not, one would be automatically generated for you in which we used the ruby `securerandom` module for generating this in the `Util` module.
1770
+
1771
+ #### Sample zambia mobile money charge call:
1772
+
1773
+ ```ruby
1774
+ response = charge_zambia_mobile_money.initiate_charge(payload)
1775
+ ```
1776
+ #### which returns:
1777
+
1778
+ It returns this response in ruby hash. A sample response:
1779
+
1780
+ ```ruby
1781
+
1782
+ {
1783
+ "error"=>false, "status"=>"success-pending-validation", "validation_required"=>true, "txRef"=>"MC-bed3093128cd133623ad3cc7cbfc22b2", "flwRef"=>"flwm3s4m0c1549542975743", "amount"=>30, "currency"=>"ZMW", "validateInstruction"=>nil, "authModelUsed"=>"MOBILEMONEY", "paymentType"=>"mobilemoneyzm"
1784
+ }
1785
+
1786
+ ```
1787
+
1788
+ ### `.verify_charge(txRef)`
1789
+
1790
+ You can call the `verify_charge` function to check if your transaction was completed successfully. To do this, you have to pass the transaction reference generated at the point of making your charge call. This is the txRef in the response parameter returned in any of the `initiate_charge` call.
1791
+
1792
+ #### Sample verify_charge call:
1793
+
1794
+ ```ruby
1795
+ response = charge_zambia_mobile_money.verify_charge(response["txRef"])
1796
+ ```
1797
+
1798
+ #### which returns:
1799
+
1800
+ It returns this response in ruby hash with the `txRef`, `flwRef` and `transaction_complete` which indicates the transaction is successfully completed.
1801
+
1802
+ Full sample response returned if a transaction is successfully verified:
1803
+
1804
+ ```ruby
1805
+ {
1806
+ "error"=>false, "transaction_complete"=>false, "data"=>{"txid"=>425673, "txref"=>"MC-bed3093128cd133623ad3cc7cbfc22b2", "flwref"=>"flwm3s4m0c1549542975743", "devicefingerprint"=>"N/A", "cycle"=>"one-time", "amount"=>30, "currency"=>"ZMW", "chargedamount"=>30, "appfee"=>0.42, "merchantfee"=>0, "merchantbearsfee"=>1, "chargecode"=>"02", "chargemessage"=>"Pending Payment Validation", "authmodel"=>"MOBILEMONEY", "ip"=>"::ffff:10.63.225.86", "narration"=>"Simply Recharge", "status"=>"success-pending-validation", "vbvcode"=>"N/A", "vbvmessage"=>"N/A", "authurl"=>"NO-URL", "acctcode"=>nil, "acctmessage"=>nil, "paymenttype"=>"mobilemoneyzm", "paymentid"=>"N/A", "fraudstatus"=>"ok", "chargetype"=>"normal", "createdday"=>4, "createddayname"=>"THURSDAY", "createdweek"=>6, "createdmonth"=>1, "createdmonthname"=>"FEBRUARY", "createdquarter"=>1, "createdyear"=>2019, "createdyearisleap"=>false, "createddayispublicholiday"=>0, "createdhour"=>12, "createdminute"=>36, "createdpmam"=>"pm", "created"=>"2019-02-07T12:36:15.000Z", "customerid"=>83416, "custphone"=>"054709929300", "custnetworkprovider"=>"UNKNOWN PROVIDER",
1807
+ "custname"=>"John Doe", "custemail"=>"user@example.com", "custemailprovider"=>"COMPANY EMAIL", "custcreated"=>"2019-02-07T12:36:14.000Z", "accountid"=>6076, "acctbusinessname"=>"Simply Recharge", "acctcontactperson"=>"Jolaoso Yusuf", "acctcountry"=>"NG", "acctbearsfeeattransactiontime"=>1, "acctparent"=>1, "acctvpcmerchant"=>"N/A", "acctalias"=>nil, "acctisliveapproved"=>0, "orderref"=>"URF_MMGH_1549542975097_8307535", "paymentplan"=>nil, "paymentpage"=>nil, "raveref"=>nil, "meta"=>[]}
1808
+ }
1809
+ ```
1810
+
1811
+ If the `chargecode` returned is `02`, it means the transaction is still pending validation else if it returns `00`, it means the transaction is successfully completed.
1812
+
1813
+ #### Full Zambia Mobile Money Transaction Flow:
1814
+
1815
+ ```ruby
1816
+
1817
+ require 'rave_ruby'
1818
+
1819
+
1820
+ # This is a rave object which is expecting public and secret keys
1821
+ rave = RaveRuby.new("FLWPUBK-xxxxxxxxxxxxxxxxxxxxx-X", "FLWSECK-xxxxxxxxxxxxxxxxxxxx-X")
1822
+
1823
+
1824
+ # This is used to perform zambia mobile money charge
1825
+
1826
+ payload = {
1827
+ "amount" => "30",
1828
+ "phonenumber" => "054709929300",
1829
+ "firstname" => "John",
1830
+ "lastname" => "Doe",
1831
+ "network" => "MTN",
1832
+ "email" => "user@example.com",
1833
+ "IP" => '355426087298442',
1834
+ "redirect_url" => "https://webhook.site/6eb017d1-c605-4faa-b543-949712931895",
1835
+ }
1836
+
1837
+ # To initiate zambia mobile money transaction
1838
+ charge_zambia_mobile_money = ZambiaMobileMoney.new(rave)
1839
+
1840
+ response = charge_zambia_mobile_money.initiate_charge(payload)
1841
+
1842
+ print response
1843
+
1844
+ # To verify the zambia mobile money transaction
1845
+ response = charge_zambia_mobile_money.verify_charge(response["txRef"])
1846
+
1847
+ print response
1848
+
1849
+ ```
1850
+
1715
1851
  ## `Ussd.new(rave)`
1716
1852
 
1717
1853
  `NOTE:` This option is currently unavailable.
@@ -8,6 +8,7 @@ require_relative "rave_ruby/rave_objects/transfer"
8
8
  require_relative "rave_ruby/rave_objects/mpesa"
9
9
  require_relative "rave_ruby/rave_objects/mobile_money"
10
10
  require_relative "rave_ruby/rave_objects/uganda_mobile_money"
11
+ require_relative "rave_ruby/rave_objects/zambia_mobile_money"
11
12
  require_relative "rave_ruby/rave_objects/payment_plan"
12
13
  require_relative "rave_ruby/rave_objects/subscription"
13
14
  require_relative "rave_ruby/rave_objects/ussd"
@@ -13,15 +13,15 @@ class Subscription < SubscriptionBase
13
13
 
14
14
  #method to fetch a subscription
15
15
 
16
- def fetch_subscription(id, email)
16
+ def fetch_subscription(trans_id)
17
17
  base_url = rave_object.base_url
18
18
  secret_key = rave_object.secret_key.dup
19
19
 
20
- response = get_request("#{base_url}#{BASE_ENDPOINTS::SUBSCRIPTIONS_ENDPOINT}/query",{"seckey" => rave_object.secret_key.dup, "id" => id, "email": email})
20
+ response = get_request("#{base_url}#{BASE_ENDPOINTS::SUBSCRIPTIONS_ENDPOINT}/query",{"seckey" => rave_object.secret_key.dup, "transaction_id" => trans_id})
21
21
  return handle_fetch_subscription_response(response)
22
22
  end
23
23
 
24
- def cancel_subscription(id)
24
+ def cancel_subscription(trans_id)
25
25
  base_url = rave_object.base_url
26
26
  secret_key = rave_object.secret_key.dup
27
27
 
@@ -30,11 +30,11 @@ class Subscription < SubscriptionBase
30
30
  }
31
31
 
32
32
  payload = payload.to_json
33
- response = post_request("#{base_url}#{BASE_ENDPOINTS::SUBSCRIPTIONS_ENDPOINT}/#{id}/cancel",payload)
34
- return handle_cancel_response(response)
33
+ response = post_request("#{base_url}#{BASE_ENDPOINTS::SUBSCRIPTIONS_ENDPOINT}/#{trans_id}/cancel?fetch_by_tx=1",payload)
34
+ return handle_cancel_subscription_response(response)
35
35
  end
36
36
 
37
- def activate_subscription(id)
37
+ def activate_subscription(trans_id)
38
38
 
39
39
  base_url = rave_object.base_url
40
40
  secret_key = rave_object.secret_key.dup
@@ -45,7 +45,7 @@ class Subscription < SubscriptionBase
45
45
  "seckey" => secret_key,
46
46
  }
47
47
  payload = payload.to_json
48
- response = post_request("#{base_url}#{BASE_ENDPOINTS::SUBSCRIPTIONS_ENDPOINT}/#{id}/activate",payload)
48
+ response = post_request("#{base_url}#{BASE_ENDPOINTS::SUBSCRIPTIONS_ENDPOINT}/#{trans_id}/activate?fetch_by_tx=1",payload)
49
49
  return handle_activate_subscription_response(response)
50
50
  end
51
51
  end
@@ -0,0 +1,58 @@
1
+ require_relative "base/mobile_money_base.rb"
2
+ require 'json'
3
+
4
+ class ZambiaMobileMoney < MobileMoneyBase
5
+ # method to initiate zambia mobile money transaction
6
+ def initiate_charge(data)
7
+
8
+ base_url = rave_object.base_url
9
+ hashed_secret_key = get_hashed_key
10
+ public_key = rave_object.public_key
11
+
12
+
13
+ # only update the payload with the transaction reference if it isn't already added to the payload
14
+ if !data.key?("txRef")
15
+ data.merge!({"txRef" => Util.transaction_reference_generator})
16
+ end
17
+
18
+ # only update the payload with the order reference if it isn't already added to the payload
19
+ if !data.key?("orderRef")
20
+ data.merge!({"orderRef" => Util.transaction_reference_generator})
21
+ end
22
+
23
+ data.merge!({"PBFPubKey" => public_key, "payment_type" => "mobilemoneyzambia", "country" => "NG", "is_mobile_money_ug" => 1, "currency" => "ZMW"})
24
+
25
+ required_parameters = ["amount", "email", "phonenumber", "network", "IP"]
26
+ check_passed_parameters(required_parameters, data)
27
+
28
+ encrypt_data = Util.encrypt(hashed_secret_key, data)
29
+
30
+ payload = {
31
+ "PBFPubKey" => public_key,
32
+ "client" => encrypt_data,
33
+ "alg" => "3DES-24"
34
+ }
35
+
36
+ payload = payload.to_json
37
+ response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}", payload)
38
+
39
+ return handle_charge_response(response)
40
+
41
+ end
42
+
43
+ # method to verify zambia mobile money transaction
44
+ def verify_charge(txref)
45
+ base_url = rave_object.base_url
46
+
47
+ payload = {
48
+ "txref" => txref,
49
+ "SECKEY" => rave_object.secret_key.dup,
50
+ }
51
+
52
+ payload = payload.to_json
53
+
54
+ response = post_request("#{base_url}#{BASE_ENDPOINTS::VERIFY_ENDPOINT}", payload)
55
+ return handle_verify_response(response)
56
+ end
57
+
58
+ end
@@ -1,3 +1,3 @@
1
1
  module RaveRuby
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rave_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MaestroJolly
@@ -112,6 +112,7 @@ files:
112
112
  - lib/rave_ruby/rave_objects/transfer.rb
113
113
  - lib/rave_ruby/rave_objects/uganda_mobile_money.rb
114
114
  - lib/rave_ruby/rave_objects/ussd.rb
115
+ - lib/rave_ruby/rave_objects/zambia_mobile_money.rb
115
116
  - lib/rave_ruby/version.rb
116
117
  - rave_ruby.gemspec
117
118
  homepage: https://github.com/MaestroJolly/rave-ruby