Sha256: 4fac4bf311bc6655e447c50658a66320e089a9d2dc1a80198a46eb102d09bdf4

Contents?: true

Size: 1.38 KB

Versions: 20

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module SolidusPaypalCommercePlatform
  class WizardController < ::Spree::Api::BaseController
    helper ::Spree::Core::Engine.routes.url_helpers

    def create
      authorize! :create, ::Spree::PaymentMethod

      @payment_method = ::Spree::PaymentMethod.new(payment_method_params)

      if @payment_method.save
        edit_url = spree.edit_admin_payment_method_url(@payment_method)

        render(
          json: { redirectUrl: edit_url },
          status: :created,
          location: edit_url,
          notice: "The PayPal Commerce Platform payment method has been successfully created"
        )
      else
        render json: @payment_method.errors, status: :unprocessable_entity
      end
    end

    private

    def payment_method_params
      {
        name: "PayPal Commerce Platform",
        type: SolidusPaypalCommercePlatform::PaymentMethod,
        preferred_client_id: api_credentials.client_id,
        preferred_client_secret: api_credentials.client_secret,
        preferred_test_mode: SolidusPaypalCommercePlatform.config.env.sandbox?,
        available_to_admin: false,
      }
    end

    def api_credentials
      @api_credentials ||= SolidusPaypalCommercePlatform::Client.fetch_api_credentials(
        auth_code: params.fetch(:authCode),
        client_id: params.fetch(:sharedId),
        nonce: params.fetch(:nonce),
      )
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
solidus_paypal_commerce_platform-1.0.3 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-1.0.2 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.7.1 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-1.0.1 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-1.0.0 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.7.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-1.0.0.beta3 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-1.0.0.beta2 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-1.0.0.beta1 lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.6.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.5.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.4.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.3.2 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.3.1 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.3.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.2.2 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.2.1 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.2.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.1.0 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb
solidus_paypal_commerce_platform-0.0.1 app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb