Class: Stall::Payments::ManualPaymentGateway::Response

Inherits:
GatewayResponse show all
Includes:
ChecksumCalculator
Defined in:
lib/stall/payments/manual_payment_gateway.rb

Instance Attribute Summary

Attributes inherited from GatewayResponse

#request

Instance Method Summary collapse

Methods included from ChecksumCalculator

#calculate_checksum_for

Methods inherited from GatewayResponse

#initialize, #process

Constructor Details

This class inherits a constructor from Stall::Payments::GatewayResponse

Instance Method Details

#cartObject



76
77
78
# File 'lib/stall/payments/manual_payment_gateway.rb', line 76

def cart
  @cart ||= ProductList.find_by_token(request.params[:cart][:token])
end

#cart_paramsObject



80
81
82
# File 'lib/stall/payments/manual_payment_gateway.rb', line 80

def cart_params
  @cart_params ||= request.params[:cart]
end

#rendering_optionsObject



48
49
50
51
52
53
# File 'lib/stall/payments/manual_payment_gateway.rb', line 48

def rendering_options
  redirect_location =
    Stall::Payments::UrlsConfig.new(cart).payment_success_return_url

  { redirect_location: redirect_location }
end

#success?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/stall/payments/manual_payment_gateway.rb', line 55

def success?
  true
end

#valid?Boolean

To allow manual payment method we verify that the provided checksum corresponds to the one we can calculate with the provided params in the form.

This avoids forging a request with ‘manual_payment` in the URL for a cart which was not set to use this method, thus allowing people to validate orders without paying them.

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
# File 'lib/stall/payments/manual_payment_gateway.rb', line 67

def valid?
  calculated_checksum = calculate_checksum_for(
    cart_params[:token], cart_params[:reference], cart_params[:timestamp]
  )
  provided_checksum = cart_params[:checksum]

  calculated_checksum == provided_checksum
end