|
@@ -64,6 +64,9 @@ from __future__ import unicode_literals |
|
|
import frappe |
|
|
import frappe |
|
|
from frappe import _ |
|
|
from frappe import _ |
|
|
import json |
|
|
import json |
|
|
|
|
|
import hmac |
|
|
|
|
|
import sys |
|
|
|
|
|
import hashlib |
|
|
from six.moves.urllib.parse import urlencode |
|
|
from six.moves.urllib.parse import urlencode |
|
|
from frappe.model.document import Document |
|
|
from frappe.model.document import Document |
|
|
from frappe.utils import get_url, call_hook_method, cint, get_timestamp |
|
|
from frappe.utils import get_url, call_hook_method, cint, get_timestamp |
|
@@ -317,6 +320,27 @@ class RazorpaySettings(Document): |
|
|
except Exception: |
|
|
except Exception: |
|
|
frappe.log_error(frappe.get_traceback()) |
|
|
frappe.log_error(frappe.get_traceback()) |
|
|
|
|
|
|
|
|
|
|
|
def verify_signature(self, body, signature, key): |
|
|
|
|
|
if sys.version_info[0] == 3: |
|
|
|
|
|
key = bytes(key, 'utf-8') |
|
|
|
|
|
body = bytes(body, 'utf-8') |
|
|
|
|
|
|
|
|
|
|
|
dig = hmac.new(key=key, |
|
|
|
|
|
msg=body, |
|
|
|
|
|
digestmod=hashlib.sha256) |
|
|
|
|
|
|
|
|
|
|
|
generated_signature = dig.hexdigest() |
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info[0:3] < (2, 7, 7): |
|
|
|
|
|
result = self.compare_string(generated_signature, signature) |
|
|
|
|
|
else: |
|
|
|
|
|
result = hmac.compare_digest(generated_signature, signature) |
|
|
|
|
|
|
|
|
|
|
|
if not result: |
|
|
|
|
|
frappe.throw(_('Razorpay Signature Verification Failed'), exc=frappe.PermissionError) |
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
|
def capture_payment(is_sandbox=False, sanbox_response=None): |
|
|
def capture_payment(is_sandbox=False, sanbox_response=None): |
|
|
""" |
|
|
""" |
|
|
Verifies the purchase as complete by the merchant. |
|
|
Verifies the purchase as complete by the merchant. |
|
|