fix: add finalize request to complete the transaction
This commit is contained in:
parent
5d4c5c56d6
commit
6eaefb35c7
5 changed files with 22 additions and 80 deletions
|
|
@ -71,8 +71,8 @@ def get_paytm_params(payment_details, order_id, paytm_config):
|
|||
# initialize a dictionary
|
||||
paytm_params = dict()
|
||||
|
||||
# redirect_uri = get_request_site_address(True) + "/api/method/frappe.integrations.doctype.paytm_settings.paytm_settings.get_transaction_status"
|
||||
redirect_uri = "http://cf9b2bb1.ngrok.io/api/method/frappe.integrations.doctype.paytm_settings.paytm_settings.get_transaction_status"
|
||||
redirect_uri = get_request_site_address(True) + "/api/method/frappe.integrations.doctype.paytm_settings.paytm_settings.verify_transaction"
|
||||
|
||||
|
||||
paytm_params.update({
|
||||
"MID" : paytm_config.merchant_id,
|
||||
|
|
@ -99,24 +99,28 @@ def verify_transaction(**kwargs):
|
|||
'''Verify checksum for received data in the callback and then verify the transaction'''
|
||||
paytm_config = get_paytm_config()
|
||||
received_data = frappe._dict(kwargs)
|
||||
is_valid_checksum = False
|
||||
|
||||
paytm_params = {}
|
||||
for key, value in received_data.items():
|
||||
if key == 'CHECKSUMHASH':
|
||||
paytm_checksum = value
|
||||
elif key == 'cmd':
|
||||
continue
|
||||
else:
|
||||
paytm_params[key] = value
|
||||
|
||||
# Verify checksum
|
||||
is_valid_checksum = verify_checksum(paytm_params, paytm_config.merchant_key, paytm_checksum)
|
||||
if paytm_params and paytm_config and paytm_checksum:
|
||||
# Verify checksum
|
||||
is_valid_checksum = verify_checksum(paytm_params, paytm_config.merchant_key, paytm_checksum)
|
||||
|
||||
if is_valid_checksum and received_data['RESPCODE'] == '01':
|
||||
verify_transaction_status(paytm_config, received_data['ORDERID'])
|
||||
else:
|
||||
frappe.respond_as_web_page("Payment Failed",
|
||||
"Transaction failed to complete. Don't worry, in case of failure amount will get refunded to your account.",
|
||||
"Transaction failed to complete. In case of any deductions, deducted amount will get refunded to your account.",
|
||||
http_status_code=401, indicator_color='red')
|
||||
frappe.log_error("Order unsuccessful, received data:"+received_data, 'Paytm Payment Failed')
|
||||
frappe.log_error("Order unsuccessful. Failed Response:"+cstr(received_data), 'Paytm Payment Failed')
|
||||
|
||||
def verify_transaction_status(paytm_config, order_id):
|
||||
'''Verify transaction completion after checksum has been verified'''
|
||||
|
|
@ -136,15 +140,16 @@ def verify_transaction_status(paytm_config, order_id):
|
|||
|
||||
def finalize_request(order_id, transaction_response):
|
||||
request = frappe.get_doc('Integration Request', order_id)
|
||||
redirect_to = request.data.get('redirect_to') or None
|
||||
redirect_message = request.data.get('redirect_message') or None
|
||||
transaction_data = frappe._dict(json.loads(request.data))
|
||||
redirect_to = transaction_data.get('redirect_to') or None
|
||||
redirect_message = transaction_data.get('redirect_message') or None
|
||||
|
||||
if transaction_response['STATUS'] == "TXN_SUCCESS":
|
||||
if request.data.reference_doctype and request.data.reference_docname:
|
||||
if transaction_data.reference_doctype and transaction_data.reference_docname:
|
||||
custom_redirect_to = None
|
||||
try:
|
||||
custom_redirect_to = frappe.get_doc(request.data.reference_doctype,
|
||||
request.data.reference_docname).run_method("on_payment_authorized", 'Completed')
|
||||
custom_redirect_to = frappe.get_doc(transaction_data.reference_doctype,
|
||||
transaction_data.reference_docname).run_method("on_payment_authorized", 'Completed')
|
||||
request.db_set('status', 'Completed')
|
||||
except Exception:
|
||||
request.db_set('status', 'Failed')
|
||||
|
|
@ -153,10 +158,10 @@ def finalize_request(order_id, transaction_response):
|
|||
if custom_redirect_to:
|
||||
redirect_to = custom_redirect_to
|
||||
|
||||
redirect_url = 'payment-success'
|
||||
redirect_url = '/integrations/payment-success'
|
||||
else:
|
||||
request.db_set('status', 'Failed')
|
||||
redirect_url = 'payment-failed'
|
||||
redirect_url = '/integrations/payment-failed'
|
||||
|
||||
if redirect_to:
|
||||
redirect_url += '?' + urlencode({'redirect_to': redirect_to})
|
||||
|
|
@ -164,7 +169,7 @@ def finalize_request(order_id, transaction_response):
|
|||
redirect_url += '&' + urlencode({'redirect_message': redirect_message})
|
||||
|
||||
frappe.local.response['type'] = 'redirect'
|
||||
frappe.local.response['location'] = 'redirect_url'
|
||||
frappe.local.response['location'] = redirect_url
|
||||
|
||||
def get_gateway_controller(doctype, docname):
|
||||
reference_doc = frappe.get_doc(doctype, docname)
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
function onScriptLoad() {
|
||||
console.log('inside on load')
|
||||
var config = {
|
||||
root: '',
|
||||
flow: 'DEFAULT',
|
||||
data: {
|
||||
orderId: '{{ order_id}}',
|
||||
token: '{{ token }}',
|
||||
tokenType: 'TXN_TOKEN',
|
||||
amount: '{{ amount }}'
|
||||
},
|
||||
handler: {
|
||||
notifyMerchant: function(eventName, data) {
|
||||
// notify about the state of the payment page ( invalid token , session expire , cancel transaction)
|
||||
console.log('notifyMerchant handler function called');
|
||||
console.log('eventName => ', eventName);
|
||||
console.log('data => ', data);
|
||||
},
|
||||
transactionStatus: function transactionStatus(paymentStatus) {
|
||||
// provide information to merchant about the payment status.
|
||||
console.log('transaction status handler function called');
|
||||
console.log('paymentStatus => ', paymentStatus);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$('.paytm-loading').addClass('hidden');
|
||||
if (window.Paytm && window.Paytm.CheckoutJS) {
|
||||
window.Paytm.CheckoutJS.onLoad(function excecuteAfterCompleteLoad() {
|
||||
// initialze configuration using init method
|
||||
window.Paytm.CheckoutJS.init(config)
|
||||
.then(function onSuccess() {
|
||||
// after successfully updating configuration, invoke Blink Checkout
|
||||
window.Paytm.CheckoutJS.invoke();
|
||||
})
|
||||
.catch(function onError(error) {
|
||||
console.log('inside the error window')
|
||||
console.log('error => ', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -16,12 +16,14 @@
|
|||
|
||||
{%- block page_content -%}
|
||||
<body>
|
||||
<center><h1>Please do not refresh this page...</h1></center>
|
||||
<div style="margin: 30vh;">
|
||||
<center><h2>Please do not refresh this page...</h2></center>
|
||||
<form method="post" action="{{ url }}" name="paytm_form">
|
||||
{% for name, value in payment_details.items() %}
|
||||
<input type="hidden" name="{{ name }}" value="{{ value }}">
|
||||
{% endfor %}
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ import requests
|
|||
|
||||
no_cache = 1
|
||||
|
||||
expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'reference_docname',
|
||||
'payer_name', 'payer_email')
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
paytm_config = get_paytm_config()
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"button_gradients": 0,
|
||||
"button_rounded_corners": 1,
|
||||
"button_shadows": 0,
|
||||
"creation": "2015-02-19 13:37:33.925909",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Website Theme",
|
||||
"font_properties": "300,600",
|
||||
"font_size": "",
|
||||
"idx": 27,
|
||||
"modified": "2020-04-21 02:10:31.761219",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Standard",
|
||||
"owner": "Administrator",
|
||||
"theme": "Standard",
|
||||
"theme_scss": "$enable-shadows: false;\n$enable-gradients: false;\n$enable-rounded: true;\n\n@import \"frappe/public/scss/website\";\n\n",
|
||||
"theme_url": "/assets/css/standard_style.css"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue