11import logging
22import json
33import pytz
4- from datetime import datetime
4+ import time
5+ import omise
56import requests
67
7-
8- import omise
8+ from datetime import datetime
99from flask import request , jsonify , Blueprint , url_for , redirect
1010from flask_jwt_extended import current_user
1111from flask_rest_jsonapi import ResourceDetail , ResourceList , ResourceRelationship
4141from app .models .ticket_holder import TicketHolder
4242from app .models .user import User
4343
44+
4445order_misc_routes = Blueprint ('order_misc' , __name__ , url_prefix = '/v1' )
4546alipay_blueprint = Blueprint ('alipay_blueprint' , __name__ , url_prefix = '/v1/alipay' )
4647
@@ -543,7 +544,6 @@ def create_paypal_payment(order_identifier):
543544 else :
544545 return jsonify (status = False , error = response )
545546
546-
547547@order_misc_routes .route ('/orders/<string:order_identifier>/verify-mobile-paypal-payment' , methods = ['POST' ])
548548@jwt_required
549549def verify_mobile_paypal_payment (order_identifier ):
@@ -629,6 +629,7 @@ def omise_checkout(order_identifier):
629629
630630
631631@order_misc_routes .route ('/orders/<string:order_identifier>/paytm/initiate-transaction' , methods = ['POST' , 'GET' ])
632+ @jwt_required
632633def initiate_transaction (order_identifier ):
633634 """
634635 Initiating a PayTM transaction to obtain the txn token
@@ -641,14 +642,14 @@ def initiate_transaction(order_identifier):
641642 # body parameters
642643 paytm_params ["body" ] = {
643644 "requestType" : "Payment" ,
644- "mid" : (get_settings ()['paytm_sandbox_merchant' ] if paytm_mode == 'sandbox '
645+ "mid" : (get_settings ()['paytm_sandbox_merchant' ] if paytm_mode == 'test '
645646 else get_settings ()['paytm_live_merchant' ]),
646647 "websiteName" : "eventyay" ,
647- "orderId" : order . id ,
648+ "orderId" : order_identifier ,
648649 "callbackUrl" : "" ,
649650 "txnAmount" : {
650651 "value" : order .amount ,
651- "currency" : order . event . payment_currency ,
652+ "currency" : "INR" ,
652653 },
653654 "userInfo" : {
654655 "custId" : order .user .id ,
@@ -660,11 +661,108 @@ def initiate_transaction(order_identifier):
660661 "signature" : checksum
661662 }
662663 post_data = json .dumps (paytm_params )
663- if paytm_mode == 'sandbox ' :
664+ if paytm_mode == 'test ' :
664665 url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}" .\
665- format (get_settings ()['paytm_sandbox_merchant' ], order . id )
666+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
666667 else :
667668 url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}" .\
668- format (get_settings ()['paytm_sandbox_merchant ' ], order . id )
669+ format (get_settings ()['paytm_live_merchant ' ], order_identifier )
669670 response = requests .post (url , data = post_data , headers = {"Content-type" : "application/json" })
670671 return response .json ()
672+
673+
674+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/fetch-payment-options/<string:txn_token>' )
675+ @jwt_required
676+ def fetch_payment_options (order_identifier , txn_token ):
677+ paytm_mode = get_settings ()['paytm_mode' ]
678+ if paytm_mode == 'test' :
679+ url = "https://securegw-stage.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}" .\
680+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
681+ else :
682+ url = "https://securegw.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}" .\
683+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
684+ head = {
685+ "clientId" : "C11" ,
686+ "version" : "v1" ,
687+ "requestTimestamp" : str (int (time .time ())),
688+ "channelId" : "WEB" ,
689+ "txnToken" : txn_token
690+ }
691+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head )
692+ return response
693+
694+
695+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/send_otp/<string:txn_token>' , methods = ['POST' ])
696+ @jwt_required
697+ def send_otp (order_identifier , txn_token ):
698+ paytm_mode = get_settings ()['paytm_mode' ]
699+ if paytm_mode == 'test' :
700+ url = "https://securegw-stage.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}" .\
701+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
702+ else :
703+ url = "https://securegw.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}" .\
704+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
705+
706+ head = {
707+ "clientId" : "C11" ,
708+ "version" : "v1" ,
709+ "requestTimestamp" : str (int (time .time ())),
710+ "channelId" : "WEB" ,
711+ "txnToken" : txn_token
712+ }
713+ body = {"mobileNumber" : request .json ['data' ]['phone' ]}
714+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
715+ return response
716+
717+
718+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/validate_otp/<string:txn_token>' , methods = ['POST' ])
719+ def validate_otp (order_identifier , txn_token ):
720+ paytm_mode = get_settings ()['paytm_mode' ]
721+ if paytm_mode == 'test' :
722+ url = "https://securegw-stage.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}" .\
723+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
724+ else :
725+ url = "https://securegw.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}" .\
726+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
727+ head = {
728+ "clientId" : "C11" ,
729+ "version" : "v1" ,
730+ "requestTimestamp" : str (int (time .time ())),
731+ "channelId" : "WEB" ,
732+ "txnToken" : txn_token
733+ }
734+ body = {"otp" : request .json ['data' ]['otp' ]}
735+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
736+ return response
737+
738+
739+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/process_transaction/<string:txn_token>' )
740+ @jwt_required
741+ def process_transaction (order_identifier , txn_token ):
742+ paytm_mode = get_settings ()['paytm_mode' ]
743+ merchant_id = (get_settings ()['paytm_sandbox_merchant' ] if paytm_mode == 'test'
744+ else get_settings ()['paytm_live_merchant' ])
745+
746+ if paytm_mode == 'test' :
747+ url = "https://securegw-stage.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}" .\
748+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
749+ else :
750+ url = "https://securegw.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}" .\
751+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
752+
753+ head = {
754+ "version" : "v1" ,
755+ "requestTimestamp" : str (int (time .time ())),
756+ "channelId" : "WEB" ,
757+ "txnToken" : txn_token
758+ }
759+
760+ body = {
761+ "requestType" : "NATIVE" ,
762+ "mid" : merchant_id ,
763+ "orderId" : order_identifier ,
764+ "paymentMode" : "BALANCE"
765+ }
766+
767+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
768+ return response
0 commit comments