Class: Adyen::API::PaymentService::AuthorisationResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/adyen/api/payment_service.rb

Constant Summary collapse

ERRORS =
{
  "validation 101 Invalid card number"                           => [:number,       'is not a valid creditcard number'],
  "validation 103 CVC is not the right length"                   => [:cvc,          'is not the right length'],
  "validation 128 Card Holder Missing"                           => [:holder_name,  "can't be blank"],
  "validation Couldn't parse expiry year"                        => [:expiry_year,  'could not be recognized'],
  "validation Expiry month should be between 1 and 12 inclusive" => [:expiry_month, 'could not be recognized'],
}
AUTHORISED =
'Authorised'
REFUSED =
'Refused'

Instance Attribute Summary

Attributes inherited from Response

#http_response

Instance Method Summary collapse

Methods inherited from Response

#body, #fault_message, #http_failure?, #initialize, response_attrs, #server_error?, #xml_querier

Constructor Details

This class inherits a constructor from Adyen::API::Response

Instance Method Details

#error(prefix = nil) ⇒ Array<Symbol, String>

In the case of a validation error, or SOAP fault message, this method will return an array describing what attribute failed validation and the accompanying message. If the errors is not of the common user validation errors, then the attribute is :base and the full original message is returned.

An optional prefix can be given so you can seamlessly integrate this in your ActiveRecord model and copy over errors.

Parameters:

  • prefix (String, Symbol) (defaults to: nil)

    A string that should be used to prefix the error key.

Returns:

  • (Array<Symbol, String>)

    A name-message pair of the attribute with an error.



318
319
320
321
322
323
324
325
326
327
328
# File 'lib/adyen/api/payment_service.rb', line 318

def error(prefix = nil)
  if error = ERRORS[fault_message]
    prefix ? ["#{prefix}_#{error[0]}".to_sym, error[1]] : error
  elsif fault_message
    [:base, fault_message]
  elsif refused?
    [:base, 'Transaction was refused.']
  else
    [:base, 'Transaction failed for unkown reasons.']
  end
end

#invalid_request?Boolean

Returns whether or not the request was valid.

Returns:

  • (Boolean)

    Returns whether or not the request was valid.



304
305
306
# File 'lib/adyen/api/payment_service.rb', line 304

def invalid_request?
  !fault_message.nil?
end

#paramsObject



330
331
332
333
334
335
336
337
338
339
340
# File 'lib/adyen/api/payment_service.rb', line 330

def params
  @params ||= xml_querier.xpath('//payment:authoriseResponse/payment:paymentResult') do |result|
    {
      :psp_reference  => result.text('./payment:pspReference'),
      :result_code    => result.text('./payment:resultCode'),
      :auth_code      => result.text('./payment:authCode'),
      :additional_data => parse_additional_data(result.xpath('.//payment:additionalData')),
      :refusal_reason => (invalid_request? ? fault_message : result.text('./payment:refusalReason'))
    }
  end
end

#refused?Boolean

Returns:

  • (Boolean)


296
297
298
# File 'lib/adyen/api/payment_service.rb', line 296

def refused?
  params[:result_code] == REFUSED
end

#success?Boolean Also known as: authorised?, authorized?

Returns:

  • (Boolean)


292
293
294
# File 'lib/adyen/api/payment_service.rb', line 292

def success?
  super && params[:result_code] == AUTHORISED
end