Example #1
0
 def get(cls):
     # finding identity of using access_token
     _id = get_jwt_identity()
     merchant = MerchantModel.find_merchant_by_id(_id)
     if not merchant:
         return {"msg": MERCHANT_NOT_FOUND}, 404
     return merchant_schema.dump(merchant), 200
Example #2
0
    def get(cls):
        _id = get_jwt_identity()
        merchant = MerchantModel.find_merchant_by_id(_id)
        print(merchant_schema.dump(merchant))
        try:
            history_details = HistoryModel.find_by_mobile_number(
                merchant.mobile_number)
        except:
            return {'message': INTERNAL_SERVER_ERROR}, 500

        return {
            'history': [history_schema.dump(hist) for hist in history_details]
        }, 200
    def get(cls):
        """
        :return: The History of transactions of the person who is logged in.
        """
        _id = get_jwt_identity()
        merchant = MerchantModel.find_merchant_by_id(_id)
        try:
            history_details = HistoryModel.find_by_mobile_number(
                merchant.mobile_number)
        except:
            return {'message': INTERNAL_SERVER_ERROR}, 500

        return {
            'history': [history_schema.dump(hist) for hist in history_details]
        }, 200
Example #4
0
    def post(cls):
        """
        This method is used when merchant scans a Qr code of customer and send a pull payment request.
        :return: msg according to status of transaction
        """
        _id = get_jwt_identity()
        payload = request.get_json()

        merchant = MerchantModel.find_merchant_by_id(_id)
        if merchant is None:
            return {"msg": INTERNAL_SERVER_ERROR}, 500

        # Setting essential fields of Payload for pull funds transfer call
        payload["acquirerCountryCode"] = merchant.acquirerCountryCode
        payload["acquiringBin"] = merchant.acquiringBin
        payload["businessApplicationId"] = merchant.businessApplicationId
        payload["cardAcceptor"] = {
            "address": {
                "country": merchant.country,
                "state": merchant.state,
                "zipCode": merchant.zipCode
            },
            "idCode": merchant.idCode,
            "name": merchant.name,
            "terminalId": merchant.terminalId
        }

        # Generates a unique system trace audit number.
        systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6]
        while systemsTraceAuditNumber in SystemsTraceAuditNumber:
            systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6]
        SystemsTraceAuditNumber.add(systemsTraceAuditNumber)

        payload["systemsTraceAuditNumber"] = systemsTraceAuditNumber
        payload["localTransactionDateTime"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
        payload["retrievalReferenceNumber"] = RetrievalNo.No() + str(systemsTraceAuditNumber)

        payload["senderPrimaryAccountNumber"] = "4895142232120006"

        # customer mobile number present in the qr scanned by merchant
        mobile_number = ""
        # customer wallet name
        wallet_name = ""

        # FLag tells whether we get mobile number from customer details or not.
        flag = False

        # status code is for transaction shows whether the transaction was successful or not
        status_code = False

        if "mobile_number" in payload:

            # mobile_number is present in payload
            flag = True

            # Setting payload for call to AuthApi for Confirmation of amount present in wallet of sender
            payloadAuthApi = {}
            mobile_number = payload["mobile_number"]
            wallet_name = payload["wallet_name"]
            payloadAuthApi["mobile_number"] = payload["mobile_number"]
            payloadAuthApi["wallet_name"] = payload["wallet_name"]
            del (payload["mobile_number"])
            del (payload["wallet_name"])
            payloadAuthApi["merchant_name"] = merchant.name
            payloadAuthApi["amount"] = payload["amount"]
            payloadAuthApi["systemsTraceAuditNumber"] = systemsTraceAuditNumber

            # call to authApi for confirmation of amount entered by customer.
            r = VisaNet.AmountConfirmation(payloadAuthApi)
            if r.status_code != 200:
                # Updating History for transaction failure.
                history = HistoryModel(amount=payload["amount"],
                                       transaction_id=systemsTraceAuditNumber,
                                       transaction_time=payload["localTransactionDateTime"],
                                       merchant_mobile_number=merchant.mobile_number,
                                       customer_mobile_number=mobile_number,
                                       customer_wallet_name=wallet_name,
                                       merchant_name=merchant.name,
                                       status=status_code
                                       )
                history.save_to_db()
                return {'msg': PAYMENT_CANNOT_BE_COMPLETED}, 400

        #    deleting nonessential fields of payload
        if "wallet_name" in payload:
            del(payload["wallet_name"])

        #   Sending pull payments request to helper function
        response = FundsTransfer.merchant_pull_payments_post_response(payload)

        if response.status_code != 200:
            if flag:
                payloadAuthApi = {
                    'mobile_number': mobile_number,
                    'pan': payload["senderPrimaryAccountNumber"],
                    'systemsTraceAuditNumber': systemsTraceAuditNumber,
                    'code': response.status_code
                }
                # Sending request for rollback of payment denoted by code of payload
                r = VisaNet.TransactionConfirmation(payloadAuthApi)

            #   setting history for payment failure
            history = HistoryModel(amount=payload["amount"],
                                   transaction_id=systemsTraceAuditNumber,
                                   transaction_time=payload["localTransactionDateTime"],
                                   merchant_mobile_number=merchant.mobile_number,
                                   customer_mobile_number=mobile_number,
                                   customer_wallet_name=wallet_name,
                                   merchant_name=merchant.name,
                                   status=status_code
                                   )
            # saving history in the database
            history.save_to_db()
            return {"msg": INTERNAL_SERVER_ERROR}, 500

        # payment approved by visa pull funds transfer api
        if response.status_code == 200:
            if flag:
                payloadAuthApi = {
                    'mobile_number': mobile_number,
                    'pan': payload["senderPrimaryAccountNumber"],
                    'systemsTraceAuditNumber': systemsTraceAuditNumber,
                    'code': response.status_code
                }
                # Sending confirmation of transaction to Auth api denoted by code of transaction
                r = VisaNet.TransactionConfirmation(payloadAuthApi)
            status_code = True

        # setting history for payment success
        history = HistoryModel(amount=payload["amount"],
                               transaction_id=systemsTraceAuditNumber,
                               transaction_time=payload["localTransactionDateTime"],
                               merchant_mobile_number=merchant.mobile_number,
                               customer_mobile_number=mobile_number,
                               customer_wallet_name=wallet_name,
                               merchant_name=merchant.name,
                               status=status_code
                               )

        # Saving history in the database.
        history.save_to_db()
        return response
Example #5
0
 def get(cls):  # get using phone number (can be changed per use case)
     _id = get_jwt_identity()
     merchant = MerchantModel.find_merchant_by_id(_id)
     if not merchant:
         return {"msg": MERCHANT_NOT_FOUND}, 404
     return merchant_schema.dump(merchant), 200
Example #6
0
    def post(cls):
        _id = get_jwt_identity()
        payload = request.get_json()

        merchant = MerchantModel.find_merchant_by_id(_id)
        if merchant is None:
            return {"msg": INTERNAL_SERVER_ERROR}, 500

        payload["acquirerCountryCode"] = merchant.acquirerCountryCode
        payload["acquiringBin"] = merchant.acquiringBin
        payload["businessApplicationId"] = merchant.businessApplicationId
        payload["cardAcceptor"] = {
            "address": {
                "country": merchant.country,
                "state": merchant.state,
                "zipCode": merchant.zipCode
            },
            "idCode": merchant.idCode,
            "name": merchant.name,
            "terminalId": merchant.terminalId
        }

        systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6]
        while systemsTraceAuditNumber in SystemsTraceAuditNumber:
            systemsTraceAuditNumber = str(uuid.uuid4().int >> 32)[0:6]
        SystemsTraceAuditNumber.add(systemsTraceAuditNumber)

        payload["systemsTraceAuditNumber"] = systemsTraceAuditNumber
        payload["localTransactionDateTime"] = datetime.utcnow().strftime(
            "%Y-%m-%dT%H:%M:%S")
        payload["retrievalReferenceNumber"] = RetrievalNo.No() + str(
            systemsTraceAuditNumber)

        payload["senderPrimaryAccountNumber"] = "4895142232120006"
        # print(payload)

        mobile_number = ""
        wallet_name = ""
        flag = False
        status_code = False
        if "mobile_number" in payload:
            flag = True
            payloadAuthApi = {}
            mobile_number = payload["mobile_number"]
            wallet_name = payload["wallet_name"]
            payloadAuthApi["mobile_number"] = payload["mobile_number"]
            payloadAuthApi["wallet_name"] = payload["wallet_name"]
            del (payload["mobile_number"])
            del (payload["wallet_name"])
            payloadAuthApi["merchant_name"] = merchant.name
            payloadAuthApi["amount"] = payload["amount"]
            payloadAuthApi["systemsTraceAuditNumber"] = systemsTraceAuditNumber
            r = VisaNet.AmountConfirmation(payloadAuthApi)
            print(r)
            print(r.json())
            if r.status_code != 200:
                history = HistoryModel(
                    amount=payload["amount"],
                    transaction_id=systemsTraceAuditNumber,
                    transaction_time=payload["localTransactionDateTime"],
                    merchant_mobile_number=merchant.mobile_number,
                    customer_mobile_number=mobile_number,
                    customer_wallet_name=wallet_name,
                    merchant_name=merchant.name,
                    status=status_code)
                history.save_to_db()
                return {'msg': PAYMENT_CANNOT_BE_COMPLETED}, 400

        if "wallet_name" in payload:
            del (payload["wallet_name"])

        response = FundsTransfer.merchant_pull_payments_post_response(payload)

        if response.status_code != 200:
            if flag:
                payloadAuthApi = {
                    'mobile_number': mobile_number,
                    'pan': payload["senderPrimaryAccountNumber"],
                    'systemsTraceAuditNumber': systemsTraceAuditNumber,
                    'code': response.status_code
                }
                r = VisaNet.TransactionConfirmation(payloadAuthApi)
            history = HistoryModel(
                amount=payload["amount"],
                transaction_id=systemsTraceAuditNumber,
                transaction_time=payload["localTransactionDateTime"],
                merchant_mobile_number=merchant.mobile_number,
                customer_mobile_number=mobile_number,
                customer_wallet_name=wallet_name,
                merchant_name=merchant.name,
                status=status_code)
            history.save_to_db()
            return {"msg": INTERNAL_SERVER_ERROR}, 500

        if response.status_code == 200:
            if flag:
                payloadAuthApi = {
                    'mobile_number': mobile_number,
                    'pan': payload["senderPrimaryAccountNumber"],
                    'systemsTraceAuditNumber': systemsTraceAuditNumber,
                    'code': response.status_code
                }
                r = VisaNet.TransactionConfirmation(payloadAuthApi)
            status_code = True
        history = HistoryModel(
            amount=payload["amount"],
            transaction_id=systemsTraceAuditNumber,
            transaction_time=payload["localTransactionDateTime"],
            merchant_mobile_number=merchant.mobile_number,
            customer_mobile_number=mobile_number,
            customer_wallet_name=wallet_name,
            merchant_name=merchant.name,
            status=status_code)
        history.save_to_db()
        # response = FundsTransfer.merchant_push_payments_post_response()
        return response