Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for iOS 7's save credit card modal #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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;

});
});