Module: Dolla::Gateway

Includes:
EncryptionTools, EndPoints, Options, Terms
Included in:
PaymentStub
Defined in:
lib/dolla/gateway.rb

Constant Summary collapse

ACTIONS =
{
  default: {
    cancel_purchase: :reverso_tdc_interred,
    process_purchase: :procesa_compra_o_l,
  },

  amex: {
    process_purchase: :ins_pago_amex_request
  }
}.freeze

Constants included from Terms

Terms::BANK_FINANCED, Terms::NOT_FINANCED

Constants included from EndPoints

EndPoints::PRODUCTION_URL, EndPoints::TESTING_URL, EndPoints::WSDL_ADDRESS, EndPoints::XML_NAMESPACE

Constants included from Options

Options::OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EncryptionTools

#build_digest, #decimal_format, #padding, #rijndael_encrypt

Methods included from Terms

#payment_plan

Methods included from EndPoints

#get_wsdl_address, #get_xml_namespace

Methods included from Options

#get_option

Instance Attribute Details

#addressObject

Returns the value of attribute address.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def address
  @address
end

#amountObject

Returns the value of attribute amount.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def amount
  @amount
end

#bank_account_termsObject

Returns the value of attribute bank_account_terms.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def 
  @bank_account_terms
end

#card_expirationObject

Returns the value of attribute card_expiration.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def card_expiration
  @card_expiration
end

#card_numberObject

Returns the value of attribute card_number.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def card_number
  @card_number
end

#card_type_bank_codeObject

Returns the value of attribute card_type_bank_code.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def card_type_bank_code
  @card_type_bank_code
end

#cardholderObject

Returns the value of attribute cardholder.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def cardholder
  @cardholder
end

#codeObject

Returns the value of attribute code.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def code
  @code
end

#cvvObject

Returns the value of attribute cvv.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def cvv
  @cvv
end

#emailObject

Returns the value of attribute email.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def email
  @email
end

#last_nameObject

Returns the value of attribute last_name.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def last_name
  @last_name
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def name
  @name
end

#payment_idObject

Returns the value of attribute payment_id.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def payment_id
  @payment_id
end

#phone_numberObject

Returns the value of attribute phone_number.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def phone_number
  @phone_number
end

#server_addressObject

Returns the value of attribute server_address.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def server_address
  @server_address
end

#user_agentObject

Returns the value of attribute user_agent.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def user_agent
  @user_agent
end

#zip_codeObject

Returns the value of attribute zip_code.



21
22
23
# File 'lib/dolla/gateway.rb', line 21

def zip_code
  @zip_code
end

Instance Method Details

#amex?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/dolla/gateway.rb', line 57

def amex?
  CardNumberPrefix.card_number_is_amex? card_number
end

#amex_avs_validationObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/dolla/gateway.rb', line 106

def amex_avs_validation
  opt = ActiveSupport::OrderedHash.new

  opt[ get_option(:name) ] = name
  opt[ get_option(:surnames) ] = last_name
  opt[ get_option(:zip_code) ] = zip_code
  opt[ get_option(:address) ]  = address
  opt[ get_option(:shipping) ] = nil

  opt
end

#amex_typed_cardObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/dolla/gateway.rb', line 118

def amex_typed_card
  opt = ActiveSupport::OrderedHash.new

  opt['operationEnvironment'] = 0 # more static values that we don't know what they are
  opt['cardHolderPresent'] = 'S'
  opt['cardPresent'] = false

  opt[ get_option(:online_purchase) ] = ActiveSupport::OrderedHash.new

  opt[ get_option(:online_purchase) ]['browser'] = user_agent[0..49]
  opt[ get_option(:online_purchase) ]['shipping'] = '05' # plz don't ask me what this means, multipagos just said to set it to this
  opt[ get_option(:online_purchase) ]['productId'] = '0' * 6 # just a placeholder until we get the asset system right
  opt[ get_option(:online_purchase) ][ get_option(:client_ip) ] = server_address
  opt
end

#build_amex_payment_bodyObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/dolla/gateway.rb', line 95

def build_amex_payment_body
  body = default_body_fields

  body.set_option :typed_card, amex_typed_card
  body.set_option :avs_validation, amex_avs_validation
  body.set_option :slid_card, nil
  body.set_option :card_chip, nil

  body.set_option :order!, body.keys
