Class: CardBase

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

Direct Known Subclasses

Card

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

#get_auth_type(suggested_auth) ⇒ Object

method to the passed suggested auth to the corresponding value in the available hash



6
7
8
9
10
11
12
13
14
# File 'lib/flutterwave_sdk/flutterwave_objects/base/card_base.rb', line 6

def get_auth_type(suggested_auth)
  auth_map = {"pin" => :pin, "avs_vbvsecurecode" => :address, "noauth_international" => :address, "avs_noauth" => :address}

  # Raise Error if the right authorization type is not passed
  unless !auth_map.has_key? auth_map[suggested_auth]
    raise RequiredAuthError, "Required suggested authorization type not available."
  end
  return auth_map[suggested_auth]
end

#update_payload(suggested_auth, payload, **keyword_args) ⇒ Object

method to update payload



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/flutterwave_sdk/flutterwave_objects/base/card_base.rb', line 18

def update_payload(suggested_auth, payload, **keyword_args)
  auth_type = get_auth_type(suggested_auth)
  
  # Error is raised if the expected suggested auth is not found in the keyword arguments
  if !keyword_args.key?(auth_type)
    raise SuggestedAuthError, "Please pass the suggested auth."
  end

  # if the authorization type is equal to address symbol, update with the required parameters
  if auth_type == :address
    required_parameters = ["city", "address", "state", "country", "zipcode"]
    check_passed_parameters(required_parameters, keyword_args[auth_type])
    authorization = {}
    authorization.merge!({"mode" => suggested_auth})
    # puts authorization
    authorization.merge!(keyword_args[auth_type])
    payload["authorization"]= authorization
    return payload
  end


  # return this updated payload if the passed authorization type isn't address symbol
  authorization = {}
  #  authorization.merge!({"mode" => suggested_auth, "fields" => keyword_args[auth_type]})
  authorization.merge!({"mode" => suggested_auth})
   puts authorization
   authorization.merge!(keyword_args[auth_type])
   payload["authorization"]= authorization
  return payload

end