Class: ActiveMerchant::Billing::OrbitalGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/orbital/ext/active_merchant/active_merchant.rb

Defined Under Namespace

Classes: AVSResult

Constant Summary collapse

API_VERSION =
'7.5'

Instance Method Summary collapse

Instance Method Details

#add_additional_network_tokenization(xml, payment_method) ⇒ Object



216
217
218
219
220
221
222
223
224
225
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 216

def add_additional_network_tokenization(xml, payment_method)
  return unless network_tokenization?(payment_method)
  card_brand = card_brand(payment_method).to_sym

  # The elements must follow a specific sequence
  xml.tag!('AAV', payment_method.payment_cryptogram) if card_brand == :master
  xml.tag!('DPANInd', 'Y')
  xml.tag!('AEVV', payment_method.payment_cryptogram) if card_brand == :american_express
  xml.tag!('DigitalTokenCryptogram', payment_method.payment_cryptogram)
end

#add_creditcard(xml, creditcard, options = {}) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 182

def add_creditcard(xml, creditcard, options = {})
  currency = options[:currency]
  cvv_indicator_visa_discover = options[:cvv_indicator_visa_discover]
  cvv_indicator_override_visa_discover = options[:cvv_indicator_override_visa_discover]

  unless creditcard.nil?
    xml.tag! :AccountNum, creditcard.number
    xml.tag! :Exp, expiry_date(creditcard)
  end

  xml.tag! :CurrencyCode, currency_code(currency)
  xml.tag! :CurrencyExponent, currency_exponents(currency)

  unless creditcard.nil?
    if %w( visa discover ).include?(creditcard.brand)
      if cvv_indicator_visa_discover
        xml.tag! :CardSecValInd, (creditcard.verification_value? ? '1' : cvv_indicator_override_visa_discover || '9')
      else
        xml.tag! :CardSecValInd, '1' if creditcard.verification_value?
      end
    end
    xml.tag! :CardSecVal,  creditcard.verification_value if creditcard.verification_value?
  end
end

#add_mit_cit_params(xml, options) ⇒ Object



174
175
176
177
178
179
180
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 174

def add_mit_cit_params(xml, options)
  xml.tag! :MITMsgType, options[:mit_cit_type] unless options[:mit_cit_type].nil?
  unless options[:credential_on_file].nil?
    xml.tag! :MITStoredCredentialInd, (options[:credential_on_file] ? 'Y' : 'N')
  end
  xml.tag! :MITSubmittedTransactionID, options[:mit_reference_trx_id] unless options[:mit_reference_trx_id].nil?
end

#add_network_tokenization(xml, payment_method) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 207

def add_network_tokenization(xml, payment_method)
  return unless network_tokenization?(payment_method)
  card_brand = card_brand(payment_method).to_sym

  # The elements must follow a specific sequence
  xml.tag!('AuthenticationECIInd', payment_method.eci) unless payment_method.eci.nil?
  xml.tag!('CAVV', payment_method.payment_cryptogram) if card_brand == :visa
end

#authorize(money, creditcard, options = {}) ⇒ Object

A – Authorization request



118
119
120
121
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 118

def authorize(money, creditcard, options = {})
  order = build_new_order_xml_with_cc(AUTH_ONLY, money, creditcard, options)
  commit(order, :authorize, options[:trace_number])
end

#build_inquiry_request(order_id, retry_num, options) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 149

def build_inquiry_request(order_id, retry_num, options)
  xml = xml_envelope
  xml.tag! :Request do
    xml.tag! :Inquiry do
      add_xml_credentials(xml)
      add_bin_merchant_and_terminal(xml, options)
      xml.tag! :OrderID, order_id
      xml.tag! :InquiryRetryNumber, retry_num
    end
  end
  xml.target!
end

#build_new_order_xml(action, money, parameters = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 66

def build_new_order_xml(action, money, parameters = {})
  requires!(parameters, :order_id)
  xml = xml_envelope
  xml.tag! :Request do
    xml.tag! :NewOrder do
      add_xml_credentials(xml)
      # EC - Ecommerce transaction
      # RC - Recurring Payment transaction
      # MO - Mail Order Telephone Order transaction
      # IV - Interactive Voice Response
      # IN - Interactive Voice Response
      xml.tag! :IndustryType, parameters[:industry_type] || ECOMMERCE_TRANSACTION
      # A  - Auth Only No Capture
      # AC - Auth and Capture
      # F  - Force Auth No Capture and no online authorization
      # FR - Force Auth No Capture and no online authorization
      # FC - Force Auth and Capture no online authorization
      # R  - Refund and Capture no online authorization
      xml.tag! :MessageType, action
      add_bin_merchant_and_terminal(xml, parameters)

      yield xml if block_given?

      xml.tag! :PriorAuthID, parameters[:prior_auth_id] if parameters[:prior_auth_id]
      xml.tag! :OrderID, format_order_id(parameters[:order_id])
      xml.tag! :Amount, amount(money)
      xml.tag! :Comments, parameters[:comments] if parameters[:comments]

      # Add additional card information for tokenized credit card that must be placed after the above three elements
      if action == AUTH_ONLY || action == AUTH_AND_CAPTURE
        add_additional_network_tokenization(xml, parameters[:creditcard]) unless parameters[:creditcard].nil?
      end

      if parameters[:soft_descriptors].is_a?(OrbitalSoftDescriptors)
        add_soft_descriptors(xml, parameters[:soft_descriptors])
      end

      set_recurring_ind(xml, parameters)

      # Append Transaction Reference Number for Refund transactions
      if action == REFUND && !parameters[:authorization].nil?
        tx_ref_num, _ = split_authorization(parameters[:authorization])
        xml.tag! :TxRefNum, tx_ref_num
      end

      add_mit_cit_params(xml, parameters)
    end
  end
  xml.target!
