Stripe on an AngularJs website with Apple/Android pay -
i trying set stripe on website take credit card payments. have managed stripe pay working this:
function directive() { return { restrict: 'a', controller: 'stripepaycontroller', controlleras: 'controller', bindtocontroller: true, templateurl: 'app/directives/stripe-pay/stripe-pay.html' }; }; function controller(stripepayservice) { var self = this; // method binding self.checkout = stripepayservice.checkout; init(); ////////////////////////////////////////////////// function init() { stripepayservice.configure(); }; }; function service($rootscope, $localstorage, $q, $document, paymentservice) { var handler; return { configure: configure, checkout: checkout }; ////////////////////////////////////////////////// function configure() { // load our script loadscript().then(function () { handler = stripecheckout.configure({ key: 'my-code', locale: 'auto', token: function (token) { token.transaction = transaction(); paymentservice.create({ token: token.id }).then(function (response) { var authorizationdata = $rootscope.authorizationdata; authorizationdata.stripecardid = response.stripecardid; authorizationdata.stripecustomerid = response.stripecustomerid; authorizationdata.stripesubscriptionid = response.stripesubscriptionid; $localstorage.set('authorizationdata', angular.tojson(authorizationdata)); }); } }); }); }; function checkout(e) { handler.open(transaction()); e.preventdefault(); }; function transaction() { var email = $rootscope.authorizationdata.username; return { name: 'acme ltd', description: 'results', email: email, zipcode: false, currency: 'gbp', amount: 199 }; }; function loadscript() { // create our script var deferred = $q.defer(); var doc = $document[0]; var script = doc.createelement('script'); // set url script.src = 'https://checkout.stripe.com/checkout.js'; // bind our methods script.onload = function () { deferred.resolve(); }; // bind our methods script.onreadystatechange = function () { var rs = this.readystate; if (rs === 'loaded' || rs === 'complete') deferred.resolve(); }; // bind our methods script.onerror = function () { deferred.reject(new error('unable load checkout.js')); }; // head var container = doc.getelementsbytagname('head')[0]; // append our script our page container.appendchild(script); // return our promise return deferred.promise; }; };
this seems work fine. setting apply pay seems lot more complicated. have angularjs code have used before might able me?
stripe great job explaining how in documentation. use vanilla javascript, should able convert angular pretty easily.
Comments
Post a Comment