Class: MobileMoney

Inherits:
Base
  • Object
show all
Defined in:
lib/flutterwave_sdk/flutterwave_objects/mobile_money.rb

Instance Attribute Summary

Attributes inherited from Base

#flutterwave_object

Instance Method Summary collapse

Methods inherited from Base

#check_passed_parameters, #delete_request, #get_request, #initialize, #post_request, #put_request

Constructor Details

This class inherits a constructor from Base

Instance Method Details

#initiate_charge(data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/flutterwave_sdk/flutterwave_objects/mobile_money.rb', line 5

def initiate_charge(data)
    base_url = flutterwave_object.base_url 
    
    # only update the payload with the transaction reference if it isn't already added to the payload
    if !data.key?("tx_ref")
        data.merge!({"tx_ref" => Util.transaction_reference_generator})
    end
    # check the currency to determine the type and the required parameters 
    if data["currency"] == "KES"
        required_parameters =  [ "amount", "email", "phone_number", "tx_ref", "currency"]
        type = "mpesa"
    elsif data["currency"]  == "UGX"
        required_parameters =  ["amount", "email", "phone_number", "tx_ref", "currency"]
        type = "mobile_money_uganda"
    elsif data["currency"]  == "GHS"
        required_parameters =  ["amount", "email", "phone_number", "tx_ref", "currency"]
        type = "mobile_money_ghana"
    elsif data["currency"] == "ZMW"
        required_parameters =  ["amount", "email", "phone_number","tx_ref", "currency"]
        type = "mobile_money_zambia"
    elsif data["currency"] == "RWF" 
        required_parameters =  ["amount", "email", "phone_number","tx_ref", "currency"]
        type = "mobile_money_rwanda"
    elsif data["currency"] == "XAF"  || data["currency"] == "XOF"
        required_parameters = ["amount", "email", "phone_number", "tx_ref", "currency"]
        type = "mobile_money_franco"
    else
        return "pass a valid currency"
    end

    check_passed_parameters(required_parameters, data)
    type = type
    payload = data.to_json

    response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload) 
    return response
end

#verify_charge(id) ⇒ Object

mthod to verify transaction



44
45
46
47
48
49
# File 'lib/flutterwave_sdk/flutterwave_objects/mobile_money.rb', line 44

def verify_charge(id)
        base_url = flutterwave_object.base_url

        response = get_request("#{base_url}/transactions/#{id}/verify")
        return response
end