<NME> checkout_payment_redirect.rb
<BEF> ADDFILE
<MSG> Extract paypal redirect logic to service class

<DFF> @@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+# Provides the redirect path if a redirect to the payment gateway is needed
+class CheckoutPaymentRedirect
+  def initialize(params)
+    @params = params
+  end
+
+  # Returns the path to the Paypal Express form if a redirect is needed
+  def path
+    return unless @params[:order][:payments_attributes]
+
+    payment_method_id = @params[:order][:payments_attributes].first[:payment_method_id]
+    payment_method = Spree::PaymentMethod.find(payment_method_id)
+    return unless payment_method.is_a?(Spree::Gateway::PayPalExpress)
+
+    spree_routes_helper.paypal_express_path(payment_method_id: payment_method.id)
+  end
+
+  private
+
+  def spree_routes_helper
+    Spree::Core::Engine.routes_url_helpers
+  end
+end

{'addition_count': 25, 'commit_subject': 'Extract paypal redirect logic to service class', 'deletion_count': 0, 'file_extension': '.rb', 'lang': 'rb', 'license': 'agpl-3.0', 'repo_name': 'openfoodfoundation/openfoodnetwork'}