I have been grappling with the problem of integrating the flutterwave API into my Django-Oscar project.
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",
"customer.email":"ba****@
yahoo.com"} # temporary, not perfect
# 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.