Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions zebra/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
73 changes: 43 additions & 30 deletions zebra/static/zebra/card-form.js
Original file line number Diff line number Diff line change
@@ -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;

});
});