Skip to content

Commit

Permalink
Fix for iOS 7's save credit card modal
Browse files Browse the repository at this point in the history
See GoodCloud#36 - this is the
fix for it that worked for me.
  • Loading branch information
BrendanBerkley committed Apr 25, 2014
1 parent 1ac291e commit c60e0ea
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions zebra/static/zebra/card-form.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@

$(function() {
$("#id_card_number").parents("form").submit(function() {
if ( $("#id_card_number").is(":visible")) {
var iOSCheck = false;
var cardField = $("#id_card_number");

if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { // This could be more elegant; should sniff iOS 7.x specifically
iOSCheck = true;
}

if (iOSCheck == true) {
$("#id_card_number").attr('id','workaround-one'); // Rename ID. Nondescript name.
$('#workaround-one').attr('autocomplete','off'); // Turn off autocomplete

$("#w1-label").after('<div class="simulate-label">Credit Card</div>'); // Kill the label. Append the text,
$("#w1-label").remove(); // Then remove the label. That way the text in the label doesn't link to the CC field.

cardField = $('#workaround-one'); // Redefine our credit card field so we can reference it below.
}

cardField.parents("form").submit(function() {
if ( cardField.is(":visible") ) {
var form = this;
var card = {
number: $("#id_card_number").val(),
number: cardField.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);
//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..")

$("button[type=submit]").attr("disabled","disabled").html("Submitting..")
} else {
$(".payment-errors").text(response.error.message);
$("#user_submit").attr("disabled", false);
Expand All @@ -27,7 +46,7 @@ $(function() {

}

return true
return true;

});
});

0 comments on commit c60e0ea

Please sign in to comment.