开发者

Django: Handling post transaction logic

开发者 https://www.devze.com 2023-04-12 05:03 出处:网络
Common use case: User select item to add to cart User makes p开发者_Go百科ayment via off site payment gateway such as paypal or

Common use case:

  1. User select item to add to cart

  2. User makes p开发者_Go百科ayment via off site payment gateway such as paypal or worldpay

  3. User gets redirect to payment page and makes payment

  4. Payment portal sends a POST request to a callback URL

  5. User gets redirected back to your page

On Step 4, typically the following things happen:

  1. Error handling and anti fraud checking

  2. Updating of order/cart models and additional logic

My question is pertaining to this step 4:

In apps like Django-Paypal, rather than do all the logic processing on the callback url view function, signals are used instead. Is there a good reason for this? Why not just do all the logic on the callback url view function?


The use of signals decouples django-paypal from your own apps. You can have all kinds of crazy custom stuff happening on payment success or failure in your projects and still use the default provided view.

The class based views in Django 1.3 do make it possible to extend views, and provide an alternative way to decoupling an apps view.

Other considerations you should have before putting logic in views is time; if logic could take a long time (like any I/O), ask yourself if they are crucial to the Response at hand and consider putting it in a task queue, so you can handle the Request quickly, without blocking.

0

精彩评论

暂无评论...
验证码 换一张
取 消