Django-oscar COD implementation

It's been 1 week now and I can't figure out how to implement COD in django-oscar. I will be very grateful if someone at least gives me a start to complete this task. I tried to use several Github repos , but they are either outdated or not clear enough to use with the project. The initial start will be good enough for me to start from scratch. Thanks to

+3


source to share


2 answers


I haven't implemented COD for Oscar yet, but for weeks I've been looking for oscar source code for another custom payment integration. The tricky part is that payment includes orders, cart, partner, order, and payment apps. Keep the source code of the original view.py file and close it and reference it often.

So what are the crucial steps:



  • All payment processing happens in the PaymentDetailsView checkout application, so you need the forked checkout application to start creating your custom PaymentDetailsView subclass.
  • You need to override the submit () method where you create the order number, hold the cart, save it in the session, and send the pre_payment signal (just copy / paste the source code). Since no payment will be made here, you will need to remove this part from your custom submit () implementation at this point.
  • Then you need to proceed as if the payment was done and call handle_order_placement () which will call handle_successful_order ()
  • Subsequently, when payment has been received on the arrival of your products, you need to implement handle_payment () for the corresponding order number and call the post_payment signal.

That in a nutshell, but obviously there is some exception handling as well. Hope it helps you!

+1


source


I recently implemented COD on django-oscar. Here's what you need to do.

You should understand how oscar validation process works. Let me show you a little. Oscars has one "checkout" app that handles the entire payment by placing the order as goods. Therefore, first of all, you need to fork this application with the command below.

./manage.py oscar_fork_app checkout apps/shop

      

Then add it in INSTALLED_APPS

in the settings.

Now, if you take a close look in the checkout application views.py

, there is this PaymentDetailsView class that handles the order of posting and payment.



Now, in the preview.html page, you can add the gateway option as "cod". When the user selects this "cod" option and submits for a "seat order", you can test the presented gateway code against the handle_payment

forked class method 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 a method handle_payment

, it continues executing the method of submit

the same class and places an order.

After that, you can indicate on the control panel what this product has cash-on-delivery

. After delivery, you can record another payment event as 'CASH-RECEIVED'

.

Ask if there is another request.

+1


source







All Articles