Best practice advice / docs for a "after order submit, redirect to payment gateway" scenario

192 views
Skip to first unread message

Ben Stähli

unread,
Jun 3, 2022, 7:24:48 AM6/3/22
to django...@googlegroups.com
Hi all

I'm struggling with my implementation of a payment gateway.
-
After submitting an order, the customer is redirected to the external
payment page, where he enters payment details. At this point, order
submission has started, ie the basket is frozen.
-
When external payment completes, the payment systems calls a webhook,
where I should verify correct payment.
-
Also, shortly after payment completion, the customer is redirected back
to the shop, showing either a "your order is processed" (no webhook
called yet) or a "Thank you" page.
-

So far, I guess quite a standard procedure. My questions:
-
How can I identify the correct order/basket in the webhook call? I think
of providing the payment system my basket id, so I can then load the
correct basket (with the basket id, posted to the webhook url), and
proceed accordingly?
-
In the webhook, I cannot use the CheckoutSessions's build_submission
method, as the session will depend on the customers browser, which is
not there, when the payment system calls my webhook? How is this done
normally?
-

Ironically, I've answered a SO on this topic:
https://stackoverflow.com/questions/31373028/integrating-a-redirection-included-method-of-payment-in-django-oscar/71677456#71677456

Thanks for your time
Best
Ben


--
Ben Stähli
bnzk GmbH
+41 22 575 25 77
bnzk.ch
--

moin khan

unread,
Jun 3, 2022, 8:35:37 AM6/3/22
to django...@googlegroups.com
You will get all details related to that basket by session. If you type {{request.session.basket}} in template, then you will get a basket object and you can fetch all the details of basket. You have to handle payment before submission of the actual order. well which payment gateway you used.

--
https://github.com/django-oscar/django-oscar
http://django-oscar.readthedocs.org/en/latest/
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-oscar/9e258e9b-602b-3576-76a0-d9af4a7fbfbd%40bnzk.ch.

Ben Stähli

unread,
Jun 3, 2022, 8:49:46 AM6/3/22
to django...@googlegroups.com
Thank you.
-
I'm using payrexx.ch.
-
I've raised "RedirectRequired" as suggested here:
https://django-oscar.readthedocs.io/en/3.1/howto/how_to_integrate_payment.html#integration-into-checkout
so, then, the order is not yet submitted (and besides the basket, all
details are only in the session!).
-
After successfull payment, when the payment systems/webhook calls my
payment capture url, there is obviously no session. So I cannot complete
the order until the customer visits my shop again, with his session/browser.
-
I've understood that oscar works better with a flow of "basket >
shipping > payment chooser > submit payment info > show preview > submit
order and capture payment in one step" style...so.
-
-
Currently, I think of just submitting the order completly, even when
using payrexx, but redirect just before sending confirmation emails and
stuff like this (in the "handle_successful_order" method). And just do
these last things when the webhook gets called. Oppinions on this
approach highly welcome!
> bnzk.ch <http://bnzk.ch>
> --
>
> --
> https://github.com/django-oscar/django-oscar
> <https://github.com/django-oscar/django-oscar>
> http://django-oscar.readthedocs.org/en/latest/
> <http://django-oscar.readthedocs.org/en/latest/>
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-oscar...@googlegroups.com
> <mailto:django-oscar%2Bunsu...@googlegroups.com>.
> <https://groups.google.com/d/msgid/django-oscar/9e258e9b-602b-3576-76a0-d9af4a7fbfbd%40bnzk.ch>.
>
> --
> https://github.com/django-oscar/django-oscar
> <https://github.com/django-oscar/django-oscar>
> http://django-oscar.readthedocs.org/en/latest/
> <http://django-oscar.readthedocs.org/en/latest/>
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com
> <mailto:django-oscar...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/django-oscar/CAMJxXTw5QJWgkbu6226P%2B0dG6cHY8j0ZH1A4jCQ_Oxkvy2VfOg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-oscar/CAMJxXTw5QJWgkbu6226P%2B0dG6cHY8j0ZH1A4jCQ_Oxkvy2VfOg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Ke T

unread,
Jun 6, 2022, 9:48:12 AM6/6/22
to django-oscar
Hey Ben,

I won't attempt to speak to best practices, but in my current implementation I'm using a webhook to place the order in the backend only after payment has been successfully captured.
The payment gateway I'm using (Stripe) allows adding metadata to the API calls, which is how I'm able to reference the basket from the webhook event without a user session.

