def test_calls_gateway_with_correct_data(self, get): get.return_value = mock.MagicMock( vendor_tx_code='v1', tx_id='123', tx_auth_num='', security_key='xx') with mock.patch('oscar_sagepay.gateway.authorise') as authorise: facade.authorise(tx_id='123', amount=D('10.00')) kwargs = authorise.call_args[1] assert kwargs['previous_txn'].vendor_tx_code == 'v1' assert kwargs['previous_txn'].tx_id == '123' assert kwargs['previous_txn'].tx_auth_num == '' assert kwargs['previous_txn'].security_key == 'xx' assert kwargs['amount'] == D('10.00') assert 'description' 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 post(self, request, number): order = shortcuts.get_object_or_404( order_models.Order, number=number) # Grab Sagepay TX ID (in a hacky way) source = order.sources.all()[0] tx_id = source.reference url = reverse('dashboard:order-detail', kwargs={ 'number': order.number}) response = http.HttpResponseRedirect(url) try: new_tx_id = facade.authorise(tx_id, order_number=order.number) except exceptions.PaymentError as e: messages.error( request, ( "We were unable to authorise your order: %s") % e) return response # Update payment source source.debit(reference=new_tx_id) messages.success( request, "Transaction authorised: TX ID %s" % new_tx_id) return response
def post(self, request, number): order = shortcuts.get_object_or_404(order_models.Order, number=number) # Grab Sagepay TX ID (in a hacky way) source = order.sources.all()[0] tx_id = source.reference url = reverse('dashboard:order-detail', kwargs={'number': order.number}) response = http.HttpResponseRedirect(url) try: new_tx_id = facade.authorise(tx_id, order_number=order.number) except exceptions.PaymentError as e: messages.error(request, ("We were unable to authorise your order: %s") % e) return response # Update payment source source.debit(reference=new_tx_id) messages.success(request, "Transaction authorised: TX ID %s" % new_tx_id) return response
def test_defaults_to_previous_amount(self, get): get.return_value = mock.MagicMock(amount=D('1.99')) with mock.patch('oscar_sagepay.gateway.authorise') as authorise: facade.authorise(tx_id='123') kwargs = authorise.call_args[1] assert kwargs['amount'] == D('1.99')
def test_raises_payment_error_if_no_matching_audit_model(self, get): get.side_effect = models.RequestResponse.DoesNotExist with pytest.raises(payment_exceptions.PaymentError): facade.authorise(tx_id='123')
def test_not_ok_response_raises_payment_error(self, get): get.return_value = mock.MagicMock() with mock.patch('oscar_sagepay.gateway.authorise') as authorise: authorise.return_value = mock.MagicMock(is_ok=False) with pytest.raises(payment_exceptions.PaymentError): facade.authorise(tx_id='123')
def test_gateway_error_raises_payment_error(self, get): get.return_value = mock.MagicMock() with mock.patch('oscar_sagepay.gateway.authorise') as authorise: authorise.side_effect = exceptions.GatewayError with pytest.raises(payment_exceptions.PaymentError): facade.authorise(tx_id='123')