Ejemplo n.º 1
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data['Token']
     transaction.meta = data
     if 'status' in data and int(data['status']) == 0:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 2
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["Authority"]
     transaction.meta = data
     if data["Status"] == "OK":
         transaction.validate_status = True
     return transaction
Ejemplo n.º 3
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data['id']
     transaction.meta = data
     transaction.validate_status = data.get('validateStatus', True)
     print('Transaction validated: \n%s' % transaction.__repr__())
     return transaction
Ejemplo n.º 4
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["token"]
     transaction.meta = data
     if "resultCode" in data and int(data["resultCode"]) == 100:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 5
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data['Authority']
     transaction.meta = data
     if data['Status'] == 'OK':
         transaction.validate_status = True
     return transaction
Ejemplo n.º 6
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["bill_id"]
     transaction.meta = data
     if data["state"] in ("pay", "request"):
         transaction.validate_status = True
     return transaction
Ejemplo n.º 7
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data['token']
     transaction.meta = data
     if 'resultCode' in data and int(data['resultCode']) == 100:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 8
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data['transId']
     transaction.meta = data
     if int(data['status']) == 1:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 9
0
Archivo: dummy.py Proyecto: meyt/payit
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["id"]
     transaction.meta = data
     transaction.validate_status = data.get("validateStatus", True)
     print("Transaction validated: \n%s" % transaction.__repr__())
     return transaction
Ejemplo n.º 10
0
Archivo: payir.py Proyecto: meyt/payit
    def verify_transaction(self, transaction: Transaction, data):
        url = "https://pay.ir/pg/verify"
        formdata = {
            "api": "test" if self.testing else self.config["pin"],
            "token": transaction.id,
        }
        try:
            resp = request("post", url, data=formdata)
        except RequestException:
            raise GatewayNetworkError("Cannot connect to payir server")

        try:
            body = resp.json()
        except Exception:
            body = None

        if resp.status_code != 200:
            if not body:
                raise TransactionError(
                    "Invalid transaction information (%s)" % resp.status_code
                )

            raise TransactionError(
                "%s, code: %s" % (body["errorMessage"], body["errorCode"])
            )

        if int(transaction.amount) != int(body["amount"]):
            raise TransactionError("Amount mismatch")

        transaction.pan = body["cardNumber"]
        transaction.amount = int(body["amount"])
        transaction.order_id = body["factorNumber"]
        transaction.meta = body
        return transaction
Ejemplo n.º 11
0
    def verify_transaction(self, transaction: Transaction, data):
        url = '%s/bills/%s' % (self._server_url, transaction.id)
        headers = {
            'access-token': self.config['access_token'],
            'content-type': 'application/json'
        }
        try:
            response = request('get', url, headers=headers)
        except RequestException:
            raise GatewayNetworkError('Cannot connect to bahamta server.')

        if response.status_code != 200:
            raise TransactionError(
                'Invalid transaction information (%s)' % response.status_code
            )
        response_data = response.json()

        if response_data['state'] != 'pay':
            raise TransactionError('Transaction not paid')

        if int(transaction.amount) != int(response_data['amount']):
            raise TransactionError('Amount mismatch')

        transaction.pan = response_data['pay_pan']
        transaction.meta = response_data
        return transaction
Ejemplo n.º 12
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["Token"]
     transaction.meta = data
     if "status" in data and int(data["status"]) == 0:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 13
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        data = {
            'payer_number': transaction.meta.get('payer_number'),
            'payer_name': transaction.meta.get('payer_name'),
            'amount': transaction.amount,
            'note': transaction.meta.get('note'),
            'silent': transaction.meta.get('silent')
        }
        for key in ('payer_name', 'payer_number', 'note'):
            if data[key] is None:
                raise ValueError('Transaction meta required (%s)' % key)
        url = '%s/bills' % self._server_url
        headers = {
            'access-token': self.config['access_token'],
            'content-type': 'application/json'
        }
        try:
            response = request(
                'post', url, json=[data], headers=headers
            )
        except RequestException:
            raise GatewayNetworkError('Cannot connect to bahamta server.')

        if response.status_code != 200:
            raise TransactionError(
                'Invalid transaction information (%s)' % response.status_code
            )
        response_data = response.json()[0]
        transaction.id = response_data['bill_id']
        transaction.meta = response_data
        return transaction
Ejemplo n.º 14
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data['bill_id']
     transaction.meta = data
     if data['state'] in ('pay', 'request'):
         transaction.validate_status = True
     return transaction
Ejemplo n.º 15
0
    def verify_transaction(self, transaction: Transaction, data):
        url = "%s/bills/%s" % (self._server_url, transaction.id)
        headers = {
            "access-token": self.config["access_token"],
            "content-type": "application/json",
        }
        try:
            response = request("get", url, headers=headers)
        except RequestException:
            raise GatewayNetworkError("Cannot connect to bahamta server.")

        if response.status_code != 200:
            raise TransactionError("Invalid transaction information (%s)" %
                                   response.status_code)
        response_data = response.json()

        if response_data["state"] != "pay":
            raise TransactionError("Transaction not paid")

        if int(transaction.amount) != int(response_data["amount"]):
            raise TransactionError("Amount mismatch")

        transaction.pan = response_data["pay_pan"]
        transaction.meta = response_data
        return transaction
Ejemplo n.º 16
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        data = {
            "payer_number": transaction.meta.get("payer_number"),
            "payer_name": transaction.meta.get("payer_name"),
            "amount": transaction.amount,
            "note": transaction.meta.get("note"),
            "silent": transaction.meta.get("silent"),
        }
        for key in ("payer_name", "payer_number", "note"):
            if data[key] is None:
                raise ValueError("Transaction meta required (%s)" % key)
        url = "%s/bills" % self._server_url
        headers = {
            "access-token": self.config["access_token"],
            "content-type": "application/json",
        }
        try:
            response = request("post", url, json=[data], headers=headers)
        except RequestException:
            raise GatewayNetworkError("Cannot connect to bahamta server.")

        if response.status_code != 200:
            raise TransactionError("Invalid transaction information (%s)" %
                                   response.status_code)
        response_data = response.json()[0]
        transaction.id = response_data["bill_id"]
        transaction.meta = response_data
        return transaction
Ejemplo n.º 17
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["RefId"]
     transaction.meta = data
     if int(data["ResCode"]) == 0:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 18
0
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data.get("transid")
     transaction.amount = int(data.get("amount", 0))
     transaction.pan = data.get("cardnumber")
     transaction.meta = data
     transaction.validate_status = transaction.id is not None
     return transaction
Ejemplo n.º 19
0
 def validate_transaction(self, data: dict) -> Transaction:
     parsed_data = self._parse_callback_data(data)
     transaction = Transaction()
     transaction.id = parsed_data['ref_id']
     transaction.meta = parsed_data
     if int(parsed_data['res_code']) == 0:
         transaction.validate_status = True
     return transaction
Ejemplo n.º 20
0
Archivo: payir.py Proyecto: meyt/payit
 def validate_transaction(self, data: dict) -> Transaction:
     transaction = Transaction()
     transaction.id = data["token"]
     transaction.meta = data
     transaction.validate_status = int(data["status"]) == 1
     return transaction