Skip to content

Commit

Permalink
Added url method paytm
Browse files Browse the repository at this point in the history
Finalized fetch payment options
  • Loading branch information
mrsaicharan1 committed Aug 20, 2019
1 parent c420b2c commit 9ed5a0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
11 changes: 6 additions & 5 deletions app/api/helpers/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,15 @@ class PaytmPaymentsManager(object):

@staticmethod
def paytm_endpoint():
if get_settings()['paytm_mode'] == 'sandbox':
mid = get_settings()['paytm_sandbox_merchant']
if get_settings()['paytm_mode'] == 'test':
url = "https://securegw-stage.paytm.in/theia/api/v1/" # for staging
else:
mid = get_settings()['paytm_live_merchant']
return mid
url = "https://securegw.paytm.in/theia/api/v1/" # for production
return url

@staticmethod
def generate_checksum(paytm_params):
if get_settings()['paytm_mode'] == 'sandbox':
if get_settings()['paytm_mode'] == 'test':
merchant_key = get_settings()['paytm_sandbox_secret']
else:
merchant_key = get_settings()['paytm_live_secret']
Expand Down
44 changes: 24 additions & 20 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,14 @@ def initiate_transaction(order_identifier):
# body parameters
paytm_params["body"] = {
"requestType": "Payment",
"mid": (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'sandbox'
"mid": (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test'
else get_settings()['paytm_live_merchant']),
"websiteName": "eventyay",
"orderId": order.id,
"orderId": order_identifier,
"callbackUrl": "",
"txnAmount": {
"value": order.amount,
"currency": order.event.payment_currency,
"currency": "INR",
},
"userInfo": {
"custId": order.user.id,
Expand All @@ -645,37 +645,43 @@ def initiate_transaction(order_identifier):
"signature" : checksum
}
post_data = json.dumps(paytm_params)
if paytm_mode == 'sandbox':
if paytm_mode == 'test':
url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}".\
format(get_settings()['paytm_sandbox_merchant'], order.id)
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.id)
return url
format(get_settings()['paytm_live_merchant'], order_identifier)
response = requests.post(url, data=post_data, headers={"Content-type": "application/json"})
return response.json()


@order_misc_routes.route('/orders/<string:order_identifier>/paytm/fetch-payment-options/<string:txn_token>')
def fetch_payment_options(txn_token):
url = "https://securegw-stage.paytm.in/theia/api/v1/"
url = PaytmPaymentsManager.paytm_api_uri + "fetchPaymentOptions?mid=" + get_settings()['paytm_sandbox_merchant'] + "&orderId=" + order_identifier
paytmParams["head"] = {
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)
paytm_params = {}
paytm_params["head"] = {
"clientId" : "C11",
"version" : "v1",
"requestTimestamp" : str(int(time.time())),
"channelId" : "WEB",
"txnToken" : txnToken
"txnToken" : txn_token
}
post_data = json.dumps(paytmParams)
post_data = json.dumps(paytm_params)
response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
return response


@order_misc_routes.route('/orders/<string:order_identifier>/paytm/send-otp/<string:txn_token>')
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/send-otp/<string:txn_token>', methods=['POST', 'GET'])
def send_otp():
paytmParams = dict()
paytmParams["body"] = {"mobileNumber" : "9968599840"}
url = "https://securegw-stage.paytm.in/theia/api/v1/" # for staging
# url = "https://securegw.paytm.in/theia/api/v1/" # for production
url = PaytmPaymentsManager.paytm_endpoint
url = url + "login/sendOtp?mid=" + get_settings()['paytm_sandbox_merchant'] + "&orderId=" + order_identifier
paytmParams["head"] = {
"clientId" : "C11",
Expand All @@ -692,8 +698,7 @@ def send_otp():
def validate_otp():
paytmParams = dict()
paytmParams["body"] = {"otp" : "348572"}
url = "https://securegw-stage.paytm.in/theia/api/v1/" # for staging
# url = "https://securegw.paytm.in/theia/api/v1/" # for production
url = PaytmPaymentsManager.paytm_endpoint
url = url + "login/validateOtp?mid=" + get_settings()['paytm_sandbox_merchant'] + "&orderId=" + order_identifier
paytmParams["head"] = {
"clientId" : "C11",
Expand All @@ -717,8 +722,7 @@ def process_transaction():
"paymentMode" : "BALANCE",
}

# url = "https://securegw-stage.paytm.in/theia/api/v1/" # for staging
url = "https://securegw.paytm.in/theia/api/v1/" # for production
url = PaytmPaymentsManager.paytm_endpoint

url = url + "processTransaction?mid=" + get_settings()['paytm_sandbox_merchant'] + "&orderId=" + order_identifier

Expand Down

0 comments on commit 9ed5a0f

Please sign in to comment.