Class: Card
- Defined in:
- lib/flutterwave_sdk/flutterwave_objects/card.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initiate_charge(data) ⇒ Object
method to initiate card charge.
- #validate_charge(flw_ref, otp) ⇒ Object
- #verify_charge(id) ⇒ Object
Methods inherited from CardBase
#get_auth_type, #update_payload
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
method to initiate card charge
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 |
# File 'lib/flutterwave_sdk/flutterwave_objects/card.rb', line 7 def initiate_charge(data) base_url = flutterwave_object.base_url encryption_key = flutterwave_object.encryption_key public_key = flutterwave_object.public_key # 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 data.merge!({"public_key" => public_key}) required_parameters = [ "card_number", "cvv", "expiry_month", "expiry_year", "amount", "tx_ref", "currency", "email"] check_passed_parameters(required_parameters, data) encrypt_data = Util.encrypt(encryption_key, data) payload = { "public_key" => public_key, "client" => encrypt_data, "alg" => "3DES-24" } type = "card" payload = payload.to_json response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload) return response end |
#validate_charge(flw_ref, otp) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flutterwave_sdk/flutterwave_objects/card.rb', line 38 def validate_charge(flw_ref, otp) base_url = flutterwave_object.base_url payload = { "otp" => otp, "flw_ref" => flw_ref } payload = payload.to_json response = post_request("#{base_url}/validate-charge", payload) return response end |
#verify_charge(id) ⇒ Object
50 51 52 53 54 |
# File 'lib/flutterwave_sdk/flutterwave_objects/card.rb', line 50 def verify_charge(id) base_url = flutterwave_object.base_url response = get_request("#{base_url}/transactions/#{id}/verify") return response end |