Class: Spree::SolidusSixSaferpay::InitializePayment

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

Direct Known Subclasses

InitializePaymentPage, InitializeTransaction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, payment_method) ⇒ InitializePayment

Returns a new instance of InitializePayment.



11
12
13
14
15
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 11

def initialize(order, payment_method)
  @order = order
  @payment_method = payment_method
  @success = false
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



5
6
7
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 5

def order
  @order
end

#payment_methodObject (readonly)

Returns the value of attribute payment_method.



5
6
7
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 5

def payment_method
  @payment_method
end

#redirect_urlObject (readonly)

Returns the value of attribute redirect_url.



5
6
7
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 5

def redirect_url
  @redirect_url
end

#successObject (readonly)

Returns the value of attribute success.



5
6
7
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 5

def success
  @success
end

Class Method Details

.call(order, payment_method) ⇒ Object



7
8
9
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 7

def self.call(order, payment_method)
  new(order, payment_method).call
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 17

def call
  gateway_response = gateway.initialize_payment(order, payment_method)

  if gateway_response.success?

    saferpay_payment = build_saferpay_payment(gateway_response.api_response)

    @redirect_url = saferpay_payment.redirect_url
    @success = saferpay_payment.save!
  end

  self
end

#gatewayObject

Raises:

  • (NotImplementedError)


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

def gateway
  raise NotImplementedError, "Must be implemented in InitializePaymentPage or InitializeTransaction by including UsePaymentPageGateway or UseTransactionGateway"
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/services/spree/solidus_six_saferpay/initialize_payment.rb', line 31

def success?
  @success
end