lib/active_merchant/billing/gateways/adyen.rb in activemerchant-1.77.0 vs lib/active_merchant/billing/gateways/adyen.rb in activemerchant-1.78.0
- old
+ new
@@ -43,38 +43,49 @@
requires!(options, :order_id)
post = init_post(options)
add_invoice(post, money, options)
add_payment(post, payment)
add_extra_data(post, options)
- add_shopper_interaction(post,payment,options)
+ add_shopper_interaction(post, payment, options)
add_address(post, options)
commit('authorise', post)
end
def capture(money, authorization, options={})
post = init_post(options)
- add_invoice_for_modification(post, money, authorization, options)
- add_references(post, authorization, options)
+ add_invoice_for_modification(post, money, options)
+ add_reference(post, authorization, options)
commit('capture', post)
end
def refund(money, authorization, options={})
post = init_post(options)
- add_invoice_for_modification(post, money, authorization, options)
- add_references(post, authorization, options)
+ add_invoice_for_modification(post, money, options)
+ add_original_reference(post, authorization, options)
commit('refund', post)
end
def void(authorization, options={})
post = init_post(options)
- add_references(post, authorization, options)
+ add_reference(post, authorization, options)
commit('cancel', post)
end
+ def store(credit_card, options={})
+ requires!(options, :order_id)
+ post = init_post(options)
+ add_invoice(post, 0, options)
+ add_payment(post, credit_card)
+ add_extra_data(post, options)
+ add_recurring_contract(post, options)
+ add_address(post, options)
+ commit('authorise', post)
+ end
+
def verify(credit_card, options={})
MultiResponse.run(:use_first_response) do |r|
- r.process { authorize(100, credit_card, options) }
+ r.process { authorize(0, credit_card, options) }
r.process(:ignore_result) { void(r.authorization, options) }
end
end
def supports_scrubbing?
@@ -99,11 +110,16 @@
post[:deliveryDate] = options[:delivery_date] if options[:delivery_date]
post[:merchantOrderReference] = options[:merchant_order_reference] if options[:merchant_order_reference]
end
def add_shopper_interaction(post, payment, options={})
- shopper_interaction = payment.verification_value ? "Ecommerce" : "ContAuth"
+ if payment.respond_to?(:verification_value) && payment.verification_value
+ shopper_interaction = "Ecommerce"
+ else
+ shopper_interaction = "ContAuth"
+ end
+
post[:shopperInteraction] = options[:shopper_interaction] || shopper_interaction
end
def add_address(post, options)
return unless post[:card] && post[:card].kind_of?(Hash)
@@ -121,41 +137,67 @@
def add_invoice(post, money, options)
amount = {
value: amount(money),
currency: options[:currency] || currency(money)
}
- post[:reference] = options[:order_id]
post[:amount] = amount
end
- def add_invoice_for_modification(post, money, authorization, options)
+ def add_invoice_for_modification(post, money, options)
amount = {
value: amount(money),
currency: options[:currency] || currency(money)
}
post[:modificationAmount] = amount
end
def add_payment(post, payment)
+ if payment.is_a?(String)
+ _, _, recurring_detail_reference = payment.split("#")
+ post[:selectedRecurringDetailReference] = recurring_detail_reference
+ add_recurring_contract(post, options)
+ else
+ add_card(post, payment)
+ end
+ end
+
+ def add_card(post, credit_card)
card = {
- expiryMonth: payment.month,
- expiryYear: payment.year,
- holderName: payment.name,
- number: payment.number,
- cvc: payment.verification_value
+ expiryMonth: credit_card.month,
+ expiryYear: credit_card.year,
+ holderName: credit_card.name,
+ number: credit_card.number,
+ cvc: credit_card.verification_value
}
card.delete_if{|k,v| v.blank? }
requires!(card, :expiryMonth, :expiryYear, :holderName, :number)
post[:card] = card
end
- def add_references(post, authorization, options = {})
- post[:originalReference] = psp_reference_from(authorization)
- post[:reference] = options[:order_id]
+ def add_reference(post, authorization, options = {})
+ _, psp_reference, _ = authorization.split("#")
+ post[:originalReference] = single_reference(authorization) || psp_reference
end
+ def add_original_reference(post, authorization, options = {})
+ original_psp_reference, _, _ = authorization.split("#")
+ post[:originalReference] = single_reference(authorization) || original_psp_reference
+ end
+
+ def single_reference(authorization)
+ authorization if !authorization.include?("#")
+ end
+
+ def add_recurring_contract(post, options = {})
+ recurring = {
+ contract: "RECURRING"
+ }
+
+ post[:recurring] = recurring
+ end
+
def parse(body)
return {} if body.blank?
JSON.parse(body)
end
@@ -203,36 +245,40 @@
false
end
end
def message_from(action, response)
- case action.to_s
- when 'authorise'
+ return authorize_message_from(response) if action.to_s == 'authorise'
+ response['response'] || response['message']
+ end
+
+ def authorize_message_from(response)
+ if response['refusalReason'] && response['additionalData'] && response['additionalData']['refusalReasonRaw']
+ "#{response['refusalReason']} | #{response['additionalData']['refusalReasonRaw']}"
+ else
response['refusalReason'] || response['resultCode'] || response['message']
- when 'capture', 'refund', 'cancel'
- response['response'] || response['message']
end
end
def authorization_from(action, parameters, response)
- [parameters[:originalReference], response['pspReference']].compact.join("#").presence
+ return nil if response['pspReference'].nil?
+ recurring = response['additionalData']['recurring.recurringDetailReference'] if response['additionalData']
+ "#{parameters[:originalReference]}##{response['pspReference']}##{recurring}"
end
def init_post(options = {})
- {merchantAccount: options[:merchant_account] || @merchant_account}
+ post = {}
+ post[:merchantAccount] = options[:merchant_account] || @merchant_account
+ post[:reference] = options[:order_id] if options[:order_id]
+ post
end
def post_data(action, parameters = {})
JSON.generate(parameters)
end
def error_code_from(response)
STANDARD_ERROR_CODE_MAPPING[response['errorCode']]
end
-
- def psp_reference_from(authorization)
- authorization.nil? ? nil : authorization.split("#").first
- end
-
end
end
end