Ejemplo n.º 1
0
    def verify_transaction(self, transaction: Transaction, data):
        try:
            params = {
                'merchantId':
                self.config['merchant'],
                'referenceNumber':
                data['referenceId'] if 'referenceId' in data else 0,
                'sha1Key':
                self.config['sha1key'],
                'token':
                transaction.id,
            }
            client = Client(self._server_url_verify)
            if 'proxies' in self.config:
                client.transport.session.proxies = self.config['proxies']

            result = int(client.service.KicccPaymentsVerification(**params))
            if result > 0:
                if result != float(transaction.amount):
                    raise TransactionError(
                        'Irankish: invalid transaction, amount mismatch')
            elif result == -90:
                raise TransactionAlreadyPaidError(
                    'Irankish: transaction already verified')
            else:
                raise TransactionError('Irankish: invalid transaction, %s' %
                                       result)
        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        client = Client(self._server_url_request)
        if 'proxies' in self.config:
            client.transport.session.proxies = self.config['proxies']
        try:
            params = {
                'merchantId': self.config['merchant'],
                'invoiceNo': transaction.order_id,
                'paymentId': transaction.order_id,
                'specialPaymentId': transaction.order_id,
                'amount': int(transaction.amount),
                'description': '',
                'revertURL': self.config['callback_url'],
            }
            result = client.service.MakeToken(**params)
            token = result.token
            if token:
                transaction.id = token
            else:
                raise TransactionError('Irankish: invalid information.')

        except zeep_exceptions.Fault:
            raise TransactionError('Irankish: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo n.º 4
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        client = Client(self._server_url)
        if 'proxies' in self.config:
            client.transport.session.proxies = self.config['proxies']
        try:
            params = {
                'merchantConfigurationID': self.config['merchant_config_id'],
                'encryptedRequest': self._get_encrypted_request(transaction)
            }

            result = client.service.RequestOperation(**params)
            if not result:
                raise TransactionError('AsanPardakht: invalid information.')

            if result[0:1] == '0':
                exploded_result = str(result).split(
                    ',')  # Should have two part [XX,YY]
                transaction.id = exploded_result[1]
            else:
                raise TransactionError(
                    'AsanPardakht: invalid information. code: %s' %
                    str(result))

        except zeep_exceptions.Fault:
            raise TransactionError('AsanPardakht: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo 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
Ejemplo n.º 6
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        client = Client(self._server_url_request)
        if 'proxies' in self.config:
            client.transport.session.proxies = self.config['proxies']
        try:
            data = {
                'LoginAccount': self.config['pin'],
                'OrderId': transaction.order_id,
                'Amount': int(transaction.amount),
                'CallBackUrl': self.config['callback_url'],
            }
            result = client.service.SalePaymentRequest(requestData=data)
            token = result.Token
            status = int(result.Status)
            if token and status == 0:
                transaction.id = str(token)

            else:
                raise TransactionError('Parsian: %s-%s' % (
                    status,
                    self._response_message_map[str(status)]
                ))

        except zeep_exceptions.Fault:
            raise TransactionError('Parsian: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo n.º 7
0
    def verify_transaction(self, transaction: Transaction, data):
        try:
            parsed_data = self._parse_callback_data(data)
            params = {
                'merchantConfigurationID':
                int(self.config['merchant_config_id']),
                'encryptedCredentials': self._encrypted_credentials,
                'payGateTranID': parsed_data['pay_gate_trans_id']
            }
            client = Client(self._server_url)
            if 'proxies' in self.config:
                client.transport.session.proxies = self.config['proxies']

            verify_result = int(client.service.RequestVerification(**params))
            if verify_result == 505:
                raise TransactionAlreadyPaidError(
                    'AsanPardakht: transaction already verified')
            elif verify_result != 500:
                raise TransactionError(
                    'AsanPardakht: invalid transaction, %s' % verify_result)

            reconcile_result = int(
                client.service.RequestReconciliation(**params))
            if reconcile_result != 600:
                raise TransactionError(
                    'AsanPardakht: invalid transaction settlement, %s' %
                    reconcile_result)

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo n.º 8
0
    def verify_transaction(self, transaction: Transaction, data):
        try:
            params = {
                'terminalId': self.config['terminal_id'],
                'userName': self.config['username'],
                'userPassword': self.config['password'],
                'orderId': transaction.order_id,
                'saleOrderId': data['SaleOrderId'],
                'saleReferenceId': data['SaleReferenceId'],
            }
            client = Client(self._server_url)
            if 'proxies' in self.config:
                client.transport.session.proxies = self.config['proxies']

            result = client.service.bpVerifyRequest(**params)
            if int(result) != 0:
                client.service.bpReversalRequest(**params)
                raise TransactionError('Mellat: invalid transaction, code: %s ' % result)

            result = client.service.bpSettleRequest(**params)
            if int(result) != 0:
                client.service.bpReversalRequest(**params)
                raise TransactionError('Mellat: invalid transaction, code: %s ' % result)

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo n.º 9
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        client = Client(self._server_url)
        if 'proxies' in self.config:
            client.transport.session.proxies = self.config['proxies']

        try:
            params = {
                'terminalId': self.config['terminal_id'],
                'userName': self.config['username'],
                'userPassword': self.config['password'],
                'orderId': transaction.order_id,
                'amount': int(transaction.amount),
                'localDate': datetime.now().strftime('%Y%m%d'),
                'localTime': datetime.now().strftime('%H%M%S'),
                'additionalData': '',
                'callBackUrl': self.config['callback_url'],
                'payerId': 0,
            }
            result = client.service.bpPayRequest(**params)
            if not result:
                raise TransactionError('Mellat: invalid information. %s' % result)
            res = str(result).split(',')
            res_code = res[0]
            if int(res_code) == 0:
                transaction.id = res[1]
            else:
                raise TransactionError('Mellat: invalid information. %s' % res_code)

        except zeep_exceptions.Fault:
            raise TransactionError('Mellat: invalid information.')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        return transaction
Ejemplo n.º 10
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.º 11
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        url = 'https://pay.ir/payment/send'
        data = {
            'api': self.config['pin'],
            'amount': transaction.amount,
            'redirect': self.config['callback_url']
        }
        if self.testing:  # pragma: nocover
            url = 'https://pay.ir/payment/test/send'
            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.URLError:
            raise GatewayNetworkError('Cannot connect to payline server.')

        if resp['status'] == 1 and resp['transId']:
            transaction.id = resp['transId']
        else:
            raise TransactionError('%s, code: %s' %
                                   (resp['errorMessage'], resp['errorCode']))

        return transaction
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        if int(transaction.amount) > self.maximum_amount:
            raise TransactionError('Amount is larger than %s' %
                                   self.maximum_amount)

        transaction.id = int(time.time())
        print('New transaction requested: \n%s' % transaction.__repr__())
        return transaction
Ejemplo n.º 15
0
    def request_transaction(self, transaction: Transaction) -> Transaction:
        client = Client(self._server_url)
        try:
            result = client.service.PaymentRequest(
                self.config['merchant'],
                self._convert_iranian_rial_to_toman(transaction.amount),
                self.config['description'], '', '',
                self.config['callback_url'])

        except zeep_exceptions.Fault:
            raise TransactionError('Zarinpal: invalid information')

        except zeep_exceptions.Error:
            raise GatewayNetworkError

        if result.Status == 100 and result.Authority:
            transaction.id = result.Authority
        else:
            raise TransactionError('Zarinpal: invalid information')

        return transaction
Ejemplo n.º 16
0
    def verify_transaction(self, transaction: Transaction, data):
        try:
            client = Client(self._server_url)
            result = client.service.PaymentVerification(
                self.config['merchant'], transaction.id,
                self._convert_iranian_rial_to_toman(transaction.amount))
        except zeep_exceptions.Error:
            raise GatewayNetworkError

        if result.Status == 100:
            return transaction

        elif result.Status == 101:
            raise TransactionAlreadyPaidError

        else:
            raise TransactionError('code: %s' % result.Status)