Beispiel #1
0
    def test_paypal(self):
        # TODO: This checks the most simple and perfect payment that could
        # happen, but not errors or other/invalid IPN

        payment = Payment.objects.create(
            user=self.user,
            time=timedelta(days=30),
            backend='paypal',
            amount=300
        )

        settings = dict(
            TEST=True,
            TITLE='Test Title',
            CURRENCY='EUR',
            ADDRESS='*****@*****.**',
        )

        with self.settings(ROOT_URL='root'):
            backend = PaypalBackend(settings)
            redirect = backend.new_payment(payment)

        self.assertIsInstance(redirect, HttpResponseRedirect)

        host, params = redirect.url.split('?', 1)
        params = parse_qs(params)

        expected_notify_url = 'root/payments/callback/paypal/%d' % payment.id
        expected_return_url = 'root/payments/view/%d' % payment.id
        expected_cancel_url = 'root/payments/cancel/%d' % payment.id

        self.assertEqual(params['cmd'][0], '_xclick')
        self.assertEqual(params['notify_url'][0], expected_notify_url)
        self.assertEqual(params['return'][0], expected_return_url)
        self.assertEqual(params['cancel_return'][0], expected_cancel_url)
        self.assertEqual(params['business'][0], '*****@*****.**')
        self.assertEqual(params['currency_code'][0], 'EUR')
        self.assertEqual(params['amount'][0], '3.00')
        self.assertEqual(params['item_name'][0], 'Test Title')

        # Replace PaypalBackend.verify_ipn to not call the PayPal API
        # we will assume the IPN is authentic
        backend.verify_ipn = lambda request: True

        ipn_url = '/payments/callback/paypal/%d' % payment.id
        ipn_request = RequestFactory().post(
            ipn_url,
            content_type='application/x-www-form-urlencoded',
            data=PAYPAL_IPN_TEST)
        r = backend.callback(payment, ipn_request)

        self.assertTrue(r)
        self.assertEqual(payment.status, 'confirmed')
        self.assertEqual(payment.paid_amount, 300)
        self.assertEqual(payment.backend_extid, '61E67681CH3238416')
Beispiel #2
0
    def test_paypal(self):
        # TODO: This checks the most simple and perfect payment that could
        # happen, but not errors or other/invalid IPN

        payment = Payment.objects.create(user=self.user,
                                         time=timedelta(days=30),
                                         backend_id='paypal',
                                         amount=300)

        settings = dict(
            TEST=True,
            TITLE='Test Title',
            CURRENCY='EUR',
            ADDRESS='*****@*****.**',
        )

        with self.settings(ROOT_URL='root'):
            backend = PaypalBackend(settings)
            redirect = backend.new_payment(payment)

        self.assertIsInstance(redirect, HttpResponseRedirect)

        host, params = redirect.url.split('?', 1)
        params = parse_qs(params)

        expected_notify_url = 'root/payments/callback/paypal/%d' % payment.id
        expected_return_url = 'root/payments/view/%d' % payment.id
        expected_cancel_url = 'root/payments/cancel/%d' % payment.id

        self.assertEqual(params['cmd'][0], '_xclick')
        self.assertEqual(params['notify_url'][0], expected_notify_url)
        self.assertEqual(params['return'][0], expected_return_url)
        self.assertEqual(params['cancel_return'][0], expected_cancel_url)
        self.assertEqual(params['business'][0], '*****@*****.**')
        self.assertEqual(params['currency_code'][0], 'EUR')
        self.assertEqual(params['amount'][0], '3.00')
        self.assertEqual(params['item_name'][0], 'Test Title')

        # Replace PaypalBackend.verify_ipn to not call the PayPal API
        # we will assume the IPN is authentic
        backend.verify_ipn = lambda request: True

        ipn_url = '/payments/callback/paypal/%d' % payment.id
        ipn_request = RequestFactory().post(
            ipn_url,
            content_type='application/x-www-form-urlencoded',
            data=PAYPAL_IPN_TEST)
        r = backend.callback(payment, ipn_request)

        self.assertTrue(r)
        self.assertEqual(payment.status, 'confirmed')
        self.assertEqual(payment.paid_amount, 300)
        self.assertEqual(payment.backend_extid, '61E67681CH3238416')
Beispiel #3
0
    def test_paypal_ipn_error(self):
        payment = Payment.objects.create(
            user=self.user,
            time=timedelta(days=30),
            backend='paypal',
            amount=300
        )

        settings = dict(
            TEST=True,
            TITLE='Test Title',
            CURRENCY='EUR',
            ADDRESS='*****@*****.**',
        )

        with self.settings(ROOT_URL='root'):
            backend = PaypalBackend(settings)
            redirect = backend.new_payment(payment)

        self.assertIsInstance(redirect, HttpResponseRedirect)

        host, params = redirect.url.split('?', 1)
        params = parse_qs(params)

        # Replace PaypalBackend.verify_ipn to not call the PayPal API
        # we will assume the IPN is authentic
        backend.verify_ipn = lambda request: True

        ipn_url = '/payments/callback/paypal/%d' % payment.id
        ipn_request = RequestFactory().post(
            ipn_url,
            content_type='application/x-www-form-urlencoded',
            data=PAYPAL_IPN_TEST)
        r = backend.callback(payment, ipn_request)

        self.assertTrue(r)
        self.assertEqual(payment.status, 'confirmed')
        self.assertEqual(payment.paid_amount, 300)
        self.assertEqual(payment.backend_extid, '61E67681CH3238416')
Beispiel #4
0
    def test_paypal_ipn_error(self):
        payment = Payment.objects.create(user=self.user,
                                         time=timedelta(days=30),
                                         backend_id='paypal',
                                         amount=300)

        settings = dict(
            TEST=True,
            TITLE='Test Title',
            CURRENCY='EUR',
            ADDRESS='*****@*****.**',
        )

        with self.settings(ROOT_URL='root'):
            backend = PaypalBackend(settings)
            redirect = backend.new_payment(payment)

        self.assertIsInstance(redirect, HttpResponseRedirect)

        host, params = redirect.url.split('?', 1)
        params = parse_qs(params)

        # Replace PaypalBackend.verify_ipn to not call the PayPal API
        # we will assume the IPN is authentic
        backend.verify_ipn = lambda request: True

        ipn_url = '/payments/callback/paypal/%d' % payment.id
        ipn_request = RequestFactory().post(
            ipn_url,
            content_type='application/x-www-form-urlencoded',
            data=PAYPAL_IPN_TEST)
        r = backend.callback(payment, ipn_request)

        self.assertTrue(r)
        self.assertEqual(payment.status, 'confirmed')
        self.assertEqual(payment.paid_amount, 300)
        self.assertEqual(payment.backend_extid, '61E67681CH3238416')