Regards,
Kenneth

Ben Stähli

unread,
Jun 6, 2022, 11:00:48 AM6/6/22
to django...@googlegroups.com, Ke T
Kenneth, that sounds interesting. My gateway as well allows passing a
"referenceId", what I'm already doing.

But, I've found it difficult to place to order with basket id only, as
there are some more things involved, that are only in the session
(address, etc)? At least this is what I see when looking at the
code...may I ask if you can share a code snippet?

Thanks already!
Ben



On 06.06.22 15:48, Ke T wrote:
> Hey Ben,
>
> I won't attempt to speak to best practices, but in my current
> implementation I'm using a webhook to place the order in the backend
> only after payment has been successfully captured.
> The payment gateway I'm using (Stripe) allows adding metadata to the API
> calls, which is how I'm able to reference the basket from the webhook
> event without a user session.
>
> Regards,
> Kenneth
> On Friday, June 3, 2022 at 7:49:46 AM UTC-5 bn...@bnzk.ch wrote:
>
> Thank you.
> -
> I'm using payrexx.ch <http://payrexx.ch>.
> > +41 22 575 25 77 <tel:+41%2022%20575%2025%2077>
> > bnzk.ch <http://bnzk.ch> <http://bnzk.ch <http://bnzk.ch>>
> <https://groups.google.com/d/msgid/django-oscar/CAMJxXTw5QJWgkbu6226P%2B0dG6cHY8j0ZH1A4jCQ_Oxkvy2VfOg%40mail.gmail.com?utm_medium=email&utm_source=footer
> +41 22 575 25 77 <tel:+41%2022%20575%2025%2077>
> bnzk.ch <http://bnzk.ch>
> --
>
> --
> https://github.com/django-oscar/django-oscar
> <https://github.com/django-oscar/django-oscar>
> http://django-oscar.readthedocs.org/en/latest/
> <http://django-oscar.readthedocs.org/en/latest/>
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com
> <mailto:django-oscar...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/django-oscar/eab082f8-6a45-44a2-990f-dc5fa8cc95e0n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-oscar/eab082f8-6a45-44a2-990f-dc5fa8cc95e0n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Ben Stähli
bn...@bnzk.ch

Ke T

unread,
Jun 22, 2022, 11:36:58 AM6/22/22
to django-oscar
Hey Ben,

It would be quite a lot of code to paste here, but if you'd like a specific piece of the puzzle I could possibly link a snippet.
 
In any case, the information you're talking about needing the session for: shipping address, billing address, etc., per my setup, is stored via the Stripe API as an 'Order' object. This is actually required as order placement relies on a webhook which is only triggered on payment success...so we don't have access to the user's session.

On my end, a Stripe API call is made as the user enters the checkout phase, creating a Stripe 'Order' object. As the user progresses through the checkout phase, pertinent information is collected and added to said Stripe Order object. So, once we are ready to capture payment, this Order object contains all the information we might need. Hope this helps

Regards,
Kenneth

Ben Stähli

unread,
Jun 22, 2022, 1:02:49 PM6/22/22
to django...@googlegroups.com, Ke T
THank you Kenneth, yes this clears things up a lot.

Thing is, I also have a "Invoice" payment mode, and I dont want to do
things twice. Also, storing a complete order on a payment provider
sounds like some work to do ;-).

Best
Ben
> > I'm using payrexx.ch <http://payrexx.ch> <http://payrexx.ch
> <http://bnzk.ch <http://bnzk.ch> <http://bnzk.ch <http://bnzk.ch>>>
> <https://groups.google.com/d/msgid/django-oscar/eab082f8-6a45-44a2-990f-dc5fa8cc95e0n%40googlegroups.com?utm_medium=email&utm_source=footer
> +41 22 575 25 77 <tel:+41%2022%20575%2025%2077>
> bnzk.ch <http://bnzk.ch>
> --
>
> --
> https://github.com/django-oscar/django-oscar
> <https://github.com/django-oscar/django-oscar>
> http://django-oscar.readthedocs.org/en/latest/
> <http://django-oscar.readthedocs.org/en/latest/>
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com
> <mailto:django-oscar...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/django-oscar/5b6bb032-41d0-4caf-abe7-b9b8c0c3858an%40googlegroups.com
> <https://groups.google.com/d/msgid/django-oscar/5b6bb032-41d0-4caf-abe7-b9b8c0c3858an%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages