Skip to content

Commit

Permalink
Added url method paytm
Browse files Browse the repository at this point in the history
Finalized fetch payment options

Tested all endpoints for responses
  • Loading branch information
mrsaicharan1 committed Aug 20, 2019
1 parent c420b2c commit 5b655c5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 54 deletions.
13 changes: 7 additions & 6 deletions app/api/helpers/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,17 @@ class PaytmPaymentsManager(object):
Class to manage PayTM payments
"""

@staticmethod
@property
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
121 changes: 73 additions & 48 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,90 +645,115 @@ 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>')
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 = url + "login/sendOtp?mid=" + get_settings()['paytm_sandbox_merchant'] + "&orderId=" + order_identifier
paytmParams["head"] = {
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/send_otp/<string:txn_token>', methods=['POST', 'GET'])
def send_otp(order_identifier, txn_token):
paytm_params = {}
paytm_params["body"] = {"mobileNumber" : "9849065497"}
paytm_mode = get_settings()['paytm_mode']
if paytm_mode == 'test':
url = "https://securegw-stage.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}".\
format(get_settings()['paytm_sandbox_merchant'], order_identifier)
else:
url = "https://securegw.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}".\
format(get_settings()['paytm_live_merchant'], order_identifier)

paytm_params["head"] = {
"clientId" : "C11",
"version" : "v1",
"requestTimestamp" : str(int(time.time())),
"channelId" : "WEB",
"txnToken" : txnToken
"txnToken" : txn_token
}
post_data = json.dumps(paytmParams)
response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
post_data = json.dumps(paytm_params)
response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"})
return response.json()


@order_misc_routes.route('/orders/<string:order_identifier>/paytm/validate-otp/<string:txn_token>')
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 = url + "login/validateOtp?mid=" + get_settings()['paytm_sandbox_merchant'] + "&orderId=" + order_identifier
paytmParams["head"] = {
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/validate_otp/<string:txn_token>')
def validate_otp(order_identifier, txn_token):
paytm_params = dict()
paytm_params["body"] = {"otp" : "695249"}
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)
paytm_params["head"] = {
"clientId" : "C11",
"version" : "v1",
"requestTimestamp" : str(int(time.time())),
"channelId" : "WEB",
"txnToken" : txnToken
"txnToken" : txn_token
}
post_data = json.dumps(paytmParams)
response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()

post_data = json.dumps(paytm_params)
response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"})
return response.json()

@order_misc_routes.route('/orders/<string:order_identifier>/paytm/validate-otp/<string:txn_token>')
def process_transaction():
paytmParams = dict()

paytmParams["body"] = {
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/process_transaction/<string:txn_token>')
def process_transaction(order_identifier, txn_token):
paytm_params = dict()
paytm_mode = get_settings()['paytm_mode']
merchant_id = (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test'
else get_settings()['paytm_live_merchant'])
paytm_params["body"] = {
"requestType" : "NATIVE",
"mid" : get_settings()['paytm_sandbox_merchant'],
"orderId" : orderId,
"mid" : merchant_id,
"orderId" : order_identifier,
"paymentMode" : "BALANCE",
}

# url = "https://securegw-stage.paytm.in/theia/api/v1/" # for staging
url = "https://securegw.paytm.in/theia/api/v1/" # for production
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)

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

paytmParams["head"] = {
paytm_params["head"] = {
"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

0 comments on commit 5b655c5

Please sign in to comment.