Skip to content

Instantly share code, notes, and snippets.

@vernondegoede
Created March 20, 2018 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vernondegoede/5369c213309ba341d44438129d82a115 to your computer and use it in GitHub Desktop.
Save vernondegoede/5369c213309ba341d44438129d82a115 to your computer and use it in GitHub Desktop.
Redirect to Mollie checkout
module Spree
module CheckoutWithMollie
def update
if payment_params_valid? && paying_with_mollie?
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
payment = @order.payments.last
payment.process!
mollie_payment_url = payment.payment_source.payment_url
MollieLogger.debug("For order #{@order.number} redirect user to payment URL: #{mollie_payment_url}")
redirect_to mollie_payment_url
else
render :edit
end
else
super
end
end
end
CheckoutController.class_eval do
prepend CheckoutWithMollie
private
def payment_method_id_param
params[:order][:payments_attributes].first[:payment_method_id]
end
def paying_with_mollie?
payment_method = PaymentMethod.find(payment_method_id_param)
payment_method.is_a? Gateway::MollieGateway
end
def payment_params_valid?
(params[:state] === 'payment') && params[:order][:payments_attributes]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment