diff options
author | Michał Ociepka <michal@ociepka.info> | 2013-11-08 17:11:42 +0100 |
---|---|---|
committer | Michał Ociepka <michal@ociepka.info> | 2013-11-08 17:11:42 +0100 |
commit | ffe9c2c87c3d9d9c1fad29a6bd45d7194dee7ae6 (patch) | |
tree | 73b344a1a59090e58d6edd0f32ed985fa066f1f2 /payments/stripe | |
parent | 80e5611758a94c8a614c7e22d3043a2dda2ef7f3 (diff) | |
download | django-payments-taler-ffe9c2c87c3d9d9c1fad29a6bd45d7194dee7ae6.tar.gz django-payments-taler-ffe9c2c87c3d9d9c1fad29a6bd45d7194dee7ae6.tar.bz2 django-payments-taler-ffe9c2c87c3d9d9c1fad29a6bd45d7194dee7ae6.zip |
Reject payment if user post empty token data
Closing widget window post empty data
Diffstat (limited to 'payments/stripe')
-rw-r--r-- | payments/stripe/forms.py | 8 | ||||
-rw-r--r-- | payments/stripe/widgets.py | 11 |
2 files changed, 13 insertions, 6 deletions
diff --git a/payments/stripe/forms.py b/payments/stripe/forms.py index 890cf10..92a33cb 100644 --- a/payments/stripe/forms.py +++ b/payments/stripe/forms.py @@ -4,14 +4,20 @@ import stripe from ..forms import PaymentForm as BasePaymentForm from .widgets import StripeWidget +from . import RedirectNeeded class PaymentForm(BasePaymentForm): + charge = None + def __init__(self, *args, **kwargs): super(PaymentForm, self).__init__(*args, **kwargs) widget = StripeWidget(provider=self.provider, payment=self.payment) self.fields['stripe_token'] = forms.CharField(widget=widget) + if self.is_bound and not self.data.get('stripe_token'): + self.payment.change_status('rejected') + raise RedirectNeeded(self.payment.get_failure_url()) def clean(self): data = self.cleaned_data @@ -24,7 +30,7 @@ class PaymentForm(BasePaymentForm): amount=self.payment.total * 100, currency=self.payment.currency, card=data['stripe_token'], - description=u"%s %s" % (self.payment.billing_last_name, + description=u'%s %s' % (self.payment.billing_last_name, self.payment.billing_first_name) ) except stripe.CardError, e: diff --git a/payments/stripe/widgets.py b/payments/stripe/widgets.py index 2422505..c283577 100644 --- a/payments/stripe/widgets.py +++ b/payments/stripe/widgets.py @@ -5,17 +5,18 @@ from django.utils.translation import ugettext_lazy as _ class StripeWidget(HiddenInput): def __init__(self, provider, payment, *args, **kwargs): - attrs = kwargs.get('attrs') or {} + attrs = kwargs.get('attrs', {}) kwargs['attrs'] = { 'id': 'stripe-id', 'data-key': provider.public_key, - 'data-description': payment.description or _("Total payment"), + 'data-description': payment.description or _('Total payment'), + # Stripe accepts cents 'data-amount': payment.total * 100, - 'data-currency': payment.currency, + 'data-currency': payment.currency } kwargs['attrs'].update(attrs) super(StripeWidget, self).__init__(*args, **kwargs) class Media: - js = ["https://checkout.stripe.com/v2/checkout.js", - "payments/js/stripe.js"] + js = ['https://checkout.stripe.com/v2/checkout.js', + 'js/payments/stripe.js'] |