Skip to content

Commit ab22238

Browse files
authored
Merge pull request #4302 from 3scale/fix-invoice-payment-page
THREESCALE-14843: Fix invoice payment page
2 parents 017b51b + eed8c79 commit ab22238

7 files changed

Lines changed: 50 additions & 6 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ dnsmasq-container: &dnsmasq-container
148148
--log-facility=- \
149149
--log-queries \
150150
--no-poll \
151-
--server=/circleci.com/dns.podman/circleci-tasks-prod.s3.us-east-1.amazonaws.com/circleci-binary-releases.s3.amazonaws.com/$DEFAULT_DNS \
151+
--server=/circleci.com/dns.podman/circleci-tasks-prod.s3.us-east-1.amazonaws.com/circleci-binary-releases.s3.amazonaws.com/api.stripe.com/js.stripe.com/$DEFAULT_DNS \
152152
--address=/#/127.0.0.1
153153
154154
only-master-filter: &only-master-filter

app/javascript/packs/invoice_payment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const style = {
2727
// eslint-disable-next-line @typescript-eslint/no-misused-promises
2828
document.addEventListener('DOMContentLoaded', async () => {
2929
const dataset = document.querySelector<HTMLElement>('.stripe-form')!.dataset
30-
const { stripePublishableKey = '', clientSecret = '' } = dataset
30+
const { publishableKey = '', clientSecret = '' } = dataset
3131
const form = document.querySelector('#payment-form')!
3232
const callbackForm = document.querySelector<HTMLFormElement>('#payment-callback-form')!
3333
const payButton = document.querySelector<HTMLButtonElement>('#submit-payment')!
@@ -36,7 +36,7 @@ document.addEventListener('DOMContentLoaded', async () => {
3636
const spinner = document.querySelector('#spinner')!
3737
const buttonText = document.querySelector('#button-text')!
3838

39-
const stripe = await loadStripe(stripePublishableKey)!
39+
const stripe = await loadStripe(publishableKey)
4040
const elements = stripe!.elements()
4141
const card = elements.create('card', { style })
4242

features/developer_portal/admin/account/payment_details.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ Feature: Dev Portal Buyer Payment Details
8989
When the buyer is reviewing their account settings
9090
Then the buyer can't add an incomplete billing address for stripe
9191

92+
@javascript
93+
Scenario: Buyer pays a failed invoice
94+
Given the provider has Stripe configured as payment gateway
95+
And the buyer has an invoice for May, 2026 with the following items:
96+
| Name | Description | Quantity | Cost |
97+
| Something | Nice things | 1 | 10 |
98+
And the invoice has a pending payment intent
99+
And they go to the invoice dev portal page
100+
And Stripe API is stubbed
101+
And they follow "Pay invoice"
102+
Then the current page is the invoice payment page on dev portal
103+
And the Stripe form is visible and configured
104+
92105
Rule: Braintree
93106

94107
Background:

features/step_definitions/finance/invoicing_steps.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
invoice.fail
9393
end
9494

95+
Given("the invoice has a pending payment intent") do
96+
invoice = @invoice.presence || Invoice.last
97+
invoice.finalize
98+
invoice.issue
99+
FactoryBot.create(:payment_intent, invoice: invoice, reference: 'pi_test', state: 'requires_payment_method')
100+
end
101+
95102
Then(/^I should (?:see|still see) (\d+) invoices?$/) do |count|
96103
if count.to_i == 0
97104
should have_no_xpath("//tr[contains(@id, 'invoice_')]")
@@ -232,3 +239,18 @@ def assert_line_items(items)
232239
Then "the total cost is/should( be) {string}" do |cost_with_currency|
233240
assert_equal cost_with_currency, find('table.invoice tfoot tr td#invoice_cost').text
234241
end
242+
243+
Given "Stripe API is stubbed" do
244+
stub_request(:get, %r{https://api\.stripe\.com/v1/payment_intents/pi_test})
245+
.to_return(status: 200, body: '{"id": "pi_test", "client_secret": "pi_test_secret", "object": "payment_intent"}', headers: { 'Content-Type' => 'application/json' })
246+
end
247+
248+
Then "the Stripe form is visible and configured" do
249+
stripe_form = page.find('.stripe-form')
250+
251+
assert_not_empty stripe_form['data-publishable-key']
252+
assert_not_empty stripe_form['data-client-secret']
253+
within(stripe_form) do
254+
assert_selector('#card-element iframe')
255+
end
256+
end

features/step_definitions/finance/settings_steps.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
provider.update!(payment_gateway_type: nil, payment_gateway_options: nil)
55
end
66

7+
Given "{provider} has Stripe configured as payment gateway" do |provider|
8+
provider.update(payment_gateway_type: :stripe, payment_gateway_options: { login: 'sk_test', publishable_key: 'pk_test', endpoint_secret: 'some-secret' })
9+
assert_instance_of ActiveMerchant::Billing::StripeGateway, provider.payment_gateway
10+
end
11+
712
But "the provider's payment gateway is unconfigured" do
813
@provider.update!(payment_gateway_options: nil)
914
end

features/support/capybara.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
options.add_argument('--no-sandbox')
3939
options.add_argument('--no-zygote') # zygote proc used by sandboxing
4040
options.add_argument('--disable-popup-blocking')
41-
options.add_argument('--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE *localhost*')
41+
options.add_argument('--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE *localhost*,EXCLUDE api.stripe.com,EXCLUDE js.stripe.com')
4242
options.add_argument('--process-per-site')
4343
options.add_argument('--disable-gpu') # TODO: gpu-process still started
4444
options.add_argument('--disable-gpu-early-init')

features/support/paths.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,14 @@ def path_to(page_name, *args) # rubocop:disable Metrics/AbcSize, Metrics/Cycloma
683683
when 'the dev portal invoices page'
684684
admin_account_invoices_path
685685

686-
when /^the invoice "(.*)" dev portal page$/
687-
invoice = Invoice.find_by!(friendly_id: $1)
686+
when /^the invoice(?: "(.*)")? dev portal page$/
687+
invoice = $1.present? ? Invoice.find_by!(friendly_id: $1) : @invoice
688688
admin_account_invoice_path(invoice)
689689

690+
when /^the invoice(?: "(.*)")? payment page on dev portal$/
691+
invoice = $1.present? ? Invoice.find_by!(friendly_id: $1) : @invoice
692+
payment_admin_account_invoice_path(invoice)
693+
690694
when 'the provider site page'
691695
admin_site_settings_path
692696

0 commit comments

Comments
 (0)