Class: Spree::SolidusSixSaferpay::InquirePayment

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree/solidus_six_saferpay/inquire_payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(saferpay_payment) ⇒ InquirePayment

Returns a new instance of InquirePayment.



10
11
12
13
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 10

def initialize(saferpay_payment)
  @saferpay_payment = saferpay_payment
  @order = saferpay_payment.order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



4
5
6
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 4

def order
  @order
end

#saferpay_paymentObject (readonly)

Returns the value of attribute saferpay_payment.



4
5
6
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 4

def saferpay_payment
  @saferpay_payment
end

#successObject (readonly)

Returns the value of attribute success.



4
5
6
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 4

def success
  @success
end

#user_messageObject (readonly)

Returns the value of attribute user_message.



4
5
6
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 4

def user_message
  @user_message
end

Class Method Details

.call(saferpay_payment) ⇒ Object



6
7
8
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 6

def self.call(saferpay_payment)
  new(saferpay_payment).call
end

Instance Method Details

#callObject

NOTE: This will be successful regardless of the API response. The reason is that the API returns HTTP error codes for failed payments, but the inquiry was still successful



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 18

def call
  inquiry = gateway.inquire(saferpay_payment)

  if inquiry.success?
    saferpay_payment.update_attributes(saferpay_payment_attributes(inquiry.api_response))
  else
    saferpay_payment.update_attributes(response_hash: saferpay_payment.response_hash.merge(error: "#{inquiry.error_name}"))
    general_error = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
    specific_error = I18n.t(inquiry.error_name, scope: [:six_saferpay, :error_names])
    @user_message = "#{general_error}: #{specific_error}"
  end

  @success = true

  self
end

#gatewayObject

Raises:

  • (NotImplementedError)


39
40
41
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 39

def gateway
  raise NotImplementedError, "Must be implemented in AssertPaymentPage or AuthorizeTransaction with UsePaymentPageGateway or UseTransactionGateway"
end

#success?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/services/spree/solidus_six_saferpay/inquire_payment.rb', line 35

def success?
  @success
end