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
@@ -544,22 +545,6 @@ def create_paypal_payment(order_identifier):
544545        return  jsonify (status = False , error = response )
545546
546547
547- @order_misc_routes .route ('/orders/<string:order_identifier>/verify-mobile-paypal-payment' , methods = ['POST' ]) 
548- @jwt_required  
549- def  verify_mobile_paypal_payment (order_identifier ):
550-     """ 
551-     Verify paypal payment made on mobile client 
552-     :return: The status of order verification 
553-     """ 
554-     try :
555-         payment_id  =  request .json ['data' ]['attributes' ]['payment-id' ]
556-     except  TypeError :
557-         return  BadRequestError ({'source' : '' }, 'Bad Request Error' ).respond ()
558-     order  =  safe_query (db , Order , 'identifier' , order_identifier , 'identifier' )
559-     status , error  =  PayPalPaymentsManager .verify_payment (payment_id , order )
560-     return  jsonify (status = status , error = error )
561- 
562- 
563548@alipay_blueprint .route ('/create_source/<string:order_identifier>' , methods = ['GET' , 'POST' ]) 
564549def  create_source (order_identifier ):
565550    """ 
@@ -641,14 +626,14 @@ def initiate_transaction(order_identifier):
641626    # body parameters 
642627    paytm_params ["body" ] =  {
643628        "requestType" : "Payment" ,
644-         "mid" : (get_settings ()['paytm_sandbox_merchant' ] if  paytm_mode  ==  'sandbox ' 
629+         "mid" : (get_settings ()['paytm_sandbox_merchant' ] if  paytm_mode  ==  'test ' 
645630                else  get_settings ()['paytm_live_merchant' ]),
646631        "websiteName" : "eventyay" ,
647-         "orderId" : order . id ,
632+         "orderId" : order_identifier ,
648633        "callbackUrl" : "" ,
649634        "txnAmount" : {
650635            "value" : order .amount ,
651-             "currency" : order . event . payment_currency ,
636+             "currency" : "INR" ,
652637        },
653638        "userInfo" : {
654639            "custId" : order .user .id ,
@@ -660,11 +645,105 @@ def initiate_transaction(order_identifier):
660645        "signature" 	: checksum 
661646    }
662647    post_data  =  json .dumps (paytm_params )
663-     if  paytm_mode  ==  'sandbox ' :
648+     if  paytm_mode  ==  'test ' :
664649        url  =  "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}" .\
665-                format (get_settings ()['paytm_sandbox_merchant' ], order . id )
650+             format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
666651    else :
667652        url  =  "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}" .\
668-                format (get_settings ()['paytm_sandbox_merchant ' ], order . id )
653+             format (get_settings ()['paytm_live_merchant ' ], order_identifier )
669654    response  =  requests .post (url , data = post_data , headers = {"Content-type" : "application/json" })
670655    return  response .json ()
656+ 
657+ 
658+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/fetch-payment-options/<string:txn_token>' ) 
659+ def  fetch_payment_options (order_identifier , txn_token ):
660+     paytm_mode  =  get_settings ()['paytm_mode' ]
661+     if  paytm_mode  ==  'test' :
662+         url  =  "https://securegw-stage.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}" .\
663+             format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
664+     else :
665+         url  =  "https://securegw.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}" .\
666+             format (get_settings ()['paytm_live_merchant' ], order_identifier )
667+     head  =  {
668+         "clientId" : "C11" ,
669+         "version" : "v1" ,
670+         "requestTimestamp" : str (int (time .time ())),
671+         "channelId" : "WEB" ,
672+         "txnToken" : txn_token 
673+     }
674+     response  =  PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head )
675+     return  response 
676+ 
677+ 
678+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/send_otp/<string:txn_token>' , methods = ['POST' , 'GET' ]) 
679+ def  send_otp (order_identifier , txn_token ):
680+     paytm_mode  =  get_settings ()['paytm_mode' ]
681+     if  paytm_mode  ==  'test' :
682+         url  =  "https://securegw-stage.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}" .\
683+             format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
684+     else :
685+         url  =  "https://securegw.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}" .\
686+             format (get_settings ()['paytm_live_merchant' ], order_identifier )
687+ 
688+     head  =  {
689+         "clientId" : "C11" ,
690+         "version" : "v1" ,
691+         "requestTimestamp" : str (int (time .time ())),
692+         "channelId" : "WEB" ,
693+         "txnToken" : txn_token 
694+     }
695+     body  =  {"mobileNumber" : "" }
696+     response  =  PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
697+     return  response 
698+ 
699+ 
700+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/validate_otp/<string:txn_token>' ) 
701+ def  validate_otp (order_identifier , txn_token ):
702+     paytm_mode  =  get_settings ()['paytm_mode' ]
703+     if  paytm_mode  ==  'test' :
704+         url  =  "https://securegw-stage.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}" .\
705+             format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
706+     else :
707+         url  =  "https://securegw.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}" .\
708+             format (get_settings ()['paytm_live_merchant' ], order_identifier )
709+     head  =  {
710+         "clientId" : "C11" ,
711+         "version" : "v1" ,
712+         "requestTimestamp" : str (int (time .time ())),
713+         "channelId" : "WEB" ,
714+         "txnToken" : txn_token 
715+     }
716+     body  =  {"otp" : "" }
717+     response  =  PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
718+     return  response 
719+ 
720+ 
721+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/process_transaction/<string:txn_token>' ) 
722+ def  process_transaction (order_identifier , txn_token ):
723+     paytm_mode  =  get_settings ()['paytm_mode' ]
724+     merchant_id  =  (get_settings ()['paytm_sandbox_merchant' ] if  paytm_mode  ==  'test' 
725+                    else  get_settings ()['paytm_live_merchant' ])
726+ 
727+     if  paytm_mode  ==  'test' :
728+         url  =  "https://securegw-stage.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}" .\
729+             format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
730+     else :
731+         url  =  "https://securegw.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}" .\
732+             format (get_settings ()['paytm_live_merchant' ], order_identifier )
733+ 
734+     head  =  {
735+         "version" : "v1" ,
736+         "requestTimestamp" : str (int (time .time ())),
737+         "channelId" : "WEB" ,
738+         "txnToken" : txn_token 
739+     }
740+ 
741+     body  =  {
742+         "requestType" : "NATIVE" ,
743+         "mid" : merchant_id ,
744+         "orderId" : order_identifier ,
745+         "paymentMode" : "BALANCE" 
746+     }
747+ 
748+     response  =  PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
749+     return  response 
0 commit comments