Esempio n. 1
0
    def refund(self):
        """Processes a refund transaction."""
        transaction = self.get_object()

        refund = gateway.Refund({
            'transaction_type': 'r',
            'amount': transaction.amount,
            'token': transaction.token,
            'token_f4l4': transaction.token_f4l4,
            'customer_code': transaction.customer_code,
        })

        try:
            refund.process()
        except exceptions.RefundError:
            messages.error(self.request, 'Unable to refund transaction')
        else:
            messages.success(self.request, 'Transaction refunded')

        return HttpResponseRedirect(
            reverse(
                'helcim_transaction_detail',
                kwargs={'transaction_id': transaction.id}
            )
        )
Esempio n. 2
0
    def process(self):
        """Attempts to process Refund with transaction details.

            Returns the values of ``gateway.Refund.process``.

            Raises:
                GatewayError: An Oscar error raised when there was an
                    error with the payment API.
                PaymentError: An Oscar error raised when there was an
                    error processing the payment.
        """

        refund_instance = gateway.Refund(save_token=self.save_token,
                                         django_user=self.django_user,
                                         **self.transaction_details)

        try:
            return refund_instance.process()
        except helcim_exceptions.ProcessingError as error:
            raise oscar_exceptions.GatewayError(str(error))
        except helcim_exceptions.PaymentError as error:
            raise oscar_exceptions.PaymentError(str(error))
        except helcim_exceptions.DjangoError:
            LOG.exception('Refund complete, but errors occured while saving '
                          'transaction to database')
        except helcim_exceptions.HelcimError as error:
            raise oscar_exceptions.GatewayError(str(error))
Esempio n. 3
0
def test_process_error_response_refund():
    refund_request = gateway.Refund()

    try:
        refund_request.process_error_response('')
    except helcim_exceptions.RefundError:
        assert True
    else:
        assert False
Esempio n. 4
0
def test_refund_processing():
    details = {
        'amount': 100.00,
        'customer_code': 'CST1000',
    }

    refund = gateway.Refund(api_details=API_DETAILS, **details)
    transaction, _ = refund.process()

    assert isinstance(transaction, MockDjangoModel)
Esempio n. 5
0
def test_process_with_save_token_disabled():
    details = {
        'amount': 100.00,
        'token': 'abcdefghijklmnopqrstuvw',
        'token_f4l4': '11119999',
        'customer_code': 'CST1000',
    }

    refund = gateway.Refund(api_details=API_DETAILS,
                            save_token=True,
                            **details)
    _, token = refund.process()

    assert token is None
Esempio n. 6
0
def test_process_with_save_token_enabled(django_user_model):
    details = {
        'amount': 100.00,
        'token': 'abcdefghijklmnopqrstuvw',
        'token_f4l4': '11119999',
        'customer_code': 'CST1000',
    }
    user = django_user_model.objects.create_user(username='******',
                                                 password='******')

    refund = gateway.Refund(api_details=API_DETAILS,
                            save_token=True,
                            django_user=user,
                            **details)
    _, token = refund.process()

    assert isinstance(token, MockDjangoModel)