Skip to content

Commit

Permalink
Wrap payment request and invoices payment status update...
Browse files Browse the repository at this point in the history
within a database transaction
  • Loading branch information
ancorcruz committed Aug 26, 2024
1 parent 3224256 commit 79a97cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
11 changes: 7 additions & 4 deletions app/services/payment_requests/payments/adyen_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ def create
provider_payment_id: res.response['pspReference'],
status: res.response['resultCode']
)
payment.save!

payable_payment_status = payable_payment_status(payment.status)
update_payable_payment_status(payment_status: payable_payment_status)
update_invoices_payment_status(payment_status: payable_payment_status)
ActiveRecord::Base.transaction do
payment.save!

payable_payment_status = payable_payment_status(payment.status)
update_payable_payment_status(payment_status: payable_payment_status)
update_invoices_payment_status(payment_status: payable_payment_status)
end

Integrations::Aggregator::Payments::CreateJob.perform_later(payment:) if payment.should_sync_payment?

Expand Down
23 changes: 13 additions & 10 deletions app/services/payment_requests/payments/stripe_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ def create
provider_payment_id: stripe_result.id,
status: stripe_result.status
)
payment.save!

payable_payment_status = payable_payment_status(payment.status)
update_payable_payment_status(
payment_status: payable_payment_status,
processing: payment.status == 'processing'
)
update_invoices_payment_status(
payment_status: payable_payment_status,
processing: payment.status == 'processing'
)
ActiveRecord::Base.transaction do
payment.save!

payable_payment_status = payable_payment_status(payment.status)
update_payable_payment_status(
payment_status: payable_payment_status,
processing: payment.status == 'processing'
)
update_invoices_payment_status(
payment_status: payable_payment_status,
processing: payment.status == 'processing'
)
end

result.payment = payment
result
Expand Down

0 comments on commit 79a97cd

Please sign in to comment.