mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Do not load order twice
The controller already does so, then, we can pass it to the service and avoid that extra round-trip to the DB and save some memory. Spree::Order is a rather bulky object (God object code smell perhaps) and it'll surely make a difference.
This commit is contained in:
@@ -25,8 +25,8 @@ module Spree
|
||||
before_action :check_at_least_one_line_item, only: :update
|
||||
|
||||
def show
|
||||
ProcessPaymentIntent.new(params["payment_intent"], params[:id]).call!
|
||||
@order = Spree::Order.find_by!(number: params[:id])
|
||||
ProcessPaymentIntent.new(params["payment_intent"], @order).call!
|
||||
end
|
||||
|
||||
def empty
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProcessPaymentIntent
|
||||
def initialize(payment_intent, order_number)
|
||||
def initialize(payment_intent, order)
|
||||
@payment_intent = payment_intent
|
||||
@order = Spree::Order.find_by!(number: order_number)
|
||||
@last_payment = OrderPaymentFinder.new(@order).last_payment
|
||||
@order = order
|
||||
@last_payment = OrderPaymentFinder.new(order).last_payment
|
||||
end
|
||||
|
||||
def call!
|
||||
@@ -16,8 +16,10 @@ class ProcessPaymentIntent
|
||||
|
||||
private
|
||||
|
||||
attr_reader :order
|
||||
|
||||
def valid?
|
||||
@order.present? && valid_intent_string? && matches_last_payment?
|
||||
order.present? && valid_intent_string? && matches_last_payment?
|
||||
end
|
||||
|
||||
def valid_intent_string?
|
||||
|
||||
Reference in New Issue
Block a user