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

fix(payments): separate redirect constructor from authorization #37502

Closed

Conversation

blaggacao
Copy link
Collaborator

@blaggacao blaggacao commented Oct 14, 2023

Context

Condiser a payment gateway that implements Instant Payment Notification (IPN), i.e. a request to
a custom webhook to notifiy the payment status.

Such IPN requests regularely are incoming prior to the user returning from the embedded form.

Now, those IPN endpoints in erpnext need to invoke on_payment_authorized on the referenc document all the while
they cannot make sense of any redirects.

What is more, as the user returns from the embedded form, they still need the redirect information, but without
invoking those parts of on_payment_authorized which would recreate state (such as: create payment entry and invoice).

Therefore, under the current implementation, implementing IPN means creating 2 payment entries, 2 invoces, etc, in those
cases wher not only the IPN returns but also the user (i.e. the user doesn't early abandon, but after having paid).

Proposed solution

  • Separate out the redirect callback so that it can be invoked independently from the user form return flow without recreating state
  • Still keep it in on_payment_authorized in a backwards compatible manner

This is meant to be used in payment flow finalizers as so:

		if not redirect_to:
			try:
				redirect_to = frappe.get_doc(
					reference_doctype, reference_docname,
				).run_method("on_payment_authorized_redirect")
			except:
    				pass

@blaggacao

This comment was marked as outdated.

@blaggacao blaggacao closed this Nov 5, 2023
@blaggacao blaggacao deleted the fix/payment-on-authorized-hook branch December 16, 2023 16:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant