ソースを参照

fix: initiate payment via standard checkout

pull/2/head
Mangesh-Khairnar 5年前
コミット
a4f54c9ea5
2個のファイルの変更32行の追加91行の削除
  1. +27
    -18
      payments/templates/pages/paytm_checkout.html
  2. +5
    -73
      payments/templates/pages/paytm_checkout.py

+ 27
- 18
payments/templates/pages/paytm_checkout.html ファイルの表示

@@ -1,26 +1,35 @@
{% extends "templates/web.html" %} {% block title %} Payment {% endblock %} {%-
block header -%}{% endblock %} {% block script %}
<script defer
type="application/javascript"
crossorigin="anonymous"
src="{{ host }}/merchantpgpui/checkoutjs/merchants/{{ mid }}.js"
onload="onScriptLoad();"
></script>
<script>
{% include "/templates/includes/integrations/paytm_checkout.js" %}
{% extends "templates/web.html" %}

{% block title %} Payment {% endblock %}

{%- block header -%}
<head>
<title>Merchant Checkout Page</title>
</head>
{% endblock %}

{% block script %}
<script defer type="text/javascript">
document.paytm_form.submit();
</script>
{% endblock %} {%- block page_content -%}
<div id="paytm-checkoutjs"></div>
<p class="lead text-center centered">
<span class="paytm-loading">Loading Payment System</span>
<span class="paytm-confirming hidden">Confirming Payment</span>
</p>
{% endblock %}

{%- block page_content -%}
<body>
<center><h1>Please do not refresh this page...</h1></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>
</body>
{% endblock %}

{% endblock %} {% block style %}
{% block style %}
<style>
/* header,
footer {
display: none;
} */
</style>
{% endblock %}
{% endblock %}

+ 5
- 73
payments/templates/pages/paytm_checkout.py ファイルの表示

@@ -6,8 +6,8 @@ from frappe import _
from frappe.utils import flt, cint
import json
from six import string_types
from frappe.integrations.doctype.paytm_settings.checksum import generate_checksum_by_str
from frappe.utils import get_request_site_address
from frappe.integrations.doctype.paytm_settings.paytm_settings import get_paytm_params, get_paytm_config
import requests

no_cache = 1
@@ -17,21 +17,15 @@ expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'referen

def get_context(context):
context.no_cache = 1
merchant_id, merchant_key = get_paytm_credentials()
paytm_config = get_paytm_config()

try:
doc = frappe.get_doc("Integration Request", frappe.form_dict['order_id'])
payment_details = json.loads(doc.data)
context.token = generate_transaction_token(payment_details, doc.name, merchant_id, merchant_key)
context.order_id = doc.name

context.payment_details = get_paytm_params(json.loads(doc.data), doc.name, paytm_config)

for key in expected_keys:
context[key] = payment_details[key]

context['amount'] = flt(context['amount'], 2)
context.host = 'https://securegw-stage.paytm.in'
context.mid = merchant_id
context.url = paytm_config.url

except Exception as e:
frappe.log_error()
@@ -40,66 +34,4 @@ def get_context(context):
http_status_code=400, indicator_color='red')

frappe.local.flags.redirect_location = frappe.local.response.location
raise frappe.Redirect

def get_paytm_credentials():
return frappe.db.get_value("Paytm Settings", None, ['merchant_id', 'merchant_key'])

@frappe.whitelist(allow_guest=True)
def make_payment(paytm_payment_id, options, reference_doctype, reference_docname, token):
data = {}

if isinstance(options, string_types):
data = json.loads(options)

data.update({
"paytm_payment_id": paytm_payment_id,
"reference_docname": reference_docname,
"reference_doctype": reference_doctype,
"token": token
})

data = frappe.get_doc("Paytm Settings").create_request(data)
frappe.db.commit()
return data

def generate_transaction_token(payment_details, order_id, merchant_id, merchant_key):

# initialize a dictionary
paytmParams = dict()

redirect_uri = get_request_site_address(True) + "?cmd=frappe.templates.pages.integrations.paytm_checkout.get_transaction_status"

# body parameters
paytmParams["body"] = {
"requestType" : "Payment",
"mid" : merchant_id,
"websiteName" : "WEBSTAGING",
"orderId" : order_id,
"callbackUrl" : redirect_uri,
"txnAmount" : {
"value" : flt(payment_details['amount'], 2),
"currency" : "INR",
},
"userInfo" : {
"custId" : payment_details['payer_email'],
},
}

checksum = generate_checksum_by_str(json.dumps(paytmParams["body"]), merchant_key)

paytmParams["head"] = {
"signature" : checksum
}

print(paytmParams)
post_data = json.dumps(paytmParams)

url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={0}&orderId={1}".format(merchant_id, order_id)

response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
return response['body'].get('txnToken')

@frappe.whitelist(allow_guest=True)
def get_transaction_status():
print(vars(frappe.form_dict))
raise frappe.Redirect

読み込み中…
キャンセル
保存