def test_created_order(self):
        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order'
                   ) as get_order:
            with patch(
                    'paypal.express_checkout.gateway.PaymentProcessor.capture_order'
            ) as capture_order:

                get_order.return_value = construct_object(
                    'Result', GET_ORDER_RESULT_DATA)
                capture_order.return_value = construct_object(
                    'Result', CAPTURE_ORDER_RESULT_DATA_MINIMAL)

                self.client.post(self.url, self.payload)

                order = Order.objects.all().first()
                assert order.total_incl_tax == D('19.99')
                assert order.guest_email == '*****@*****.**'

                address = order.shipping_address
                assert address.line1 == '221B Baker Street'
                assert address.line4 == 'London'
                assert address.country.iso_3166_1_a2 == 'GB'
                assert address.postcode == 'WC2N 5DU'

                self.txn.refresh_from_db()
                assert self.txn.capture_id == '2D6171889X1782919'
                assert self.txn.authorization_id is None
                assert self.txn.refund_id is None
                assert self.txn.payer_id == '0000000000001'
                assert self.txn.email == '*****@*****.**'
                assert self.txn.address_full_name == 'Sherlock Holmes'
                assert self.txn.address is not None
Esempio n. 2
0
    def test_create_order_when_bayer_pays_on_paypal_no_shipping(self):
        for lines in self.basket.lines.all():
            lines.product.product_class.requires_shipping = False
            lines.product.product_class.save()

        url = reverse('express-checkout-handle-order', kwargs={'basket_id': self.basket.id})
        query_string = urlencode({'PayerID': '0000000000001', 'token': '4MW805572N795704B'})
        url_with_query_string = f'{url}?{query_string}'

        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order') as get_order:
            with patch('paypal.express_checkout.gateway.PaymentProcessor.capture_order') as capture_order:

                get_order.return_value = construct_object('Result', GET_ORDER_RESULT_NO_SHIPPING_DATA)
                capture_order.return_value = construct_object('Result', CAPTURE_ORDER_RESULT_NO_SHIPPING_DATA_MINIMAL)

                self.client.get(url_with_query_string)

                order = Order.objects.all().first()
                assert order.total_incl_tax == D('19.99')
                assert order.guest_email == '*****@*****.**'
                assert order.shipping_address is None

                self.txn.refresh_from_db()
                assert self.txn.capture_id == '2D6171889X1782919'
                assert self.txn.authorization_id is None
                assert self.txn.refund_id is None
                assert self.txn.payer_id == '0000000000001'
                assert self.txn.email == '*****@*****.**'
                assert self.txn.address_full_name == ''
                assert self.txn.address == ''
Esempio n. 3
0
    def test_create_order_when_bayer_pays_on_paypal(self):
        url = reverse('express-checkout-handle-order', kwargs={'basket_id': self.basket.id})
        query_string = urlencode({'PayerID': '0000000000001', 'token': '4MW805572N795704B'})
        url_with_query_string = f'{url}?{query_string}'

        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order') as get_order:
            with patch('paypal.express_checkout.gateway.PaymentProcessor.capture_order') as capture_order:

                get_order.return_value = construct_object('Result', GET_ORDER_RESULT_DATA)
                capture_order.return_value = construct_object('Result', CAPTURE_ORDER_RESULT_DATA_MINIMAL)

                self.client.get(url_with_query_string)

                order = Order.objects.all().first()
                assert order.total_incl_tax == D('19.99')
                assert order.guest_email == '*****@*****.**'

                address = order.shipping_address
                assert address.line1 == '221B Baker Street'
                assert address.line4 == 'London'
                assert address.country.iso_3166_1_a2 == 'GB'
                assert address.postcode == 'WC2N 5DU'

                self.txn.refresh_from_db()
                assert self.txn.capture_id == '2D6171889X1782919'
                assert self.txn.authorization_id is None
                assert self.txn.refund_id is None
                assert self.txn.payer_id == '0000000000001'
                assert self.txn.email == '*****@*****.**'
                assert self.txn.address_full_name == 'Sherlock Holmes'
                assert self.txn.address is not None
