lib/active_merchant/billing/gateways/qvalent.rb in activemerchant-1.94.0 vs lib/active_merchant/billing/gateways/qvalent.rb in activemerchant-1.95.0

- old
+ new

@@ -25,10 +25,11 @@ post = {} add_invoice(post, amount, options) add_order_number(post, options) add_payment_method(post, payment_method) add_verification_value(post, payment_method) + add_stored_credential_data(post, payment_method, options) add_customer_data(post, options) add_soft_descriptors(post, options) commit('capture', post) end @@ -37,10 +38,11 @@ post = {} add_invoice(post, amount, options) add_order_number(post, options) add_payment_method(post, payment_method) add_verification_value(post, payment_method) + add_stored_credential_data(post, payment_method, options) add_customer_data(post, options) add_soft_descriptors(post, options) commit('preauth', post) end @@ -59,10 +61,11 @@ post = {} add_invoice(post, amount, options) add_reference(post, authorization, options) add_customer_data(post, options) add_soft_descriptors(post, options) + post['order.ECI'] = options[:eci] || 'SSL' commit('refund', post) end # Credit requires the merchant account to be enabled for "Adhoc Refunds" @@ -122,17 +125,56 @@ end def add_invoice(post, money, options) post['order.amount'] = amount(money) post['card.currency'] = CURRENCY_CODES[options[:currency] || currency(money)] - post['order.ECI'] = options[:eci] || 'SSL' end def add_payment_method(post, payment_method) post['card.cardHolderName'] = payment_method.name post['card.PAN'] = payment_method.number post['card.expiryYear'] = format(payment_method.year, :two_digits) post['card.expiryMonth'] = format(payment_method.month, :two_digits) + end + + def add_stored_credential_data(post, payment_method, options) + post['order.ECI'] = options[:eci] || eci(options) + if (stored_credential = options[:stored_credential]) && %w(visa master).include?(payment_method.brand) + post['card.posEntryMode'] = stored_credential[:initial_transaction] ? 'MANUAL' : 'STORED_CREDENTIAL' + stored_credential_usage(post, payment_method, options) unless stored_credential[:initiator] && stored_credential[:initiator] == 'cardholder' + post['order.authTraceId'] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id] + end + end + + def stored_credential_usage(post, payment_method, options) + return unless payment_method.brand == 'visa' + stored_credential = options[:stored_credential] + if stored_credential[:initial_transaction] + post['card.storedCredentialUsage'] = 'INITIAL_STORAGE' + elsif stored_credential[:reason_type] == ('recurring' || 'installment') + post['card.storedCredentialUsage'] = 'RECURRING' + elsif stored_credential[:reason_type] == 'unscheduled' + post['card.storedCredentialUsage'] = 'UNSCHEDULED' + end + end + + def eci(options) + if options.dig(:stored_credential, :initial_transaction) + 'SSL' + elsif options.dig(:stored_credential, :initiator) && options[:stored_credential][:initiator] == 'cardholder' + 'MTO' + elsif options.dig(:stored_credential, :reason_type) + case options[:stored_credential][:reason_type] + when 'recurring' + 'REC' + when 'installment' + 'INS' + when 'unscheduled' + 'MTO' + end + else + 'SSL' + end end def add_verification_value(post, payment_method) post['card.CVN'] = payment_method.verification_value end