Skip to content

Commit

Permalink
fix(stripe): Add invoice description to payment url payload (#2278)
Browse files Browse the repository at this point in the history
## Context

Payment description not provided when after complting the payment via
payment URL.
Stripe payment does not include the standard description (shows payment
intent ID instead).

## Description

This PR fixes the issue by adding description to the payload.
  • Loading branch information
ivannovosad committed Jul 12, 2024
1 parent e14c3e3 commit a7a7b44
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/services/invoices/payments/stripe_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def stripe_payment_payload
confirm: true,
off_session: true,
error_on_requires_action: true,
description: "#{organization.name} - Invoice #{invoice.number}",
description:,
metadata: {
lago_customer_id: customer.id,
lago_invoice_id: invoice.id,
Expand Down Expand Up @@ -241,6 +241,7 @@ def payment_url_payload
customer: customer.stripe_customer.provider_customer_id,
payment_method_types: customer.stripe_customer.provider_payment_methods,
payment_intent_data: {
description:,
metadata: {
lago_customer_id: customer.id,
lago_invoice_id: invoice.id,
Expand All @@ -252,6 +253,10 @@ def payment_url_payload
}
end

def description
"#{organization.name} - Invoice #{invoice.number}"
end

def invoice_payment_status(payment_status)
return :pending if PENDING_STATUSES.include?(payment_status)
return :succeeded if SUCCESS_STATUSES.include?(payment_status)
Expand Down
62 changes: 62 additions & 0 deletions spec/services/invoices/payments/stripe_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,68 @@
end
end

describe '#payment_url_payload' do
subject(:payment_url_payload_call) { stripe_service.__send__(:payment_url_payload) }

let(:payload) do
{
line_items: [
{
quantity: 1,
price_data: {
currency: invoice.currency.downcase,
unit_amount: invoice.total_amount_cents,
product_data: {
name: invoice.number
}
}
}
],
mode: 'payment',
success_url:,
customer: customer.stripe_customer.provider_customer_id,
payment_method_types: customer.stripe_customer.provider_payment_methods,
payment_intent_data: {
description:,
metadata: {
lago_customer_id: customer.id,
lago_invoice_id: invoice.id,
invoice_issuing_date: invoice.issuing_date.iso8601,
invoice_type: invoice.invoice_type,
payment_type: 'one-time'
}
}
}
end

let(:success_url) { stripe_service.__send__(:success_redirect_url) }
let(:description) { stripe_service.__send__(:description) }

before do
stripe_payment_provider
stripe_customer
end

it 'returns payload' do
expect(subject).to eq(payload)
end
end

describe '#description' do
subject(:description_call) { stripe_service.__send__(:description) }

let(:description) { "#{organization.name} - Invoice #{invoice.number}" }

before do
stripe_payment_provider
stripe_customer
end

it 'returns description' do
expect(subject).to eq(description)
end
end

describe '.update_payment_status' do
let(:payment) do
create(
Expand Down

0 comments on commit a7a7b44

Please sign in to comment.