Skip to Content
Menu
This question has been flagged
1 Reply
7414 Views

Hello Everyone !

How can we redirect to a http URL along with form data.

I am integrating a payment gateway and want to redirect to payment gateway site through a controller. But we have some credentials to access the URL. So we have to pass these credentials in form data with redirect request.

Here is my controller:

@http.route('/payment/gateway/nift/post', type='http', auth='public', website=True)
def payment_gateway_nift_post_request(self, **kw):
payload = {
'pp_Version': 1.1,
'pp_Language': 'EN',
'pp_MerchantID': 'abc',
'pp_SubMerchantID': 'abcsub',
'pp_Password': '123',
'pp_TxnRefNo': '222',
'pp_Amount': 10000,
'pp_TxnCurrency': 'PKR',
'pp_TxnDateTime': '20201214135136',
'pp_BillReference': 'Cart0011',
'pp_Description': 'Payment for 3Item(s) bought',
'pp_TxnExpiryDateTime': '20201214135436',
'pp_ReturnURL': 'return_url',
'pp_SecureHash': '5fab8dcbd2d78508b8c3d9ea41ae7c16bd6e92ceddec04e2323be3c5b9086c74',
}
return werkzeug.utils.redirect('https://uat-merchants-url', payload)

  I am using werkzeug.utils.redirect("URL") to redirect to URL, but I am unable to pass access credentials.

How can we do it?

Thank You.

Avatar
Discard
Best Answer

Hello Muhammad Yaseen,

First of all, you need to post this payload data to the desirable URL by using request.

Like this:

import requests

x = requests.post('https://uat-merchants-url', payload)

after that, you will get a response from that request and you can analyze it by print the value of x

print(x)

In payload, you already specified the redirect URL so it will automatically redirect to that URL defined in the payload dictionary

Thanks 

Avatar
Discard
Author

Hello Vishal Thacker !

Thank you for reply..

I have post data using POST..

It give me <Response [200]>..but it is not redirecting to the URL.

Hello Yaseen

You will need to add the following line at the end of the function to redirect on a particular page

eg: The below line will redirect on home page

return request.redirect("/")

Author

HI Vishal Thacker,

I am using same method, it is redirecting to the desired URL but not working, mean we we cant access the url,

Here is complete controller,

@http.route('/payment/gateway/nift/post', type='http', auth='public', website=True)

def payment_gateway_nift_post_request(self, **kw):

post_url = "https://uat-merchants.niftepay.pk/CustomerPortal/transactionmanagement/merchantform"

now = datetime.now()

year = now.strftime("%Y")

month = now.strftime("%m")

day = now.strftime("%d")

hour = now.strftime("%H")

minutes = now.strftime("%M")

seconds = now.strftime("%S")

date_start_str = str(year) + str(month) + str(day) + str(hour) + str(minutes) + str(seconds)

due_date = datetime.now() + timedelta(days=5)

due_year = due_date.strftime("%Y")

due_month = due_date.strftime("%m")

due_days = due_date.strftime("%d")

due_hours = due_date.strftime("%H")

due_minutes = due_date.strftime("%M")

due_seconds = due_date.strftime("%S")

due_date_str = str(due_year) + str(due_month) + str(due_days) + str(due_hours) + str(due_minutes) + str(due_seconds)

payload = {

'pp_Version': 1.1,

'pp_Language': 'EN',

'pp_MerchantID': 'dibban',

'pp_SubMerchantID': 'DIBsub',

'pp_Password': '56Fnsk/qjBQ=',

'pp_TxnRefNo': 'Hx2020121022',

'pp_Amount': 10000,

'pp_TxnCurrency': 'PKR',

'pp_TxnDateTime': date_start_str,

'pp_BillReference': 'Cart0015',

'pp_Description': 'Description',

'pp_TxnExpiryDateTime': due_date_str,

'pp_ReturnURL': 'http://emsdev.odoo-hx.com/api/paymentgateway/nift',

'pp_SecureHash': '5fab8dcbd2d78508b8c3d9ea41ae7c16bd6e92ceddec04e2323be3c5b9086c74'

}

payment_response = requests.post(post_url, data=json.dumps(payload))

return request.redirect(post_url)