lib/active_merchant/billing/gateways/adyen.rb in activemerchant-1.119.0 vs lib/active_merchant/billing/gateways/adyen.rb in activemerchant-1.120.0

- old
+ new

@@ -76,14 +76,23 @@ add_original_reference(post, authorization, options) add_splits(post, options) commit('refund', post, options) end + def credit(money, payment, options = {}) + post = init_post(options) + add_invoice(post, money, options) + add_payment(post, payment, options) + add_shopper_reference(post, options) + commit('refundWithData', post, options) + end + def void(authorization, options = {}) post = init_post(options) + endpoint = options[:cancel_or_refund] ? 'cancelOrRefund' : 'cancel' add_reference(post, authorization, options) - commit('cancel', post, options) + commit(endpoint, post, options) end def adjust(money, authorization, options = {}) post = init_post(options) add_invoice_for_modification(post, money, options) @@ -372,11 +381,11 @@ number: credit_card.number, cvc: credit_card.verification_value } card.delete_if { |_k, v| v.blank? } - card[:holderName] ||= 'Not Provided' if credit_card.is_a?(NetworkTokenizationCreditCard) + card[:holderName] ||= 'Not Provided' requires!(card, :expiryMonth, :expiryYear, :holderName, :number) post[:card] = card end def capture_options(options) @@ -389,11 +398,15 @@ _, psp_reference, = authorization.split('#') post[:originalReference] = single_reference(authorization) || psp_reference end def add_original_reference(post, authorization, options = {}) - original_psp_reference, = authorization.split('#') + if authorization.start_with?('#') + _, original_psp_reference, = authorization.split('#') + else + original_psp_reference, = authorization.split('#') + end post[:originalReference] = single_reference(authorization) || original_psp_reference end def add_mpi_data_for_network_tokenization_card(post, payment) post[:mpiData] = {} @@ -550,30 +563,31 @@ def success_from(action, response, options) if %w[RedirectShopper ChallengeShopper].include?(response.dig('resultCode')) && !options[:execute_threed] && !options[:threed_dynamic] response['refusalReason'] = 'Received unexpected 3DS authentication response. Use the execute_threed and/or threed_dynamic options to initiate a proper 3DS flow.' return false end - case action.to_s when 'authorise', 'authorise3d' %w[Authorised Received RedirectShopper].include?(response['resultCode']) - when 'capture', 'refund', 'cancel' + when 'capture', 'refund', 'cancel', 'cancelOrRefund' response['response'] == "[#{action}-received]" when 'adjustAuthorisation' response['response'] == 'Authorised' || response['response'] == '[adjustAuthorisation-received]' when 'storeToken' response['result'] == 'Success' when 'disable' response['response'] == '[detail-successfully-disabled]' + when 'refundWithData' + response['resultCode'] == 'Received' else false end end def message_from(action, response) return authorize_message_from(response) if %w(authorise authorise3d authorise3ds2).include?(action.to_s) - response['response'] || response['message'] || response['result'] + response['response'] || response['message'] || response['result'] || response['resultCode'] end def authorize_message_from(response) if response['refusalReason'] && response['additionalData'] && response['additionalData']['refusalReasonRaw'] "#{response['refusalReason']} | #{response['additionalData']['refusalReasonRaw']}"