Class: SolidusMollie::CallbacksController
- Inherits:
-
Spree::StoreController
- Object
- Spree::StoreController
- SolidusMollie::CallbacksController
- Defined in:
- app/controllers/solidus_mollie/callbacks_controller.rb
Overview
Handles the two requests Mollie sends us:
* #webhook - server-to-server POST with the payment id (source of truth)
* #return - the buyer's browser coming back from Mollie's hosted page
Instance Method Summary collapse
-
#return ⇒ Object
GET /mollie/return?order_number=R123&token=abc.
-
#webhook ⇒ Object
POST /mollie/webhook (body: id=tr_xxxxx).
Instance Method Details
#return ⇒ Object
GET /mollie/return?order_number=R123&token=abc
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/solidus_mollie/callbacks_controller.rb', line 24 def return order = ::Spree::Order.find_by!(number: params[:order_number]) if params[:token].present? && order.token.present? && !ActiveSupport::SecurityUtils.secure_compare(params[:token].to_s, order.token.to_s) raise ActiveRecord::RecordNotFound end unless order.completed? flash[:notice] = I18n.t('solidus_mollie.confirming_payment', default: "Thanks! We're confirming your payment with Mollie.") end redirect_to spree.order_url(order, token: order.token) rescue ActiveRecord::RecordNotFound flash[:error] = I18n.t('solidus_mollie.order_not_found', default: 'Order not found.') redirect_to spree.root_path end |
#webhook ⇒ Object
POST /mollie/webhook (body: id=tr_xxxxx)
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/solidus_mollie/callbacks_controller.rb', line 11 def webhook SolidusMollie::ProcessWebhook.call(mollie_payment_id: params[:id]) head :ok rescue SolidusMollie::ProcessWebhook::PaymentNotFound => e # 422 so Mollie retries (covers the rare webhook-before-persist race). Rails.logger.warn("[solidus_mollie] webhook payment not found: #{e.}") head :unprocessable_entity rescue StandardError => e Rails.logger.error("[solidus_mollie] webhook error: #{e.}") head :internal_server_error end |