Esempio n. 4
0
    def test_created_order_no_shipping(self):
        for lines in self.basket.lines.all():
            lines.product.product_class.requires_shipping = False
            lines.product.product_class.save()

        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order') as get_order:
            with patch('paypal.express_checkout.gateway.PaymentProcessor.capture_order') as capture_order:

                get_order.return_value = construct_object('Result', GET_ORDER_RESULT_NO_SHIPPING_DATA)
                capture_order.return_value = construct_object('Result', CAPTURE_ORDER_RESULT_NO_SHIPPING_DATA_MINIMAL)

                self.client.post(self.url, self.payload)

                order = Order.objects.all().first()
                assert order.total_incl_tax == D('19.99')
                assert order.guest_email == '*****@*****.**'
                assert order.shipping_address is None

                self.txn.refresh_from_db()
                assert self.txn.capture_id == '2D6171889X1782919'
                assert self.txn.authorization_id is None
                assert self.txn.refund_id is None
                assert self.txn.payer_id == '0000000000001'
                assert self.txn.email == '*****@*****.**'
                assert self.txn.address_full_name == ''
                assert self.txn.address == ''
Esempio n. 5
0
    def test_nonempty_basket_redirects_to_paypal(self):
        order_approve_url = 'https://www.sandbox.paypal.com/checkoutnow?token=4MW805572N795704B'

        with patch('paypal.express_checkout.gateway.PaymentProcessor.create_order') as create_order:
            create_order.return_value = construct_object('Result', CREATE_ORDER_RESULT_DATA_MINIMAL)

            self.add_product_to_basket()
            response = self.client.get(self.url)
            assert response.url == order_approve_url
Esempio n. 6
0
    def test_refund_order(self):
        with patch('paypal.express_checkout.facade.PaymentProcessor.refund_order') as mocked_refund_order:
            mocked_refund_order.return_value = construct_object('Result', REFUND_ORDER_DATA_MINIMAL)

            refund_order('4MW805572N795704B')

            self.txn.refresh_from_db()
            assert self.txn.refund_id == '0SM71185A67927728'

            mocked_refund_order.assert_called_once_with('45315376249711632', D('0.99'), 'GBP')
Esempio n. 7
0
    def test_paypal_error(self):
        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order') as get_order:
            with patch('paypal.express_checkout.gateway.PaymentProcessor.capture_order') as capture_order:

                get_order.return_value = construct_object('Result', GET_ORDER_RESULT_DATA)
                capture_order.side_effect = HttpError(message='Error message', status_code=404, headers=None)

                response = self.client.post(self.url, self.payload)
                expected_message = 'A problem occurred during payment capturing - please try again later'
                assert expected_message in response.content.decode()
Esempio n. 8
0
    def test_context(self):
        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order') as get_order:
            get_order.return_value = construct_object('Result', GET_ORDER_RESULT_DATA)

            response = self.client.get(self.url_with_query_string, follow=True)

            context = response.context
            assert D('19.99') == context['paypal_amount']
            assert 'Royal Mail Signed For™ 2nd Class' == context['shipping_method'].name
            assert 'uk_rm_2ndrecorded' == context['shipping_method'].code

            keys = ('shipping_address', 'shipping_method', 'payer_id', 'token', 'paypal_user_email', 'paypal_amount')
            for k in keys:
                assert k in context, f'{k} not in context'
    def test_created_order(self):
        with patch('paypal.express_checkout.gateway.PaymentProcessor.get_order'
                   ) as get_order:
            with patch(
                    'paypal.express_checkout.gateway.PaymentProcessor.capture_order'
            ) as capture_order:

                get_order.return_value = construct_object(
                    'Result', GET_ORDER_RESULT_DATA)
                capture_order.return_value = construct_object(
                    'Result', CAPTURE_ORDER_RESULT_DATA_MINIMAL)

                self.client.post(self.url, self.payload)

                order = Order.objects.all().first()
                assert order.total_incl_tax == D('9.99')
                assert order.guest_email == '*****@*****.**'

                address = order.shipping_address
                assert address.line1 == '221B Baker Street'
                assert address.line4 == 'London'
                assert address.country.iso_3166_1_a2 == 'GB'
                assert address.postcode == 'WC2N 5DU'