-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc(stripe): Refact payment method update webhooks
- Loading branch information
1 parent
f564be8
commit 5d2c14c
Showing
31 changed files
with
614 additions
and
411 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
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
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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
app/services/payment_provider_customers/stripe/update_payment_method_service.rb
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_String_literal: true | ||
|
||
module PaymentProviderCustomers | ||
module Stripe | ||
class UpdatePaymentMethodService < BaseService | ||
def initialize(stripe_customer:, payment_method_id:) | ||
@stripe_customer = stripe_customer | ||
@payment_method_id = payment_method_id | ||
|
||
super | ||
end | ||
|
||
def call | ||
return result.not_found_failure!(resource: 'stripe_customer') unless stripe_customer | ||
|
||
stripe_customer.payment_method_id = payment_method_id | ||
stripe_customer.save! | ||
|
||
reprocess_pending_invoices | ||
|
||
result.stripe_customer = stripe_customer | ||
result | ||
end | ||
|
||
private | ||
|
||
attr_reader :stripe_customer, :payment_method_id | ||
|
||
delegate :customer, to: :stripe_customer | ||
|
||
def reprocess_pending_invoices | ||
invoices = customer.invoices | ||
.payment_pending | ||
.where(ready_for_payment_processing: true) | ||
.where(status: 'finalized') | ||
|
||
invoices.find_each do |invoice| | ||
Invoices::Payments::StripeCreateJob.perform_later(invoice) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
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
Oops, something went wrong.