diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index e0b23277da..fbad74e943 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -58,7 +58,8 @@ module Spree # Currently can only destroy the whole customer object def destroy_at_stripe - if @credit_card.payment_method && @credit_card.payment_method.type == "Spree::Gateway::StripeSCA" + if @credit_card.payment_method && + @credit_card.payment_method.type == "Spree::Gateway::StripeSCA" options = { stripe_account: stripe_account_id } end diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 03b2c0c5a7..ca1fd676e8 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,5 +1,7 @@ class Subscription < ActiveRecord::Base - ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", "Spree::Gateway::StripeConnect", "Spree::Gateway::StripeSCA"].freeze + ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", + "Spree::Gateway::StripeConnect", + "Spree::Gateway::StripeSCA"].freeze belongs_to :shop, class_name: 'Enterprise' belongs_to :customer diff --git a/app/serializers/api/admin/payment_method_serializer.rb b/app/serializers/api/admin/payment_method_serializer.rb index 18fccbe9e7..9862b81dcd 100644 --- a/app/serializers/api/admin/payment_method_serializer.rb +++ b/app/serializers/api/admin/payment_method_serializer.rb @@ -4,7 +4,8 @@ module Api delegate :serializable_hash, to: :method_serializer def method_serializer - if object.type == 'Spree::Gateway::StripeConnect' || object.type == 'Spree::Gateway::StripeSCA' + if object.type == 'Spree::Gateway::StripeConnect' || + object.type == 'Spree::Gateway::StripeSCA' Api::Admin::PaymentMethod::StripeSerializer.new(object) else Api::Admin::PaymentMethod::BaseSerializer.new(object) diff --git a/app/services/subscription_validator.rb b/app/services/subscription_validator.rb index 9ba52145e4..4cce8a3af3 100644 --- a/app/services/subscription_validator.rb +++ b/app/services/subscription_validator.rb @@ -82,13 +82,18 @@ class SubscriptionValidator def credit_card_ok? return unless customer && payment_method - return unless payment_method.type == "Spree::Gateway::StripeConnect" || payment_method.type == "Spree::Gateway::StripeSCA" + return unless stripe_payment_method?(payment_method) return errors.add(:payment_method, :charges_not_allowed) unless customer.allow_charges return if customer.user.andand.default_card.present? errors.add(:payment_method, :no_default_card) end + def stripe_payment_method?(payment_method) + payment_method.type == "Spree::Gateway::StripeConnect" || + payment_method.type == "Spree::Gateway::StripeSCA" + end + def subscription_line_items_present? return if subscription_line_items.reject(&:marked_for_destruction?).any?