end

#build_new_order_xml_with_cc(operation, money, creditcard, options) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 162

def build_new_order_xml_with_cc(operation, money, creditcard, options)
  build_new_order_xml(operation, money, options.merge(:creditcard=>creditcard)) do |xml|
    add_creditcard(xml, creditcard, options)
    add_address(xml, creditcard, options)
    if @options[:customer_profiles]
      add_customer_data(xml, creditcard, options)
      add_managed_billing(xml, options)
    end
    add_network_tokenization(xml, creditcard)
  end
end

#capture(money, authorization, options = {}) ⇒ Object

MFC - Mark For Capture or Force capture



135
136
137
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 135

def capture(money, authorization, options = {})
  commit(build_mark_for_capture_xml(money, authorization, options), :capture, options[:trace_number])
end

#commit(order, message_type, trace_number = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 36

def commit(order, message_type, trace_number=nil)
  x_r_id = x_request_id

  headers = POST_HEADERS.merge('Content-length' => order.size.to_s,
                               'User-Agent' => user_agent,
                               'Interface-Version' => 'Ruby|KillBill|Open-Source Gateway',
                               'Content-Type' => 'application/PTI74')
  headers['X-Request-Id'] = x_r_id unless x_r_id.blank?
  headers.merge!('Trace-number' => trace_number.to_s,
                 'Merchant-Id' => @options[:merchant_id]) if trace_number
  request = lambda { |url| parse(ssl_post(url, order, headers)) }

  # Failover URL will be attempted in the event of a connection error
  response = begin
    request.call(remote_url)
  rescue ConnectionError
    request.call(remote_url(:secondary))
  end

  Response.new(success?(response, message_type),
               message_from(response),
               response,
               {
                   :authorization => authorization_string(response[:tx_ref_num], response[:order_id]),
                   :test => self.test?,
                   :avs_result => OrbitalGateway::AVSResult.new(response[:avs_resp_code]),
                   :cvv_result => OrbitalGateway::CVVResult.new(response[:cvv2_resp_code]),
               })
end

#credit(money, creditcard, options = {}) ⇒ Object



139
140
141
142
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 139

def credit(money, creditcard, options= {})
  order = build_new_order_xml_with_cc(REFUND, money, creditcard, options)
  commit(order, :credit, options[:trace_number])
end

#inquiry(order_id, retry_num) ⇒ Object



144
145
146
147
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 144

def inquiry(order_id, retry_num)
  query = build_inquiry_request(order_id, retry_num, options)
  commit(query, :inquiry, options[:trace_number])
end

#network_tokenization?(payment_method) ⇒ Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 227

def network_tokenization?(payment_method)
  payment_method.is_a?(NetworkTokenizationCreditCard)
end

#purchase(money, creditcard, options = {}) ⇒ Object

AC – Authorization and Capture or Force Capture



124
125
126
127
128
129
130
131
132
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 124

def purchase(money, creditcard, options = {})
  if options[:force_capture]
    order = build_new_order_xml_with_cc(FORCE_AUTH_AND_CAPTURE, money, creditcard, options)
    commit(order, :purchase, options[:trace_number])
  else
    order = build_new_order_xml_with_cc(AUTH_AND_CAPTURE, money, creditcard, options)
    commit(order, :purchase, options[:trace_number])
  end
end

#store(creditcard, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 10

def store(creditcard, options = {})
  response = add_customer_profile(creditcard, options)

  # Workaround: unmask the PAN if needed
  # TODO We could call on-the-fly retrieve_customer_profile instead in PaymentPlugin#get_payment_source to
  # avoid having to store the PAN, but this requires a specific merchant account setting
  response.params['cc_account_num'] = creditcard.number if response.params['cc_account_num'].include?('XXXX')

  response
end

#success?(response, message_type) ⇒ Boolean

Returns:

  • (Boolean)


231
232
233
234
235
236
237
238
239
240
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 231

def success?(response, message_type)
  if [:refund, :void, :credit].include?(message_type)
    response[:proc_status] == SUCCESS
  elsif response[:customer_profile_action]
    response[:profile_proc_status] == SUCCESS
  else
    response[:proc_status] == SUCCESS &&
        APPROVED.include?(response[:resp_code])
  end
end

#user_agentObject



21
22
23
24
25
26
27
28
29
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 21

def user_agent
  @@ua ||= JSON.dump({
                         :bindings_version => KB_PLUGIN_VERSION,
                         :lang => 'ruby',
                         :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
                         :platform => RUBY_PLATFORM,
                         :publisher => 'killbill'
                     })
end

#x_request_idObject



31
32
33
34
# File 'lib/orbital/ext/active_merchant/active_merchant.rb', line 31

def x_request_id
  # See KillbillMDCInsertingServletFilter
  org::slf4j::MDC::get('req.requestId') rescue nil
end