Example #1
0
 def create(self, validated_data):
     """Create the payment using initialization of its CardHandler."""
     card_handler = get_card_payment_handler_instance(
         validated_data.pop('card_handler'))
     payment, self.gateway_redirect_url = card_handler.init_payment(
         **validated_data)
     return payment
Example #2
0
    def test_retrieve_exists(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 = {
            'paymentStatus': CSOB.PAYMENT_STATUS_CANCELLED,
            'resultCode': CSOB.RETURN_CODE_OK
        }

        card_payment_hadler = get_card_payment_handler_instance(
            payment.card_handler)
        with patch.object(card_payment_hadler,
                          '_client') as gateway_client_mock:
            gateway_client_mock.payment_status.return_value = result_mock
            response = self.client.get('/api/private/bankpayment/{}/'.format(
                payment.uuid))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['state'], ExternalPaymentState.CANCELED)
Example #3
0
 def _get_payments_states(self, payments):
     """Get states of the payments using their card_payment_handler."""
     for payment in payments:
         try:
             card_payment_handler = get_card_payment_handler_instance(payment.card_handler)
             card_payment_handler.update_payments_state(payment)
         except PaymentHandlerConnectionError:
             LOGGER.error('Connection error while updating state of payment identifier=%s', payment.identifier)
         except PaymentHandlerError:
             LOGGER.error('Error while updating state of payment identifier=%s', payment.identifier)
Example #4
0
    def retrieve(self, request, *args, **kwargs):
        """Update payment state and return update payment."""
        payment = self.get_object()
        old_payment_state = payment.state

        card_payment_handler = get_card_payment_handler_instance(
            payment.card_handler)
        try:
            card_payment_handler.update_payments_state(payment)
        except PaymentHandlerConnectionError:
            return Response(status=status.HTTP_503_SERVICE_UNAVAILABLE)

        if old_payment_state == PaymentState.INITIALIZED and payment.state == PaymentState.READY_TO_PROCESS:
            self._process_payment(payment)

        serializer = BankPaymentSerializer(payment)
        return Response(serializer.data)
Example #5
0
    def test_retrieve_gateway_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.READY_TO_PROCESS,
                              card_handler='csob')
        payment.save()

        card_payment_hadler = get_card_payment_handler_instance(
            payment.card_handler)
        with patch.object(card_payment_hadler,
                          '_client') as gateway_client_mock:
            gateway_client_mock.payment_status.side_effect = PaymentHandlerConnectionError(
            )
            response = self.client.get('/api/private/bankpayment/{}/'.format(
                payment.uuid))

        self.assertEqual(response.status_code, 503)
Example #6
0
 def test_success(self):
     """Test success."""
     self.assertIsInstance(
         get_card_payment_handler_instance('dummy'),
         DummyCardPaymentHandler
     )