Skip to content

Commit

Permalink
misc(payment): Avoid error webhooks on small amount failure
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Dec 23, 2024
1 parent 7909008 commit 0604e13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/services/invoices/payments/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def call
payment_provider_id: current_payment_provider.id,
payment_provider_customer_id: current_payment_provider_customer.id,
amount_cents: invoice.total_amount_cents,
amount_currency: invoice.currency
amount_currency: invoice.currency,
status: "pending"
).find_or_create_by!(
payable: invoice,
payable_payment_status: "pending",
status: "pending"
payable_payment_status: "pending"
)

result.payment = payment
Expand All @@ -56,9 +56,9 @@ def call
result
rescue BaseService::ServiceFailure => e
result.payment = e.result.payment
deliver_error_webhook(e.result)

if e.result.payment.payable_payment_status&.to_sym != :pending
deliver_error_webhook(e.result)
update_invoice_payment_status(payment_status: e.result.payment.payable_payment_status)
end

Expand Down
4 changes: 3 additions & 1 deletion spec/services/invoices/payments/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
end
end

it "re-reaise the error and delivers an error webhook" do
it "updates the invoice payment status and does not delivers an error webhook" do
result = create_service.call

expect(result).to be_success
Expand All @@ -262,6 +262,8 @@

expect(provider_class).to have_received(:new)
expect(provider_service).to have_received(:call!)

expect(SendWebhookJob).not_to have_been_enqueued
end
end
end
Expand Down

0 comments on commit 0604e13

Please sign in to comment.