Skip to content

Commit

Permalink
Merge pull request #90 from rvanlieshout/do-not-create-mollie-custome…
Browse files Browse the repository at this point in the history
…r-for-inactive-gateway

Don't create a Mollie customer when the gateway is inactive
  • Loading branch information
Oldharlem authored Aug 10, 2020
2 parents fbc13a9 + 38d1c7f commit 6283703
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/models/spree/user_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
module Spree::UserDecorator

def self.prepended(base)
base.after_create :create_mollie_customer
base.after_commit :ensure_mollie_customer, on: %i[create update]
end

def ensure_mollie_customer
return if try(:mollie_customer_id).present?

def create_mollie_customer
# Don't create Mollie customers if spree_auth_devise is not installed.
return unless defined? Spree::User

mollie_gateway = Spree::PaymentMethod.find_by_type 'Spree::Gateway::MollieGateway'
return unless mollie_gateway.present?
return unless mollie_gateway&.active?

mollie_customer = mollie_gateway.create_customer(self)
update mollie_customer_id: mollie_customer.id
end
end

Spree.user_class.prepend(Spree::UserDecorator)
Spree.user_class.prepend(Spree::UserDecorator)

0 comments on commit 6283703

Please sign in to comment.