Beispiel #1
0
 def test_provider_raises_redirect_needed_when_token_does_not_exist(self):
     payment = Payment()
     provider = StripeProvider(
         name='Example.com store',
         secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
     data = {}
     with self.assertRaises(RedirectNeeded) as exc:
         provider.get_form(payment, data)
         self.assertEqual(exc.args[0], payment.get_failure_url())
     self.assertEqual(payment.status, 'rejected')
Beispiel #2
0
 def test_provider_detect_already_processed_payment(self):
     payment = Payment()
     payment.transaction_id = 'existing_transaction_id'
     provider = StripeProvider(
         name='Example.com store',
         secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
     data = {'stripeToken': 'abcd'}
     with mock_stripe_Charge_create():
         with mock_stripe_Charge_retrieve():
             form = provider.get_form(payment, data=data)
             msg = 'This payment has already been processed.'
             self.assertEqual(form.errors['__all__'][0], msg)
Beispiel #3
0
 def test_provider_raises_redirect_needed_on_success(self):
     payment = Payment()
     provider = StripeProvider(
         name='Example.com store',
         secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
     data = {'stripeToken': 'abcd'}
     with patch('stripe.Charge.create'):
         with self.assertRaises(RedirectNeeded) as exc:
             provider.get_form(payment, data)
             self.assertEqual(exc.args[0], payment.get_success_url())
     self.assertEqual(payment.status, 'confirmed')
     self.assertEqual(payment.captured_amount, payment.total)
Beispiel #4
0
 def test_provider_set_fraudulent_status(self):
     error_msg = 'Error message'
     payment = Payment()
     provider = StripeProvider(
         name='Example.com store',
         secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
     data = {'stripeToken': 'abcd'}
     with mock_stripe_Charge_create(error_msg=error_msg):
         with mock_stripe_Charge_retrieve(fraudulent=True):
             provider.get_form(payment, data=data)
     self.assertEqual(payment.status, 'error')
     self.assertEqual(payment.fraud_status, 'reject')
     self.assertEqual(payment.captured_amount, 0)
Beispiel #5
0
 def test_form_contains_stripe_script(self):
     payment = Payment()
     store_name = 'Test store'
     provider = StripeProvider(
         name=store_name,
         secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
     form = provider.get_form(payment)
     self.assertTrue(
         '<script class="stripe-button" data-amount="10000" '
         'data-currency="USD" data-description="payment" data-image="" '
         'data-key="%s" data-name="%s" '
         'src="https://checkout.stripe.com/checkout.js"></script>' % (
             PUBLIC_KEY, store_name)
         in str(form))
Beispiel #6
0
    def test_provider_shows_validation_error_message(self):
        error_msg = 'Error message'

        payment = Payment()
        provider = StripeProvider(
            name='Example.com store',
            secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
        data = {'stripeToken': 'abcd'}
        with mock_stripe_Charge_create(error_msg=error_msg):
            with mock_stripe_Charge_retrieve():
                form = provider.get_form(payment, data=data)
                self.assertEqual(form.errors['__all__'][0], error_msg)
        self.assertEqual(payment.status, 'error')
        self.assertEqual(payment.message, error_msg)
        self.assertEqual(payment.captured_amount, 0)