0

I have a case where I want a user to enter an amount they want to make payment with and I want the user to be redirected to this Payment Gateway checkout page immediately after they enter an amount.

AttributeError at /payment/opay/nowdepos/
'Response' object has no attribute 'streaming'.

but my users are never redirected to this page when the amount has been entered. kindly correct me on the error in my code.

def process_paynow_payment(request, comment = None):
    if request.method == 'POST':
        form = PaymentForm(request.POST)
        if form.is_valid():
            payment  = form.save() 
            user = request.user
            first_name = user.first_name
            last_name = user.last_name
            email = user.email
            now = datetime.datetime.now()
            name = first_name
            amount = payment.amount 
            ref = payment.ref
            ramount = amount
            first_name = request.user.first_name
            last_name = request.user.last_name
           

            headers = {

                "authorization": f"Bearer XXXXXXXXX",
                "MerchantId": "XXXXXXX",
                "Content-Type": 'application/json'
                }
            data = {
                "reference": ref,
                "mchShortName": name,
                "productName": "Balance Deposit",
                "productDesc": "simply deposit now",
                "userPhone": "+123456789",
                "userRequestIp": "123.123.123.123",
                "amount": ramount,
                "currency": "USD",
                "payTypes": ["BalancePayment", "BonusPayment", "OWealth"],
                "payMethods": ["account", "qrcode", "bankCard", "bankAccount", "bankTransfer", "bankUSSD"],
                "callbackUrl": "https://callbackurl.com/callbackUrl",
                "returnUrl": "https://myreturnurl.com/returnUrl",
                "expireAt": "10"
                }

            url = 'https://cashierapi.paynow.com/api/v3/cashier/initialize'
            response = requests.post(url, json=data, headers=headers )
        
            return response

    else:
        form = PaymentForm(request.POST)
    return render(request, 'paynow/paynow_initiate_payment.html', {'form': form})

How do I resolve this issue where my users will be redirected to this payment gateway and enter their card details to complete this payment?

nullptr
  • 3,701
  • 2
  • 16
  • 40
  • I think you need to return django valid response object that will redirect to remote site. try [https://stackoverflow.com/questions/35903832/how-to-redirect-to-external-url-in-django] – Waldemar Podsiadło Jul 09 '22 at 17:53
  • @Waldemar Podsiadło, he want plant at external payment page with POST. But redirect not works with post data. He should to work with response on the front and send after post to payment – Maxim Danilov Jul 09 '22 at 18:53
  • Your can not make a request using `requests.post()` and return the server side response data from the payment gateway as a response from your django application. Please check the documentation of your payment gateway provider how to corretcly handle the payment process. – JanMalte Jul 09 '22 at 20:48

0 Answers0