def setUp(self): super(PaymentsDocdataAdapterRefundTestCase, self).setUp() self.order_payment = OrderPaymentFactory.create( status='started', payment_method='docdataIdeal', integration_data={'default_pm': 'ideal'}, order=OrderFactory.create(status='locked')) DocdataPaymentFactory.create(order_payment=self.order_payment, payment_cluster_key='123-4', default_pm='ideal', total_gross_amount=100, status='settled') self.adapter = DocdataPaymentAdapter(self.order_payment)
def test_payment_country_without_profile(self, mock_client): # For anonymous donations the default from settings should be used. instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} order_payment = OrderPaymentFactory( payment_method='docdataCreditcard', integration_data={'default_pm': 'mastercard'}) self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'BG')
class PaymentsDocdataAdapterRefundTestCase(BluebottleTestCase, FsmTestMixin): def setUp(self): super(PaymentsDocdataAdapterRefundTestCase, self).setUp() self.order_payment = OrderPaymentFactory.create( status='started', payment_method='docdataIdeal', integration_data={'default_pm': 'ideal'}, order=OrderFactory.create(status='locked')) DocdataPaymentFactory.create(order_payment=self.order_payment, payment_cluster_key='123-4', default_pm='ideal', total_gross_amount=100, status='settled') self.adapter = DocdataPaymentAdapter(self.order_payment) def test_refund(self, mock_client): refund_reply = bunchify({'refundSuccess': True}) with patch.object(DocdataClientMock.service, 'refund', return_value=refund_reply) as refund_mock: self.adapter.refund_payment() self.assertEqual(refund_mock.call_count, 1) self.assertEqual(refund_mock.call_args[0][1], 'test-id') def test_refund_failure(self, mock_client): refund_reply = bunchify({ 'refundError': { 'error': { '_code': 'some code', 'value': 'some value' } } }) with patch.object(DocdataClientMock.service, 'refund', return_value=refund_reply): with self.assertRaises(DocdataPaymentStatusException): self.adapter.refund_payment()
def test_payment_country_without_user(self, mock_client): # For donations without users some defaults should be used instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} order_payment = OrderPaymentFactory( payment_method='docdataCreditcard', integration_data={'default_pm': 'ideal'}) order_payment.order.user = None order_payment.order.save() self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.first_name, 'Nomen') self.assertEqual(payment.last_name, 'Nescio')
def test_payment_country_with_profile_without_country(self, mock_client): # If no country specified in profile the default from settings should be used instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} user = BlueBottleUserFactory() order_payment = OrderPaymentFactory( user=user, payment_method='docdataCreditcard', integration_data={'default_pm': 'mastercard'}) order_payment.order.user = user self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'BG')
def test_ideal_payment_country_with_profile(self, mock_client): # Even a yankees should get NL for country when selecting iDEAL. instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} user = BlueBottleUserFactory() user.address.country = CountryFactory(name='Merica', alpha2_code='US') order_payment = OrderPaymentFactory( user=user, payment_method='docdataIdeal', integration_data={'default_pm': 'ideal'}) order_payment.order.user = user self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'NL')
def test_payment_country_with_profile(self, mock_client): # When a country is set in profile, that should be used. instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} user = BlueBottleUserFactory() user.address.country = CountryFactory(name='Netherlands', alpha2_code='NL') order_payment = OrderPaymentFactory( user=user, payment_method='docdataCreditcard', integration_data={'default_pm': 'mastercard'}) order_payment.order.user = user self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'NL')