コード例 #1
0
    def test_init_payment_ok(self):
        account = get_account(account_number='123456', currency='CZK')
        account.save()

        handler = CSOBCardPaymentHandler('csob')
        with patch.object(handler, '_client') as gateway_client_mock:
            gateway_client_mock.gateway_return.return_value = OrderedDict([
                ('payId', 'unique_id_123'),
                ('resultCode', CSOB.RETURN_CODE_OK), ('resultMessage', 'OK'),
                ('paymentStatus', CSOB.PAYMENT_STATUS_INIT),
                ('dttime', datetime.datetime(2020, 6, 10, 16, 47, 30))
            ])
            gateway_client_mock.get_payment_process_url.return_value = sentinel.url
            payment, redirect_url = handler.init_payment(
                100, '123', 'donations', 'https://example.com', 'POST', [
                    CartItem('Gift for FRED', 1, 1000000,
                             'Gift for the best FRED')
                ], 'CZ')
        self.assertEqual(redirect_url, sentinel.url)
        self.assertEqual(payment.identifier, 'unique_id_123')
        self.assertEqual(payment.state, PaymentState.INITIALIZED)
        self.assertEqual(payment.card_payment_state,
                         CSOB.PAYMENT_STATUSES[CSOB.PAYMENT_STATUS_INIT])
        self.assertEqual(payment.amount, Money(100, 'CZK'))
        self.assertEqual(payment.processor, 'donations')
        self.assertEqual(payment.card_handler, 'csob')
コード例 #2
0
 def test_init_payment_connection_error(self):
     handler = CSOBCardPaymentHandler('csob')
     with patch.object(handler, '_client') as gateway_client_mock:
         gateway_client_mock.payment_init.side_effect = requests.ConnectionError(
         )
         self.assertRaises(PaymentHandlerConnectionError,
                           handler.init_payment, 100, '123', 'csob',
                           'https://example.com', 'POST', [], 'CZ')
コード例 #3
0
    def test_update_payment_state_no_update_not_initialized(self):
        account = get_account(account_number='123456', currency='CZK')
        account.save()
        payment = get_payment(identifier='1',
                              account=account,
                              counter_account_number='',
                              payment_type=PaymentType.CARD_PAYMENT,
                              state=PaymentState.PROCESSED,
                              card_handler='csob')
        payment.save()

        result_mock = Mock()
        result_mock.payload = {
            'paymentStatus': CSOB.PAYMENT_STATUS_CANCELLED,
            'resultCode': CSOB.RETURN_CODE_OK
        }

        handler = CSOBCardPaymentHandler('csob')
        with patch.object(handler, '_client') as gateway_client_mock:
            gateway_client_mock.payment_status.return_value = result_mock

            handler.update_payments_state(payment)

        self.assertEqual(payment.state, PaymentState.PROCESSED)
コード例 #4
0
    def test_update_payment_state_connection_error(self):
        account = get_account(account_number='123456', currency='CZK')
        account.save()
        payment = get_payment(identifier='1',
                              account=account,
                              counter_account_number='',
                              payment_type=PaymentType.CARD_PAYMENT,
                              state=PaymentState.INITIALIZED,
                              card_handler='csob')
        payment.save()

        handler = CSOBCardPaymentHandler('csob')
        with patch.object(handler, '_client') as gateway_client_mock:
            gateway_client_mock.payment_status.side_effect = requests.ConnectionError(
            )

            self.assertRaises(PaymentHandlerConnectionError,
                              handler.update_payments_state, payment)
コード例 #5
0
    def test_init_payment_not_ok(self):
        account = get_account(account_number='123456', currency='CZK')
        account.save()

        handler = CSOBCardPaymentHandler('csob')
        with patch.object(handler, '_client') as gateway_client_mock:
            gateway_client_mock.gateway_return.return_value = OrderedDict([
                ('payId', 'unique_id_123'),
                ('resultCode', CSOB.RETURN_CODE_MERCHANT_BLOCKED),
                ('resultMessage', 'Merchant blocked'),
                ('dttime', datetime.datetime(2020, 6, 10, 16, 47, 30))
            ])
            self.assertRaisesRegex(PaymentHandlerError, 'resultCode != OK',
                                   handler.init_payment, 100, '123',
                                   'donations', 'https://example.com', 'POST',
                                   [
                                       CartItem('Gift for FRED', 1, 1000000,
                                                'Gift for the best FRED')
                                   ], 'CZ')
コード例 #6
0
    def test_update_payment_state_not_ok(self):
        account = get_account(account_number='123456', currency='CZK')
        account.save()
        payment = get_payment(identifier='1',
                              account=account,
                              counter_account_number='',
                              payment_type=PaymentType.CARD_PAYMENT,
                              state=PaymentState.INITIALIZED,
                              card_handler='csob')
        payment.save()

        result_mock = Mock()
        result_mock.payload = {'resultCode': CSOB.RETURN_CODE_MERCHANT_BLOCKED}

        handler = CSOBCardPaymentHandler('csob')
        with patch.object(handler, '_client') as gateway_client_mock:
            gateway_client_mock.payment_status.return_value = result_mock
            self.assertRaisesRegex(PaymentHandlerError,
                                   'payment_status resultCode != OK',
                                   handler.update_payments_state, payment)
        self.assertEqual(payment.state, PaymentState.INITIALIZED)
コード例 #7
0
 def test_get_client(self):
     handler = CSOBCardPaymentHandler('csob')
     client = handler.client
     # repeated calls should get the same client instance
     client2 = handler.client
     self.assertEqual(client, client2)