diff --git a/zebra/forms.py b/zebra/forms.py index 0041320..87c42bb 100644 --- a/zebra/forms.py +++ b/zebra/forms.py @@ -22,8 +22,8 @@ def __init__(self, *args, **kwargs): super(StripePaymentForm, self).__init__(*args, **kwargs) self.fields['card_cvv'].label = "Card CVC" self.fields['card_cvv'].help_text = "Card Verification Code; see rear of card." - months = [ (m[0], u'%02d - %s' % (m[0], unicode(m[1]))) - for m in sorted(MONTHS.iteritems()) ] + months = [(m[0], u'%02d - %s' % (m[0], unicode(m[1]))) + for m in sorted(MONTHS.iteritems())] self.fields['card_expiry_month'].choices = months card_number = forms.CharField(required=False, max_length=20, @@ -34,3 +34,18 @@ def __init__(self, *args, **kwargs): choices=MONTHS.iteritems()) card_expiry_year = forms.ChoiceField(required=False, widget=NoNameSelect(), choices=options.ZEBRA_CARD_YEARS_CHOICES) + + +class StripePaymentAddressForm(StripePaymentForm): + card_name = forms.CharField(required=False, max_length=100, + widget=NoNameTextInput()) + card_address_line1 = forms.CharField(required=False, max_length=255, + widget=NoNameTextInput()) + card_address_line2 = forms.CharField(required=False, max_length=255, + widget=NoNameTextInput()) + card_address_zip = forms.CharField(required=False, max_length=255, + widget=NoNameTextInput()) + card_address_state = forms.CharField(required=False, max_length=255, + widget=NoNameTextInput()) + card_address_country = forms.CharField(required=False, max_length=255, + widget=NoNameTextInput()) diff --git a/zebra/static/zebra/card-form.js b/zebra/static/zebra/card-form.js index 139d0aa..4d65b47 100644 --- a/zebra/static/zebra/card-form.js +++ b/zebra/static/zebra/card-form.js @@ -1,33 +1,46 @@ $(function() { - $("#id_card_number").parents("form").submit(function() { - if ( $("#id_card_number").is(":visible")) { - var form = this; - var card = { - number: $("#id_card_number").val(), - expMonth: $("#id_card_expiry_month").val(), - expYear: $("#id_card_expiry_year").val(), - cvc: $("#id_card_cvv").val() - }; + $("#id_card_number").parents("form").submit(function() { + if ( $("#id_card_number").is(":visible")) { + var form = this; + var card = { + number: $("#id_card_number").val(), + expMonth: $("#id_card_expiry_month").val(), + expYear: $("#id_card_expiry_year").val(), + cvc: $("#id_card_cvv").val() + }; - Stripe.createToken(card, function(status, response) { - if (status === 200) { - // console.log(status, response); - $("#credit-card-errors").hide(); - $("#id_last_4_digits").val(response.card.last4); - $("#id_stripe_token").val(response.id); - form.submit(); - $("button[type=submit]").attr("disabled","disabled").html("Submitting..") - } else { - $(".payment-errors").text(response.error.message); - $("#user_submit").attr("disabled", false); - } - }); - - return false; - - } - - return true - - }); + // Check if the address fields are present + if ( $("#id_card_address_line1").is(":visible")) { + // Extend card with the address attributes + $.extend(card, { + name: $("#id_card_name").val(), + address_line1: $("#id_card_address_line1").val(), + address_line2: $("#id_card_address_line2").val(), + address_zip: $("#id_card_address_zip").val(), + address_state: $("#id_card_address_state").val(), + address_country: $("#id_card_address_country").val() + }); + } + + Stripe.createToken(card, function(status, response) { + if (status === 200) { + // console.log(status, response); + $("#credit-card-errors").hide(); + $("#id_last_4_digits").val(response.card.last4); + $("#id_stripe_token").val(response.id); + form.submit(); + $("button[type=submit]").attr("disabled","disabled").html("Submitting.."); + } else { + $(".payment-errors").text(response.error.message); + $("#user_submit").attr("disabled", false); + } + }); + + return false; + + } + + return true; + + }); });