-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from rvanlieshout/do-not-create-mollie-custome…
…r-for-inactive-gateway Don't create a Mollie customer when the gateway is inactive
- Loading branch information
Showing
1 changed file
with
5 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |