Skip to content

Stripe: finalize_request() appends redirect_to=None to success URL, causing broken redirect and invalid docname parsing #203

Description

@SYSINFRACH

Summary

When a Stripe payment is completed, the redirect URL generated by payments can incorrectly include redirect_to=None.

This leads to malformed success URLs such as:

  • payment-success?doctype=Payment Request&docname=ACC-PRQ-2026-00002&redirect_to=None
  • https://example.com/payment-success?redirect_to=None

In our case this caused the success page to break because the request parameters were no longer interpreted correctly downstream.

We also observed this traceback:

frappe.exceptions.DoesNotExistError: Payment Request ACC-PRQ-2026-00002?redirect_to=None not found

Affected area

File:

payments/payment_gateways/doctype/stripe_settings/stripe_settings.py

Method:

finalize_request()

Environment

erpnext 16.9.1 version-16 (99a81db)
frappe 16.11.0 version-16 (694a53f)
payments 0.0.1 develop (3cebd94)
print_designer 1.6.7 develop (9d62227)
swiss_accounting_software 0.0.6 main (5388f1c)

Observed in our environment with:

  • Frappe / ERPNext + payments
  • Stripe test mode
  • Payment Request based checkout flow

Steps to reproduce

  1. Configure Stripe in ERPNext / Frappe using the standard payments Stripe integration.
  2. Create a Payment Request.
  3. Complete a Stripe payment successfully.
  4. Let the flow return to the configured success page.

Variant A

Leave redirect_to unset / effectively None.

Variant B

Set a custom redirect_url, for example:

https://example.com/payment-success

Actual behavior

finalize_request() builds a redirect URL that still appends redirect_to=None.

Example:

https://example.com/payment-success?redirect_to=None

or

payment-success?doctype=Payment Request&docname=ACC-PRQ-2026-00002&redirect_to=None

This pollutes the return URL with a meaningless query parameter and can break downstream parsing / success page behavior.

In our case it resulted in a malformed lookup where the document name was effectively treated as:

ACC-PRQ-2026-00002?redirect_to=None

instead of just:

ACC-PRQ-2026-00002

Expected behavior

If redirect_to is empty / None, it should not be appended at all.

Expected success URL:

payment-success?doctype=Payment Request&docname=ACC-PRQ-2026-00002

or, when a custom redirect URL is configured:

https://example.com/payment-success

with no redirect_to=None appended.

Root cause

Current logic in finalize_request():

if redirect_to and "?" in redirect_url:
        redirect_url += "&" + urlencode({"redirect_to": redirect_to})
else:
        redirect_url += "?" + urlencode({"redirect_to": redirect_to})

This is wrong because the else branch still appends redirect_to, even when redirect_to is None.

Proposed fix

Only append redirect_to if it actually has a value.

Suggested change:

if redirect_to:
        if "?" in redirect_url:
                redirect_url += "&" + urlencode({"redirect_to": redirect_to})
        else:
                redirect_url += "?" + urlencode({"redirect_to": redirect_to})

Why this matters

This is not cosmetic.

A successful Stripe payment can return the user to a broken URL and trigger downstream lookup failures on the ERPNext side. It also makes custom success URLs unreliable.

Additional note

We confirmed locally that changing the redirect composition logic to only append redirect_to when truthy removes the broken ?redirect_to=None behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions