Esempio n. 1
0
    def verify_transaction(self, transaction: Transaction, data):
        url = 'https://pay.ir/payment/verify'
        data = {
            'api': self.config['pin'],
            'transId': transaction.id,
        }
        if self.testing:  # pragma: nocover
            url = 'https://pay.ir/payment/test/verify'
            data['api'] = 'test'

        try:
            req = request.Request(url, data=parse.urlencode(data).encode())
            resp = request.urlopen(req)
            resp = json.loads(resp.read().decode())
        except error.HTTPError as e:
            if e.code == 422:
                raise TransactionError('Invalid transaction id')
            raise TransactionError('Invalid transaction information')
        except error.URLError:
            raise GatewayNetworkError('Cannot connect to payline server.')

        if int(resp['status']) != 1:
            raise TransactionError('%s, code: %s' %
                                   (resp['errorMessage'], resp['errorCode']))

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

        transaction.pan = resp['cardNumber']
        return transaction
Esempio n. 2
0
    def verify_transaction(self, transaction: Transaction, data):
        try:
            data = {
                "LoginAccount": self.config["pin"],
                "Token": transaction.id,
            }
            client = Client(self._server_url_verify)
            if "proxies" in self.config:
                client.transport.session.proxies = self.config["proxies"]

            result = client.service.ConfirmPayment(requestData=data)
            status = int(result.Status)
            if status == -1533:
                raise TransactionAlreadyPaidError(
                    "Parsian: Transaction already paid"
                )

            elif status != 0:
                raise TransactionError(
                    "Parsian: %s-%s"
                    % (status, self._response_message_map[str(status)])
                )

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        transaction.pan = result.CardNumberMasked
        return transaction
Esempio n. 3
0
File: payir.py Progetto: 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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
    def verify_transaction(self, transaction: Transaction, data):
        if data['id'] == 'false':
            raise TransactionError('Invalid transaction ID')

        transaction.pan = data.get('cardNumber')
        print('Transaction verified: \n%s' % transaction.__repr__())
        return transaction
Esempio n. 7
0
File: dummy.py Progetto: meyt/payit
    def verify_transaction(self, transaction: Transaction, data):
        if data["id"] == "false":
            raise TransactionError("Invalid transaction ID")

        transaction.pan = data.get("cardNumber")
        print("Transaction verified: \n%s" % transaction.__repr__())
        return transaction
Esempio n. 8
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