Last active
January 3, 2018 19:27
-
-
Save mootrichard/0d186f54ee0cbae93665978a5b827ba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AutoForm.addHooks("square-payment-form", { | |
onSubmit: function (doc) { | |
submitting = true; | |
const template = this.template; | |
hidePaymentAlert(); | |
const form = { | |
cardNonce: doc.nonce // Here is where we're placing our nonce | |
}; | |
Meteor.subscribe("Packages", Reaction.getShopId()); | |
const packageData = Packages.findOne({ | |
name: "square-paymentmethod", | |
shopId: Reaction.getShopId() | |
}); | |
Square.authorize( | |
form, // This is where we're passing the nonce back to the server | |
{ | |
total: Cart.findOne().getTotal(), | |
currency: Shops.findOne().currency | |
}, | |
function (error, transaction) { | |
// Omitted for brevity | |
} | |
); | |
return false; | |
}, | |
beginSubmit: function () { | |
this.template.$(":input").attr("disabled", true); | |
this.template.$("#btn-complete-order").text("Submitting "); | |
return this.template.$("#btn-processing").removeClass("hidden"); | |
}, | |
endSubmit: function () { | |
if (!submitting) { | |
return uiEnd(this.template, "Complete your order"); | |
} | |
}, | |
onSuccess: function () { | |
paymentForm.destroy(); // To prevent issues if they decided to continue shopping, we destroy the form | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment