def get_transaction_status(order_identifier): paytm_params = {} paytm_checksum_params = {} url = "" paytm_mode = get_settings()['paytm_mode'] merchant_id = (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test' else get_settings()['paytm_live_merchant']) paytm_checksum_params["body"] = { "mid": merchant_id, "orderId": order_identifier } checksum = PaytmPaymentsManager.generate_checksum(paytm_checksum_params) paytm_params["MID"] = merchant_id paytm_params["ORDERID"] = order_identifier paytm_params["CHECKSUMHASH"] = checksum post_data = json.dumps(paytm_params) if paytm_mode == 'test': url = "https://securegw-stage.paytm.in/order/status" else: url = "https://securegw.paytm.in/order/status" response = requests.post(url, data=post_data, headers={ "Content-type": "application/json" }).json() return response
def process_transaction(order_identifier, txn_token): paytm_mode = get_settings()['paytm_mode'] merchant_id = (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test' else get_settings()['paytm_live_merchant']) if paytm_mode == 'test': url = "https://securegw-stage.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}".format( get_settings()['paytm_sandbox_merchant'], order_identifier) else: url = "https://securegw.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}".format( get_settings()['paytm_live_merchant'], order_identifier) head = { "version": "v1", "requestTimestamp": str(int(time.time())), "channelId": "WEB", "txnToken": txn_token, } body = { "requestType": "NATIVE", "mid": merchant_id, "orderId": order_identifier, "paymentMode": "BALANCE", } response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head, body=body) return response
def fetch_payment_options(order_identifier, txn_token): paytm_mode = get_settings()['paytm_mode'] if paytm_mode == 'test': url = "https://securegw-stage.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}".format( get_settings()['paytm_sandbox_merchant'], order_identifier) else: url = "https://securegw.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}".format( get_settings()['paytm_live_merchant'], order_identifier) head = { "clientId": "C11", "version": "v1", "requestTimestamp": str(int(time.time())), "channelId": "WEB", "txnToken": txn_token, } response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head) return response
def validate_otp(order_identifier, txn_token): paytm_mode = get_settings()['paytm_mode'] if paytm_mode == 'test': url = "https://securegw-stage.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}".\ format(get_settings()['paytm_sandbox_merchant'], order_identifier) else: url = "https://securegw.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}".\ format(get_settings()['paytm_live_merchant'], order_identifier) head = { "clientId": "C11", "version": "v1", "requestTimestamp": str(int(time.time())), "channelId": "WEB", "txnToken": txn_token } body = {"otp": request.json['data']['otp']} response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head, body=body) return response
def initiate_transaction(order_identifier): """ Initiating a PayTM transaction to obtain the txn token :param order_identifier: :return: JSON response containing the signature & txn token """ order = safe_query(Order, 'identifier', order_identifier, 'identifier') paytm_mode = get_settings()['paytm_mode'] paytm_params = {} # body parameters paytm_params["body"] = { "requestType": "Payment", "mid": ( get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test' else get_settings()['paytm_live_merchant'] ), "websiteName": "eventyay", "orderId": order_identifier, "callbackUrl": "", "txnAmount": { "value": order.amount, "currency": "INR", }, "userInfo": { "custId": order.user.id, }, } checksum = PaytmPaymentsManager.generate_checksum(paytm_params) # head parameters paytm_params["head"] = {"signature": checksum} post_data = json.dumps(paytm_params) if paytm_mode == 'test': url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}".format( get_settings()['paytm_sandbox_merchant'], order_identifier ) else: url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}".format( get_settings()['paytm_live_merchant'], order_identifier ) response = requests.post( url, data=post_data, headers={"Content-type": "application/json"} ) return response.json()