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.



287
288
289
290
291
292
293
294
295
296
297
# File 'lib/adyen/api/payment_service.rb', line 287

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.



273
274
275
# File 'lib/adyen/api/payment_service.rb', line 273

def invalid_request?
  !fault_message.nil?
end

#paramsObject



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/adyen/api/payment_service.rb', line 299

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)


265
266
267
# File 'lib/adyen/api/payment_service.rb', line 265

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

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

Returns:

  • (Boolean)


261
262
263
# File 'lib/adyen/api/payment_service.rb', line 261

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