소스 검색

feat: added webhook hmac verification

pull/2/head
Shivam Mishra 5 년 전
부모
커밋
e98b30ea36
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. +24
    -0
      payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py

+ 24
- 0
payments/payment_gateways/doctype/razorpay_settings/razorpay_settings.py 파일 보기

@@ -64,6 +64,9 @@ from __future__ import unicode_literals
import frappe
from frappe import _
import json
import hmac
import sys
import hashlib
from six.moves.urllib.parse import urlencode
from frappe.model.document import Document
from frappe.utils import get_url, call_hook_method, cint, get_timestamp
@@ -317,6 +320,27 @@ class RazorpaySettings(Document):
except Exception:
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):
"""
Verifies the purchase as complete by the merchant.


불러오는 중...
취소
저장