rave_ruby 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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +1743 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rave_ruby/error.rb +48 -0
- data/lib/rave_ruby/rave_modules/base_endpoints.rb +21 -0
- data/lib/rave_ruby/rave_modules/util.rb +46 -0
- data/lib/rave_ruby/rave_objects/account.rb +68 -0
- data/lib/rave_ruby/rave_objects/base/base.rb +106 -0
- data/lib/rave_ruby/rave_objects/base/charge_base.rb +154 -0
- data/lib/rave_ruby/rave_objects/base/mobile_money_base.rb +44 -0
- data/lib/rave_ruby/rave_objects/base/mpesa_base.rb +41 -0
- data/lib/rave_ruby/rave_objects/base/payment_plan_base.rb +86 -0
- data/lib/rave_ruby/rave_objects/base/preauth_base.rb +84 -0
- data/lib/rave_ruby/rave_objects/base/sub_account_base.rb +34 -0
- data/lib/rave_ruby/rave_objects/base/subscription_base.rb +78 -0
- data/lib/rave_ruby/rave_objects/base/transfer_base.rb +80 -0
- data/lib/rave_ruby/rave_objects/base/ussd_base.rb +60 -0
- data/lib/rave_ruby/rave_objects/card.rb +91 -0
- data/lib/rave_ruby/rave_objects/list_banks.rb +18 -0
- data/lib/rave_ruby/rave_objects/mobile_money.rb +58 -0
- data/lib/rave_ruby/rave_objects/mpesa.rb +59 -0
- data/lib/rave_ruby/rave_objects/payment_plan.rb +61 -0
- data/lib/rave_ruby/rave_objects/preauth.rb +111 -0
- data/lib/rave_ruby/rave_objects/sub_account.rb +55 -0
- data/lib/rave_ruby/rave_objects/subscription.rb +51 -0
- data/lib/rave_ruby/rave_objects/transactions.rb +24 -0
- data/lib/rave_ruby/rave_objects/transfer.rb +79 -0
- data/lib/rave_ruby/rave_objects/uganda_mobile_money.rb +58 -0
- data/lib/rave_ruby/rave_objects/ussd.rb +59 -0
- data/lib/rave_ruby/version.rb +3 -0
- data/lib/rave_ruby.rb +74 -0
- data/rave_ruby.gemspec +46 -0
- metadata +144 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative "base.rb"
|
2
|
+
|
3
|
+
class PreauthBase < Base
|
4
|
+
|
5
|
+
# method to handle preauth charge response
|
6
|
+
def handle_charge_response(response)
|
7
|
+
charge_response = response
|
8
|
+
flwRef = charge_response["data"]["flwRef"]
|
9
|
+
txRef = charge_response["data"]["txRef"]
|
10
|
+
status = charge_response["data"]["status"]
|
11
|
+
amount = charge_response["data"]["amount"]
|
12
|
+
message = charge_response["message"]
|
13
|
+
charged_amount = charge_response["data"]["charged_amount"]
|
14
|
+
currency = charge_response["data"]["currency"]
|
15
|
+
payment_type = charge_response["data"]["paymentType"]
|
16
|
+
charge_response_code = charge_response["data"]["chargeResponseCode"]
|
17
|
+
charge_response_message = charge_response["data"]["chargeResponseMessage"]
|
18
|
+
validation_instruction = charge_response["data"]["validateInstruction"]
|
19
|
+
|
20
|
+
|
21
|
+
if charge_response_code == "02"
|
22
|
+
res = {"error": false, "status": status, "message": message, "validation_required": true, "txRef": txRef, "flwRef": flwRef, "validateInstruction": validation_instruction, "amount": amount, "currency": currency, "paymentType": payment_type}
|
23
|
+
return JSON.parse(res.to_json)
|
24
|
+
else
|
25
|
+
res = {"error": false, "status": status, "message": message, "validation_required": false, "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "paymentType": payment_type}
|
26
|
+
return JSON.parse(res.to_json)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# method to handle capture response
|
32
|
+
def handle_capture_response(response)
|
33
|
+
capture_response = response
|
34
|
+
flwRef = capture_response["data"]["flwRef"]
|
35
|
+
txRef = capture_response["data"]["txRef"]
|
36
|
+
status = capture_response["data"]["status"]
|
37
|
+
message = capture_response["message"]
|
38
|
+
payment_type = capture_response["data"]["paymentType"]
|
39
|
+
amount = capture_response["data"]["amount"]
|
40
|
+
charge_response_code = capture_response["data"]["chargeResponseCode"]
|
41
|
+
charge_response_message = capture_response["data"]["chargeResponseMessage"]
|
42
|
+
currency = capture_response["data"]["currency"]
|
43
|
+
|
44
|
+
if charge_response_code == "02"
|
45
|
+
res = {"error": false, "status": status, "validation_required": true, "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "chargeResponseCode": charge_response_code, "chargeResponseMessage": charge_response_message, "paymentType": payment_type}
|
46
|
+
return JSON.parse(res.to_json)
|
47
|
+
else
|
48
|
+
res = {"error": false, "status": status, "message": message, "validation_required": false, "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "chargeResponseCode": charge_response_code, "chargeResponseMessage": charge_response_message, "paymentType": payment_type}
|
49
|
+
return JSON.parse(res.to_json)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# method to handle refund or void response
|
55
|
+
def handle_refund_void_response(response)
|
56
|
+
refund_void_response = response
|
57
|
+
status = refund_void_response["data"]["status"]
|
58
|
+
charge_response_code = refund_void_response["data"]["chargeResponseCode"]
|
59
|
+
|
60
|
+
if charge_response_code == "02"
|
61
|
+
res = {"error": false, "status": status, "data": refund_void_response["data"]}
|
62
|
+
return JSON.parse(res.to_json)
|
63
|
+
else
|
64
|
+
res = {"error": false, "status": status, "data": refund_void_response["data"]}
|
65
|
+
return JSON.parse(res.to_json)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# method to handle verify preauth response
|
71
|
+
def handle_verify_response(response)
|
72
|
+
verify_response = response
|
73
|
+
status = verify_response["data"]["status"]
|
74
|
+
charge_code = verify_response["data"]["chargecode"]
|
75
|
+
|
76
|
+
if charge_code == "00" && status == "successful"
|
77
|
+
res = {"error": false, "transaction_complete": true, "data": verify_response["data"]}
|
78
|
+
return JSON.parse(res.to_json)
|
79
|
+
else
|
80
|
+
res = {"error": false, "transaction_complete": true, "data": verify_response["data"]}
|
81
|
+
return JSON.parse(res.to_json)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "base.rb"
|
2
|
+
|
3
|
+
class SubAccountBase < Base
|
4
|
+
|
5
|
+
# method to handle subaccount creation response
|
6
|
+
def handle_create_response(response)
|
7
|
+
|
8
|
+
initiate_response = response
|
9
|
+
status = initiate_response["status"]
|
10
|
+
id = initiate_response["data"]["id"]
|
11
|
+
|
12
|
+
if status == "success"
|
13
|
+
response = {"error": false, "id": id, "data": initiate_response["data"]}
|
14
|
+
return JSON.parse(response.to_json)
|
15
|
+
else
|
16
|
+
response = {"error": true, "data": initiate_response["data"]}
|
17
|
+
raise InitiateTransferError, JSON.parse(response.to_json)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# method to list subaccounts response
|
22
|
+
def handle_subaccount_response(response)
|
23
|
+
|
24
|
+
subaccount_response = response
|
25
|
+
|
26
|
+
if subaccount_response.code == 200
|
27
|
+
response = {"error" => false, "data" => JSON.parse(subaccount_response.body)}
|
28
|
+
return response
|
29
|
+
else
|
30
|
+
response = {"error" => true, "data" => JSON.parse(subaccount_response.body)}
|
31
|
+
raise InitiateTransferError, response
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative "base.rb"
|
2
|
+
|
3
|
+
class SubscriptionBase < Base
|
4
|
+
|
5
|
+
# method to handle list subscription
|
6
|
+
|
7
|
+
def handle_list_all_subscription(response)
|
8
|
+
|
9
|
+
list_all_subscription = response
|
10
|
+
status = list_all_subscription["status"]
|
11
|
+
message = list_all_subscription["message"]
|
12
|
+
data = list_all_subscription["data"]
|
13
|
+
plansubscriptions =list_all_subscription["data"]["plansubscriptions"]
|
14
|
+
|
15
|
+
if status == "success"
|
16
|
+
response = {"error": false, "status": status,"message": message, "data": data, "plansubscriptions": plansubscriptions}
|
17
|
+
return JSON.parse(response.to_json)
|
18
|
+
else
|
19
|
+
response = {"error": true, "data": create_response["data"]}
|
20
|
+
raise ListSubscriptionError, JSON.parse(response.to_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
#method to handle fetch subscription
|
26
|
+
|
27
|
+
def handle_fetch_subscription_response(response)
|
28
|
+
fetch_subscription_response = response
|
29
|
+
status = fetch_subscription_response["status"]
|
30
|
+
message = fetch_subscription_response["message"]
|
31
|
+
data = fetch_subscription_response["data"]
|
32
|
+
|
33
|
+
if status == "success"
|
34
|
+
response = {"error": false, "status": status,"message": message, "data": data}
|
35
|
+
return JSON.parse(response.to_json)
|
36
|
+
else
|
37
|
+
response = {"error": true, "data": create_response["data"]}
|
38
|
+
raise FetchSubscriptionError, JSON.parse(response.to_json)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
#method to handle cancel subscription
|
44
|
+
|
45
|
+
def handle_cancel_subscription_response(response)
|
46
|
+
cancel_subscription_response = response
|
47
|
+
status = cancel_subscription_response["status"]
|
48
|
+
message = cancel_subscription_response["message"]
|
49
|
+
data = cancel_subscription_response["data"]
|
50
|
+
|
51
|
+
if status == "success"
|
52
|
+
response = {"error": false, "status": status,"message": message, "data": data}
|
53
|
+
return JSON.parse(response.to_json)
|
54
|
+
else
|
55
|
+
response = {"error": true, "data": create_response["data"]}
|
56
|
+
raise CancelSubscriptionError, JSON.parse(response.to_json)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#method to handle activate subscription
|
61
|
+
|
62
|
+
def handle_activate_subscription_response(response)
|
63
|
+
handle_activate_subscription_response = response
|
64
|
+
status = handle_activate_subscription_response["status"]
|
65
|
+
message = handle_activate_subscription_response["message"]
|
66
|
+
data = handle_activate_subscription_response["data"]
|
67
|
+
|
68
|
+
if status == "success"
|
69
|
+
response = {"error": false, "status": status,"message": message, "data": data}
|
70
|
+
return JSON.parse(response.to_json)
|
71
|
+
else
|
72
|
+
response = {"error": true, "data": create_response["data"]}
|
73
|
+
raise ActivateSubscriptionError, JSON.parse(response.to_json)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative "base.rb"
|
2
|
+
|
3
|
+
class TransferBase < Base
|
4
|
+
|
5
|
+
# method to handle single transfer response
|
6
|
+
def handle_initiate_response(response)
|
7
|
+
|
8
|
+
initiate_response = response
|
9
|
+
status = initiate_response["status"]
|
10
|
+
id = initiate_response["data"]["id"]
|
11
|
+
|
12
|
+
if status == "success"
|
13
|
+
response = {"error": false, "id": id, "data": initiate_response["data"]}
|
14
|
+
return JSON.parse(response.to_json)
|
15
|
+
else
|
16
|
+
response = {"error": true, "data": initiate_response["data"]}
|
17
|
+
raise InitiateTransferError, JSON.parse(response.to_json)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# method to handle bulk transfer response
|
22
|
+
def handle_bulk_response(response)
|
23
|
+
|
24
|
+
bulk_response = response
|
25
|
+
status = bulk_response["status"]
|
26
|
+
id = bulk_response["data"]["id"]
|
27
|
+
|
28
|
+
if status == "success"
|
29
|
+
response = {"error": false, "status": status, "message": bulk_response["message"], "id": id, "data": bulk_response["data"]}
|
30
|
+
return JSON.parse(response.to_json)
|
31
|
+
else
|
32
|
+
response = {"error": true, "data": initiate_response["data"]}
|
33
|
+
raise InitiateTransferError, JSON.parse(response.to_json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# method to handle get fee response
|
38
|
+
def handle_transfer_status(response)
|
39
|
+
|
40
|
+
transfer_status = response
|
41
|
+
|
42
|
+
if transfer_status.code == 200
|
43
|
+
response = {"error" => false, "data" => JSON.parse(transfer_status.body)}
|
44
|
+
return response
|
45
|
+
else
|
46
|
+
response = {"error" => true, "data" => JSON.parse(transfer_status.body)}
|
47
|
+
raise InitiateTransferError, response
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# method to handle get balance response
|
52
|
+
def handle_balance_status(response)
|
53
|
+
|
54
|
+
balance_status = response
|
55
|
+
status = balance_status["status"]
|
56
|
+
|
57
|
+
if status == "success"
|
58
|
+
response = {"error" => false, "returned_data" => JSON.parse(balance_status.body)}
|
59
|
+
return response
|
60
|
+
else
|
61
|
+
response = {"error" => true, "returned_data" => JSON.parse(balance_status.body)}
|
62
|
+
raise InitiateTransferError, response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# method to handle fetch account response
|
67
|
+
def handle_fetch_status(response)
|
68
|
+
|
69
|
+
fetch_status = response
|
70
|
+
|
71
|
+
if fetch_status.code == 200
|
72
|
+
response = {"error" => false, "returned_data" => JSON.parse(fetch_status.body)}
|
73
|
+
return response
|
74
|
+
else
|
75
|
+
response = {"error" => true, "returned_data" => JSON.parse(fetch_status.body)}
|
76
|
+
raise InitiateTransferError, response
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative "base.rb"
|
2
|
+
|
3
|
+
class UssdBase < Base
|
4
|
+
|
5
|
+
# method to handle ussd charge response
|
6
|
+
def handle_charge_response(response, request)
|
7
|
+
charge_response = response
|
8
|
+
flwRef = charge_response["data"]["flwRef"]
|
9
|
+
txRef = charge_response["data"]["txRef"]
|
10
|
+
status = charge_response["data"]["status"]
|
11
|
+
amount = charge_response["data"]["amount"]
|
12
|
+
charged_amount = charge_response["data"]["charged_amount"]
|
13
|
+
currency = charge_response["data"]["currency"]
|
14
|
+
payment_type = charge_response["data"]["paymentType"]
|
15
|
+
charge_response_code = charge_response["data"]["chargeResponseCode"]
|
16
|
+
charge_response_message = charge_response["data"]["chargeResponseMessage"]
|
17
|
+
validation_instruction = charge_response["data"]["validateInstructions"]
|
18
|
+
|
19
|
+
bank_list = {"gtb" => "058", "zenith" => "057"}
|
20
|
+
gtb_response_text = "To complete this transaction, please dial *737*50*#{charged_amount.ceil}*159#"
|
21
|
+
|
22
|
+
|
23
|
+
if charge_response_code == "02"
|
24
|
+
if request["accountbank"] == bank_list["gtb"]
|
25
|
+
res = {"error": false, "status": status, "validation_required": true, "txRef": txRef, "flwRef": flwRef, "validateInstruction": gtb_response_text, "amount": amount, "currency": currency, "paymentType": payment_type}
|
26
|
+
return JSON.parse(res.to_json)
|
27
|
+
else
|
28
|
+
res = {"error": false, "status": status, "validation_required": true, "txRef": txRef, "flwRef": flwRef, "validateInstruction": validation_instruction, "amount": amount, "currency": currency, "paymentType": payment_type}
|
29
|
+
return JSON.parse(res.to_json)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
res = {"error": false, "status": status, "validation_required": false, "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "paymentType": payment_type}
|
33
|
+
return JSON.parse(res.to_json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# method to handle ussd verify response
|
39
|
+
def handle_verify_response(response)
|
40
|
+
verify_response = response
|
41
|
+
flwref = verify_response["data"]["flwref"]
|
42
|
+
txref = verify_response["data"]["txref"]
|
43
|
+
status = verify_response["data"]["status"]
|
44
|
+
charged_amount = verify_response["data"]["chargedamount"]
|
45
|
+
amount = verify_response["data"]["amount"]
|
46
|
+
vbvmessage = verify_response["data"]["vbvmessage"]
|
47
|
+
vbvcode = verify_response["data"]["vbvcode"]
|
48
|
+
currency = verify_response["data"]["currency"]
|
49
|
+
charge_code = verify_response["data"]["chargecode"]
|
50
|
+
charge_message = verify_response["data"]["chargemessage"]
|
51
|
+
|
52
|
+
if charge_code == "00" && status == "successful"
|
53
|
+
res = {"error": false, "status": status, "transaction_complete": true, "txref": txref, "flwref": flwref, "amount": amount, "chargedamount": charged_amount, "vbvmessage": vbvmessage, "vbvcode": vbvcode, "currency": currency, "chargecode": charge_code, "chargemessage": charge_message}
|
54
|
+
return JSON.parse(res.to_json)
|
55
|
+
else
|
56
|
+
res = {"error": false, "status": status, "transaction_complete": false, "txref": txref, "flwef": flwref, "amount": amount, "chargedamount": charged_amount, "vbvmessage": vbvmessage, "vbvcode": vbvcode, "currency": currency, "charge_code": charge_code, "chargemessage": charge_message}
|
57
|
+
return JSON.parse(res.to_json)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative "base/charge_base.rb"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Card < ChargeBase
|
5
|
+
|
6
|
+
# method to initiate card charge
|
7
|
+
def initiate_charge(data)
|
8
|
+
base_url = rave_object.base_url
|
9
|
+
hashed_secret_key = get_hashed_key
|
10
|
+
public_key = rave_object.public_key
|
11
|
+
|
12
|
+
# only update the payload with the transaction reference if it isn't already added to the payload
|
13
|
+
if !data.key?("txRef")
|
14
|
+
data.merge!({"txRef" => Util.transaction_reference_generator})
|
15
|
+
end
|
16
|
+
|
17
|
+
data.merge!({"PBFPubKey" => public_key})
|
18
|
+
|
19
|
+
required_parameters = ["PBFPubKey", "cardno", "cvv", "expirymonth", "expiryyear", "amount", "txRef", "email"]
|
20
|
+
check_passed_parameters(required_parameters, data)
|
21
|
+
|
22
|
+
encrypt_data = Util.encrypt(hashed_secret_key, data)
|
23
|
+
|
24
|
+
payload = {
|
25
|
+
"PBFPubKey" => public_key,
|
26
|
+
"client" => encrypt_data,
|
27
|
+
"alg" => "3DES-24"
|
28
|
+
}
|
29
|
+
|
30
|
+
payload = payload.to_json
|
31
|
+
|
32
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}", payload)
|
33
|
+
|
34
|
+
return handle_charge_response(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
# method to initiate card charge
|
38
|
+
def tokenized_charge(data)
|
39
|
+
base_url = rave_object.base_url
|
40
|
+
hashed_secret_key = get_hashed_key
|
41
|
+
public_key = rave_object.public_key
|
42
|
+
|
43
|
+
# only update the payload with the transaction reference if it isn't already added to the payload
|
44
|
+
if !data.key?("txRef")
|
45
|
+
data.merge!({"txRef" => Util.transaction_reference_generator})
|
46
|
+
end
|
47
|
+
|
48
|
+
data.merge!({"SECKEY" => rave_object.secret_key.dup})
|
49
|
+
|
50
|
+
required_parameters = ["SECKEY", "amount", "currency", "country", "token", "txRef", "email"]
|
51
|
+
check_passed_parameters(required_parameters, data)
|
52
|
+
|
53
|
+
payload = data.to_json
|
54
|
+
|
55
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::TOKENISED_CHARGE_ENDPOINT}", payload)
|
56
|
+
|
57
|
+
return handle_charge_response(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_charge(flwRef, otp)
|
61
|
+
base_url = rave_object.base_url
|
62
|
+
public_key = rave_object.public_key
|
63
|
+
|
64
|
+
|
65
|
+
payload = {
|
66
|
+
"PBFPubKey" => public_key,
|
67
|
+
"transactionreference" => flwRef,
|
68
|
+
"transaction_reference" => flwRef,
|
69
|
+
"otp" => otp,
|
70
|
+
}
|
71
|
+
|
72
|
+
payload = payload.to_json
|
73
|
+
|
74
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::CARD_VALIDATE_ENDPOINT}", payload)
|
75
|
+
return handle_validate_response(response)
|
76
|
+
end
|
77
|
+
|
78
|
+
def verify_charge(txref)
|
79
|
+
base_url = rave_object.base_url
|
80
|
+
|
81
|
+
payload = {
|
82
|
+
"txref" => txref,
|
83
|
+
"SECKEY" => rave_object.secret_key.dup,
|
84
|
+
}
|
85
|
+
|
86
|
+
payload = payload.to_json
|
87
|
+
|
88
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::VERIFY_ENDPOINT}", payload)
|
89
|
+
return handle_verify_response(response)
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "base/base.rb"
|
2
|
+
|
3
|
+
class ListBanks < Base
|
4
|
+
|
5
|
+
attr_reader :rave_object
|
6
|
+
|
7
|
+
# method to initialize the object
|
8
|
+
def initialize(rave_object)
|
9
|
+
@rave_object = rave_object
|
10
|
+
end
|
11
|
+
|
12
|
+
# method to fetch the list of banks using the list bank endpoint
|
13
|
+
def fetch_banks
|
14
|
+
base_url = rave_object.base_url
|
15
|
+
response = get_request("#{base_url}#{BASE_ENDPOINTS::BANKS_ENDPOINT}", {:json => 1})
|
16
|
+
return handle_list_bank(response)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative "base/mobile_money_base.rb"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class MobileMoney < MobileMoneyBase
|
5
|
+
# method to initiate 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" => "mobilemoneygh", "country" => "GH", "is_mobile_money_gh"=> 1, "currency" => "GHS"})
|
24
|
+
|
25
|
+
required_parameters = ["amount", "email", "phonenumber", "network"]
|
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 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
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative "base/mpesa_base.rb"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Mpesa < MpesaBase
|
5
|
+
|
6
|
+
# method to initiate mpesa transaction
|
7
|
+
def initiate_charge(data)
|
8
|
+
|
9
|
+
base_url = rave_object.base_url
|
10
|
+
hashed_secret_key = get_hashed_key
|
11
|
+
public_key = rave_object.public_key
|
12
|
+
|
13
|
+
|
14
|
+
# only update the payload with the transaction reference if it isn't already added to the payload
|
15
|
+
if !data.key?("txRef")
|
16
|
+
data.merge!({"txRef" => Util.transaction_reference_generator})
|
17
|
+
end
|
18
|
+
|
19
|
+
# only update the payload with the order reference if it isn't already added to the payload
|
20
|
+
if !data.key?("orderRef")
|
21
|
+
data.merge!({"orderRef" => Util.transaction_reference_generator})
|
22
|
+
end
|
23
|
+
|
24
|
+
data.merge!({"PBFPubKey" => public_key, "payment_type" => "mpesa", "country" => "KE", "is_mpesa" => "1", "is_mpesa_lipa" => true, "currency" => "KES"})
|
25
|
+
|
26
|
+
required_parameters = ["amount", "email", "phonenumber"]
|
27
|
+
check_passed_parameters(required_parameters, data)
|
28
|
+
|
29
|
+
encrypt_data = Util.encrypt(hashed_secret_key, data)
|
30
|
+
|
31
|
+
payload = {
|
32
|
+
"PBFPubKey" => public_key,
|
33
|
+
"client" => encrypt_data,
|
34
|
+
"alg" => "3DES-24"
|
35
|
+
}
|
36
|
+
|
37
|
+
payload = payload.to_json
|
38
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}", payload)
|
39
|
+
|
40
|
+
return handle_charge_response(response)
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# method to verify mpesa transaction
|
45
|
+
def verify_charge(txref)
|
46
|
+
base_url = rave_object.base_url
|
47
|
+
|
48
|
+
payload = {
|
49
|
+
"txref" => txref,
|
50
|
+
"SECKEY" => rave_object.secret_key.dup,
|
51
|
+
}
|
52
|
+
|
53
|
+
payload = payload.to_json
|
54
|
+
|
55
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::VERIFY_ENDPOINT}", payload)
|
56
|
+
return handle_verify_response(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative "base/payment_plan_base.rb"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class PaymentPlan < PaymentPlanBase
|
5
|
+
|
6
|
+
# method to create a payment plan
|
7
|
+
|
8
|
+
def create_payment_plan(data)
|
9
|
+
base_url = rave_object.base_url
|
10
|
+
secret_key = rave_object.secret_key.dup
|
11
|
+
|
12
|
+
data.merge!({"seckey" => secret_key.dup})
|
13
|
+
|
14
|
+
required_parameters = ["amount", "name", "interval"]
|
15
|
+
check_passed_parameters(required_parameters, data)
|
16
|
+
|
17
|
+
payload = data.to_json
|
18
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::PAYMENT_PLANS_ENDPOINT}/create", payload)
|
19
|
+
|
20
|
+
return handle_create_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def list_payment_plans
|
24
|
+
base_url = rave_object.base_url
|
25
|
+
response = get_request("#{base_url}#{BASE_ENDPOINTS::PAYMENT_PLANS_ENDPOINT}/query",{"seckey" => rave_object.secret_key.dup})
|
26
|
+
return handle_list_response(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch_payment_plan(id,q=nil )
|
30
|
+
base_url = rave_object.base_url
|
31
|
+
secret_key = rave_object.secret_key.dup
|
32
|
+
|
33
|
+
response = get_request("#{base_url}#{BASE_ENDPOINTS::PAYMENT_PLANS_ENDPOINT}/query",{"seckey" => rave_object.secret_key.dup, "id" => id, "q": q})
|
34
|
+
return handle_fetch_response(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def cancel_payment_plan(id)
|
38
|
+
base_url = rave_object.base_url
|
39
|
+
secret_key = rave_object.secret_key.dup
|
40
|
+
|
41
|
+
payload = {
|
42
|
+
"seckey" => secret_key,
|
43
|
+
}
|
44
|
+
|
45
|
+
payload = payload.to_json
|
46
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::PAYMENT_PLANS_ENDPOINT}/#{id}/cancel",payload)
|
47
|
+
return handle_cancel_response(response)
|
48
|
+
end
|
49
|
+
|
50
|
+
def edit_payment_plan(id, data)
|
51
|
+
|
52
|
+
base_url = rave_object.base_url
|
53
|
+
secret_key = rave_object.secret_key.dup
|
54
|
+
|
55
|
+
data.merge!({"seckey" => secret_key.dup})
|
56
|
+
|
57
|
+
payload = data.to_json
|
58
|
+
response = post_request("#{base_url}#{BASE_ENDPOINTS::PAYMENT_PLANS_ENDPOINT}/#{id}/edit",payload)
|
59
|
+
return handle_edit_response(response)
|
60
|
+
end
|
61
|
+
end
|