Flutterwave Payment Redirect Integration into Django-Oscar

瀏覽次數:246 次
跳到第一則未讀訊息

Tunde Ojo

未讀,
2021年7月15日 上午10:45:212021/7/15
收件者:django-oscar
Good day all,

I have been grappling with the problem of integrating the flutterwave API into my Django-Oscar project.

I have forked the checkout app and I am attempting to override the PaymentDetailsView in checkout.views.py as shown below:

from oscar.apps import checkout
from oscar.apps.checkout import session, views
from oscar.apps.checkout.forms import User
from oscar.apps.payment import models

from oscar.apps.payment.exceptions import *
import requests
import datetime

import os

from requests.api import request
import json

FLUTTERWAVE_SECRET_KEY = os.environ.get('FLUTTERWAVE_SECRET_KEY')
a='Bearer ' + FLUTTERWAVE_SECRET_KEY


# Subclass the core Oscar view so we can customise
class PaymentDetailsView(views.PaymentDetailsView):

    def handle_payment(self, order_number, total, **kwargs):
        # Talk to payment gateway.  If unsuccessful/error, raise a
        # PaymentError exception which we allow to percolate up to be caught
        # and handled by the core PaymentDetailsView.


       
        # Hardcode the para variable for a dictionary. I will like to get the 
        para = {"tx_ref":"hooli-tx-1920bbtytty", "amount":"100", "currency":"NGN", 
                "redirect_url":"https://webhook.site/9d0b00ba-9a69-44fa-a43d-a82c33c36fdc", 
                "customer.email":"ba****@yahoo.com"} # temporary, not perfect
             
        response2=requests.post(url, para, headers={'Authorization': a}) 

        
        # the response is in the following form {"status":"success","message":"Hosted Link",
        # extract the text part of the response in string format
        response2_text = response2.text
        
        # convert the extracted text from response to json
        response2_json = json.loads(response2_text)

        # Get the data and link part from the response_json
        pay_url = response2_json.get("data").get("link")

        # Redirect to the pay_url link returned as link in response to bring up the 
        # flutterwave modal so that customer can enter make payment
        raise RedirectRequired(pay_url)


Instead of hard-coding the para dictionary, how can I get the dynamic vlaues such as email, basket totals_incl_tax and my tr_ref which I believe is the order_no.

I will like some help to get this working. Thanks in anticipation of your help.

回覆所有人
回覆作者
轉寄
0 則新訊息