Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(payment): Avoid error webhooks on small amount failure #2994

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading