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,21 +544,20 @@ 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' ])
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 )
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 )
561561
562562
563563@alipay_blueprint .route ('/create_source/<string:order_identifier>' , methods = ['GET' , 'POST' ])
@@ -641,14 +641,14 @@ def initiate_transaction(order_identifier):
641641 # body parameters
642642 paytm_params ["body" ] = {
643643 "requestType" : "Payment" ,
644- "mid" : (get_settings ()['paytm_sandbox_merchant' ] if paytm_mode == 'sandbox '
644+ "mid" : (get_settings ()['paytm_sandbox_merchant' ] if paytm_mode == 'test '
645645 else get_settings ()['paytm_live_merchant' ]),
646646 "websiteName" : "eventyay" ,
647- "orderId" : order . id ,
647+ "orderId" : order_identifier ,
648648 "callbackUrl" : "" ,
649649 "txnAmount" : {
650650 "value" : order .amount ,
651- "currency" : order . event . payment_currency ,
651+ "currency" : "INR" ,
652652 },
653653 "userInfo" : {
654654 "custId" : order .user .id ,
@@ -660,11 +660,105 @@ def initiate_transaction(order_identifier):
660660 "signature" : checksum
661661 }
662662 post_data = json .dumps (paytm_params )
663- if paytm_mode == 'sandbox ' :
663+ if paytm_mode == 'test ' :
664664 url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}" .\
665- format (get_settings ()['paytm_sandbox_merchant' ], order . id )
665+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
666666 else :
667667 url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}" .\
668- format (get_settings ()['paytm_sandbox_merchant ' ], order . id )
668+ format (get_settings ()['paytm_live_merchant ' ], order_identifier )
669669 response = requests .post (url , data = post_data , headers = {"Content-type" : "application/json" })
670670 return response .json ()
671+
672+
673+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/fetch-payment-options/<string:txn_token>' )
674+ def fetch_payment_options (order_identifier , txn_token ):
675+ paytm_mode = get_settings ()['paytm_mode' ]
676+ if paytm_mode == 'test' :
677+ url = "https://securegw-stage.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}" .\
678+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
679+ else :
680+ url = "https://securegw.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}" .\
681+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
682+ head = {
683+ "clientId" : "C11" ,
684+ "version" : "v1" ,
685+ "requestTimestamp" : str (int (time .time ())),
686+ "channelId" : "WEB" ,
687+ "txnToken" : txn_token
688+ }
689+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head )
690+ return response
691+
692+
693+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/send_otp/<string:txn_token>' , methods = ['POST' , 'GET' ])
694+ def send_otp (order_identifier , txn_token ):
695+ paytm_mode = get_settings ()['paytm_mode' ]
696+ if paytm_mode == 'test' :
697+ url = "https://securegw-stage.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}" .\
698+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
699+ else :
700+ url = "https://securegw.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}" .\
701+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
702+
703+ head = {
704+ "clientId" : "C11" ,
705+ "version" : "v1" ,
706+ "requestTimestamp" : str (int (time .time ())),
707+ "channelId" : "WEB" ,
708+ "txnToken" : txn_token
709+ }
710+ body = {"mobileNumber" : "" }
711+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
712+ return response
713+
714+
715+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/validate_otp/<string:txn_token>' )
716+ def validate_otp (order_identifier , txn_token ):
717+ paytm_mode = get_settings ()['paytm_mode' ]
718+ if paytm_mode == 'test' :
719+ url = "https://securegw-stage.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}" .\
720+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
721+ else :
722+ url = "https://securegw.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}" .\
723+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
724+ head = {
725+ "clientId" : "C11" ,
726+ "version" : "v1" ,
727+ "requestTimestamp" : str (int (time .time ())),
728+ "channelId" : "WEB" ,
729+ "txnToken" : txn_token
730+ }
731+ body = {"otp" : "" }
732+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
733+ return response
734+
735+
736+ @order_misc_routes .route ('/orders/<string:order_identifier>/paytm/process_transaction/<string:txn_token>' )
737+ def process_transaction (order_identifier , txn_token ):
738+ paytm_mode = get_settings ()['paytm_mode' ]
739+ merchant_id = (get_settings ()['paytm_sandbox_merchant' ] if paytm_mode == 'test'
740+ else get_settings ()['paytm_live_merchant' ])
741+
742+ if paytm_mode == 'test' :
743+ url = "https://securegw-stage.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}" .\
744+ format (get_settings ()['paytm_sandbox_merchant' ], order_identifier )
745+ else :
746+ url = "https://securegw.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}" .\
747+ format (get_settings ()['paytm_live_merchant' ], order_identifier )
748+
749+ head = {
750+ "version" : "v1" ,
751+ "requestTimestamp" : str (int (time .time ())),
752+ "channelId" : "WEB" ,
753+ "txnToken" : txn_token
754+ }
755+
756+ body = {
757+ "requestType" : "NATIVE" ,
758+ "mid" : merchant_id ,
759+ "orderId" : order_identifier ,
760+ "paymentMode" : "BALANCE"
761+ }
762+
763+ response = PaytmPaymentsManager .hit_paytm_endpoint (url = url , head = head , body = body )
764+ return response
0 commit comments