예제 #1
0
 def test_extracts_bankcard_info(self, gateway_authenticate):
     facade.authenticate(AMT, CURRENCY,
                         BANKCARD, SHIPPING_ADDRESS, BILLING_ADDRESS)
     __, kwargs = gateway_authenticate.call_args
     for key in ('amount', 'currency', 'bankcard_number', 'bankcard_cv2',
                 'bankcard_name', 'bankcard_expiry'):
         assert key in kwargs
예제 #2
0
 def test_extracts_billing_address_info(self, gateway_authenticate):
     facade.authenticate(AMT, CURRENCY, BANKCARD,
                         SHIPPING_ADDRESS, BILLING_ADDRESS)
     __, kwargs = gateway_authenticate.call_args
     for key in ('billing_surname', 'billing_first_names',
                 'billing_address1', 'billing_address2', 'billing_city',
                 'billing_postcode', 'billing_country', 'billing_state',):
         assert key in kwargs
def test_multiple_transactions():
    # Authenticate transaction
    authenticate_tx_id = facade.authenticate(
        AMT, CURRENCY, BANKCARD, SHIPPING_ADDRESS, BILLING_ADDRESS)

    # Authorise (in two parts)
    facade.authorise(
        tx_id=authenticate_tx_id, amount=D('8.00'))
    auth_tx_id = facade.authorise(
        tx_id=authenticate_tx_id, amount=D('2.00'))

    # Refund last authorise
    facade.refund(auth_tx_id)
    def handle_payment(self, order_number, total, bankcard_form,
                       billing_address_form, shipping_address, **kwargs):
        tx_id = facade.authenticate(
            order_number=order_number,
            amount=total.incl_tax, currency=total.currency,
            bankcard=bankcard_form.bankcard,
            shipping_address=shipping_address,
            billing_address=billing_address_form.save(commit=False))

        # Request was successful - record the "payment source".  As this
        # request was a 'pre-auth', we set the 'amount_allocated' - if we had
        # performed an 'auth' request, then we would set 'amount_debited'.
        source_type, __ = SourceType.objects.get_or_create(name='Sagepay')
        source = Source(source_type=source_type,
                        currency=total.currency,
                        amount_allocated=total.incl_tax,
                        reference=tx_id)
        self.add_payment_source(source)

        # Also record payment event
        self.add_payment_event('authenticate', total.incl_tax)
예제 #5
0
 def test_returns_tx_id_if_successful(self, gateway_authenticate):
     gateway_authenticate.return_value = mock.Mock(tx_id='123xxx')
     tx_id = facade.authenticate(
         AMT, CURRENCY, BANKCARD, SHIPPING_ADDRESS, BILLING_ADDRESS)
     assert tx_id == '123xxx'
예제 #6
0
 def test_raises_payment_error_if_response_not_ok(self, gateway_authenticate):
     gateway_authenticate.return_value = mock.Mock(is_registered=False)
     with pytest.raises(payment_exceptions.PaymentError):
         facade.authenticate(
             AMT, CURRENCY, BANKCARD, SHIPPING_ADDRESS, BILLING_ADDRESS)
예제 #7
0
 def test_raises_payment_error_if_gateway_problem(self, gateway_authenticate):
     gateway_authenticate.side_effect = exceptions.GatewayError
     with pytest.raises(payment_exceptions.PaymentError):
         facade.authenticate(
             AMT, CURRENCY, BANKCARD, SHIPPING_ADDRESS, BILLING_ADDRESS)