It has been 1 week now, and I cannot figure out the way to implement COD in django-oscar. I would be really thankful if someone can at least give me a head start to accomplish this task. I've tried to use few Github repositories, but either they are outdated or not clear enough to be used with the project. A head start will be good enough for me to get started from scratch. Thanks
I have not yet implemented COD for Oscar, but I have been digging in the oscar source code for weeks for another non-standard payment integration. The hard part is that payment involves the checkout, basket, partner, order and payment apps. Keep the source code of the original checkout views.py file close, and refer to it often.
So what are the crucial steps:
That's about it in a nutshell, but obviously there is some exception handling needed as well. Hope this will get you started!
I have recently implemented COD on django-oscar. Here's what you need to do.
You should understand how the checkout process of oscar works. Let me show you in the bit. There is one 'checkout' app in the oscar which handles all the payment, placing order like stuffs. So, first of all you need to fork that app with below command.
./manage.py oscar_fork_app checkout apps/shop
Then add it in the INSTALLED_APPS
at settings.
Now, If you look closely in the checkout app's views.py
, there is this class PaymentDetailsView which handles the placing order and payment stuff.
Now, at your preview.html page, you can add gateway option as 'cod'. When user selects this 'cod' option and submit for 'place order', you can check for submitted gateway code at the handle_payment
method of the forked class PaymentDetailsView
.
CorePaymentDetailsView = get_class('checkout.views', 'PaymentDetailsView')
class PaymentDetailsView(CorePaymentDetailsView):
"""
currently used to redirect to preview page
Handles the payment and cod.
"""
def handle_payment(self, order_number, total, **kwargs):
self.amount = float(total.excl_tax)
gateway_code = self.request.POST.get('gateway_code', None)
if gateway_code and gateway_code == 'cash-on-delivery':
# Record payment source and event
source_type, is_created = SourceType.objects.get_or_create(
name='cash-on-delivery')
source = source_type.sources.model(
source_type=source_type,
amount_allocated=total.excl_tax)
self.add_payment_source(source)
self.add_payment_event('CREATED', total.excl_tax)
return
When you return from the handle_payment
method, it continues executing the submit
method of the same class and places the order.
After that you can mention at the dashboard that, this product has cash-on-delivery
option. After delivery you can capture another payment-event as 'CASH-RECEIVED'
.
Ask if have any other query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With