end

#build_default_payment_bodyObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dolla/gateway.rb', line 77

def build_default_payment_body
  body = default_body_fields

  body.set_option :card_type, card_type_bank_code
  body.set_option :transaction_type, Dolla.configuration.transaction_type
  body.set_option :track, ''
  body.set_option :admin_email, Dolla.configuration.admin_email
  body.set_option :transaction, Dolla.configuration.payment
  body.set_option :afiliation, ''
  body.set_option :platform, Dolla.configuration.platform

  %i/card_sequence interred_sequence signature_flag promissory_code promissory_transaction/.each do |opt|
    body.set_option opt, ''
  end

  body.set_option(:order!, body.keys) # Unfortunately order matters...
end

#build_payment_bodyObject



73
74
75
# File 'lib/dolla/gateway.rb', line 73

def build_payment_body
  amex? ? build_amex_payment_body : build_default_payment_body
end

#decimal_amountObject



69
70
71
# File 'lib/dolla/gateway.rb', line 69

def decimal_amount
  decimal_format( amount )
end

#default_body_fieldsObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/dolla/gateway.rb', line 134

def default_body_fields
  encrypted = encrypted_customer_info

  if amex?
    cardholder = :full_name
    currency = :amex_currency
    terms =  > 1 ?  : ''
  end

  cardholder ||= :cardholder
  currency   ||= :currency

  body = RequestBuilder.new

  body.set_option :payment_id, payment_id
  body.set_option :payment_code, code
  body.set_option :business_unit, Dolla.configuration.business_unit
  body.set_option :service_type, Dolla.configuration.payment_gateway_code
  body.set_option currency, Dolla.configuration.currency
  body.set_option :total, decimal_amount
  body.set_option cardholder, full_name
  body.set_option :card_number, encrypted[:cc]
  body.set_option :card_expiration, encrypted[:cc_exp]
  body.set_option :cvv, encrypted[:cc_cvv]
  body.set_option :digest, encrypted[:hmac]
  body.set_option :client_email, email
  body.set_option :client_phone, phone_number
  body.set_option :client_id, Dolla.configuration.client_id
  body.set_option :payment_plan, payment_plan
  body.set_option :terms, (amex? ? terms : )
end

#encrypted_customer_infoObject



166
167
168
169
170
171
172
173
# File 'lib/dolla/gateway.rb', line 166

def encrypted_customer_info
  {
    hmac: build_digest( payment_id, code, decimal_amount, cvv ),
    cc: rijndael_encrypt( card_number ),
    cc_exp: rijndael_encrypt( card_expiration.strftime( '%y%m' ) ),
    cc_cvv: rijndael_encrypt( cvv.to_s ),
  }
end

#full_nameObject



65
66
67
# File 'lib/dolla/gateway.rb', line 65

def full_name
  [name, last_name].join(' ')
end

#pay!Object



25
26
27
28
29
30
# File 'lib/dolla/gateway.rb', line 25

def pay!
  request soap_action(:process_purchase), xmlns: xml_namespace do
    soap.element_form_default = :qualified
    soap.body = build_payment_body.to_hash
  end
end

#payments_gatewayObject



37
38
39
40
41
42
# File 'lib/dolla/gateway.rb', line 37

def payments_gateway
  @client ||= ::Savon::Client.new do
    wsdl.endpoint   = wsdl_address
    wsdl.namespace  = xml_namespace
  end
end

#reference(valid_timeframe = 1.week) ⇒ Object



32
33
34
35
# File 'lib/dolla/gateway.rb', line 32

def reference valid_timeframe = 1.week
  due_date = valid_timeframe.from_now
  ReferenceNumber.new( due_date: due_date, amount: amount, payment_id: payment_id )
end

#soap_action(key) ⇒ Object



52
53
54
55
# File 'lib/dolla/gateway.rb', line 52

def soap_action key
  actions = amex? ? ACTIONS[:amex] : ACTIONS[:default]
  actions[key]
end

#wsdl_addressObject



44
45
46
# File 'lib/dolla/gateway.rb', line 44

def wsdl_address
  amex? ? get_wsdl_address(:amex) : get_wsdl_address
end

#xml_namespaceObject



48
49
50
# File 'lib/dolla/gateway.rb', line 48

def xml_namespace
  amex? ? get_xml_namespace(:amex) : get_xml_namespace
end