def test_issue_credit_error(self): """ Tests that issue_credit errors in case of communication error or declined transaction """ transaction_id = 'request-1234' refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() self.mock_cybersource_wsdl() # Test for communication failure. with mock.patch('suds.client.ServiceSelector', mock.Mock(side_effect=Exception)): self.assertRaises(GatewayError, self.processor.issue_credit, order, source.reference, amount, currency) self.assertEqual(source.amount_refunded, 0) # Test for declined transaction cs_soap_mock = self.get_soap_mock(amount=amount, currency=currency, transaction_id=transaction_id, basket_id=basket.id, decision='DECLINE') with mock.patch('suds.client.ServiceSelector', cs_soap_mock): self.assertRaises(GatewayError, self.processor.issue_credit, order, source.reference, amount, currency) self.assert_processor_response_recorded( self.processor.NAME, transaction_id, suds_response_to_dict(cs_soap_mock().runTransaction()), basket) self.assertEqual(source.amount_refunded, 0)
def test_issue_credit(self): """ Tests issue_credit operation """ transaction_id = 'request-1234' refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() self.mock_cybersource_wsdl() self.assertEqual(source.amount_refunded, 0) self.assertFalse(order.payment_events.exists()) cs_soap_mock = self.get_soap_mock(amount=amount, currency=currency, transaction_id=transaction_id, basket_id=basket.id) with mock.patch('suds.client.ServiceSelector', cs_soap_mock): actual = self.processor.issue_credit(order, source.reference, amount, currency) self.assertEqual(actual, transaction_id) # Verify PaymentProcessorResponse created self.assert_processor_response_recorded( self.processor.NAME, transaction_id, suds_response_to_dict(cs_soap_mock().runTransaction()), basket)
def test_issue_credit(self): transaction_id = 'request-1234' refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() self.mock_cybersource_wsdl() self.assertEqual(source.amount_refunded, 0) self.assertFalse(order.payment_events.exists()) cs_soap_mock = self.get_soap_mock(amount=amount, currency=currency, transaction_id=transaction_id, basket_id=basket.id) with mock.patch('suds.client.ServiceSelector', cs_soap_mock): self.processor.issue_credit(source, amount, currency) # Verify PaymentProcessorResponse created self.assert_processor_response_recorded( self.processor.NAME, transaction_id, suds_response_to_dict(cs_soap_mock().runTransaction()), basket) # Verify Source updated self.assertEqual(source.amount_refunded, amount) # Verify PaymentEvent created paid_type = PaymentEventType.objects.get(code=u'refunded') payment_event = order.payment_events.first() self.assert_valid_payment_event_fields(payment_event, amount, paid_type, self.processor.NAME, transaction_id)
def test_issue_credit_error(self): transaction_id = 'request-1234' refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() self.mock_cybersource_wsdl() # Test for communication failure. with mock.patch('suds.client.ServiceSelector', mock.Mock(side_effect=Exception)): self.assertRaises(GatewayError, self.processor.issue_credit, source, amount, currency) self.assertEqual(source.amount_refunded, 0) # Test for declined transaction cs_soap_mock = self.get_soap_mock(amount=amount, currency=currency, transaction_id=transaction_id, basket_id=basket.id, decision='DECLINE') with mock.patch('suds.client.ServiceSelector', cs_soap_mock): self.assertRaises(GatewayError, self.processor.issue_credit, source, amount, currency) self.assert_processor_response_recorded(self.processor.NAME, transaction_id, suds_response_to_dict(cs_soap_mock().runTransaction()), basket) self.assertEqual(source.amount_refunded, 0)
def test_issue_credit(self): transaction_id = 'request-1234' refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() self.mock_cybersource_wsdl() self.assertEqual(source.amount_refunded, 0) self.assertFalse(order.payment_events.exists()) cs_soap_mock = self.get_soap_mock(amount=amount, currency=currency, transaction_id=transaction_id, basket_id=basket.id) with mock.patch('suds.client.ServiceSelector', cs_soap_mock): self.processor.issue_credit(source, amount, currency) # Verify PaymentProcessorResponse created self.assert_processor_response_recorded(self.processor.NAME, transaction_id, suds_response_to_dict(cs_soap_mock().runTransaction()), basket) # Verify Source updated self.assertEqual(source.amount_refunded, amount) # Verify PaymentEvent created paid_type = PaymentEventType.objects.get(code=u'refunded') payment_event = order.payment_events.first() self.assert_valid_payment_event_fields(payment_event, amount, paid_type, self.processor.NAME, transaction_id)
def test_issue_credit(self): """ Tests issue_credit operation """ transaction_id = 'request-1234' refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() self.mock_cybersource_wsdl() self.assertEqual(source.amount_refunded, 0) self.assertFalse(order.payment_events.exists()) cs_soap_mock = self.get_soap_mock(amount=amount, currency=currency, transaction_id=transaction_id, basket_id=basket.id) with mock.patch('suds.client.ServiceSelector', cs_soap_mock): actual = self.processor.issue_credit(order, source.reference, amount, currency) self.assertEqual(actual, transaction_id) # Verify PaymentProcessorResponse created self.assert_processor_response_recorded(self.processor.NAME, transaction_id, suds_response_to_dict(cs_soap_mock().runTransaction()), basket)