diff --git a/composer.json b/composer.json index 8be3e84..b7b21fa 100755 --- a/composer.json +++ b/composer.json @@ -2,24 +2,21 @@ "name": "pmclain/module-stripe", "description": "Stripe Payments for Magento 2", "type": "magento2-module", - "license": [ - "OSL-3.0", - "ASL-3.0" - ], + "license": "GPL-3.0", "require": { "php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0", - "magento/framework": "~100.0.0|~100.1.0", - "magento/module-config": "~100.0.0|~100.1.0", - "magento/module-payment": "~100.0.0|~100.1.0", - "magento/module-checkout": "~100.0.0|~100.1.0", - "magento/module-sales": "~100.0.0|~100.1.0", - "magento/module-backend": "~100.0.0|~100.1.0", - "magento/module-customer": "~100.0.0|~100.1.0", + "magento/framework": "~100.1.0|~100.2.0", + "magento/module-config": "~100.1.0|~100.2.0", + "magento/module-payment": "~100.1.0|~100.2.0", + "magento/module-checkout": "~100.1.0|~100.2.0", + "magento/module-sales": "~100.1.0|~100.2.0", + "magento/module-backend": "~100.1.0|~100.2.0", + "magento/module-customer": "~100.1.0|~100.2.0", "magento/module-catalog": "~101.0.0|~101.1.0", - "magento/module-quote": "~100.0.0|~100.1.0", - "magento/module-ui": "~100.0.0|~100.1.0", - "magento/module-vault": "100.1.*|100.2.*", - "stripe/stripe-php": "3.7.0" + "magento/module-quote": "~100.1.0|~100.2.0", + "magento/module-ui": "~100.1.0|~100.2.0", + "magento/module-vault": "~100.1.0|~100.2.0", + "stripe/stripe-php": "~5.2.0" }, "autoload": { "files": [ diff --git a/view/adminhtml/templates/form/cc.phtml b/view/adminhtml/templates/form/cc.phtml index c84095f..bd05fd1 100644 --- a/view/adminhtml/templates/form/cc.phtml +++ b/view/adminhtml/templates/form/cc.phtml @@ -23,73 +23,9 @@ $ccExpYear = $block->getInfoData('cc_exp_year'); ?> diff --git a/view/adminhtml/web/js/stripe.js b/view/adminhtml/web/js/stripe.js index c349688..d4116ba 100644 --- a/view/adminhtml/web/js/stripe.js +++ b/view/adminhtml/web/js/stripe.js @@ -18,7 +18,9 @@ define([ active: false, scriptLoaded: false, stripe: null, - selectedCardType: null, + stripeCardElement: null, + stripeCard: null, + token: null, imports: { onActiveChange: 'active' } @@ -35,8 +37,7 @@ define([ this._super() .observe([ 'active', - 'scriptLoaded', - 'selectedCardType' + 'scriptLoaded' ]); // re-init payment method events @@ -47,7 +48,6 @@ define([ domObserver.get('#' + self.container, function () { if (self.scriptLoaded()) { self.$selector.off('submit'); - self.initStripe(); } }); @@ -97,29 +97,22 @@ define([ var state = self.scriptLoaded; $('body').trigger('processStart'); - require(['https://js.stripe.com/v2/'], function () { + require(['https://js.stripe.com/v3/'], function () { state(true); - self.stripe = window.Stripe; - self.initStripe(); + self.stripe = window.Stripe(self.publishableKey); + self.stripeCardElement = self.stripe.elements(); + self.stripeCard = self.stripeCardElement.create('card', { + style: { + base: { + fontSize: '20px' + } + } + }); + self.stripeCard.mount('#stripe-card-element'); $('body').trigger('processStop'); }); }, - initStripe: function() { - var self = this; - - try { - $('body').trigger('processStart'); - - self.stripe.setPublishableKey(this.publishableKey); - - $('body').trigger('processStop'); - }catch(e) { - $('body').trigger('processStop'); - self.error(e.message); - } - }, - /** * Show alert message * @param {String} message @@ -178,22 +171,24 @@ define([ var container = $('#' + this.container); var cardInfo = { - number: container.find('#' + this.code + '_cc_number').val(), - exp_month: container.find('#' + this.code + '_expiration').val(), - exp_year: container.find('#' + this.code + '_expiration_yr').val(), - cvc: container.find('#' + this.code + '_cc_cid').val() + number: container.find('#' + self.code + '_cc_number').val(), + + exp_month: container.find('#' + self.code + '_expiration').val(), + exp_year: container.find('#' + self.code + '_expiration_yr').val(), + cvc: container.find('#' + self.code + '_cc_cid').val() }; var defer = $.Deferred(); - this.stripe.card.createToken(cardInfo, function(status, response) { + self.stripe.createToken(self.stripeCard).then(function(response) { if (response.error) { - defer.reject(response.error.message); + deffer.reject(response.error.message); }else { - container.find('#' + self.code + '_cc_number').val(''); - container.find('#' + self.code + '_cc_last4').val(cardInfo.number.slice(-4)); - delete cardInfo.number; - $('#' + self.container).find('#' + self.code + '_cc_token').val(response.id); + var card = response.token.card; + container.find('#' + self.code + '_expiration').val(card.exp_month); + container.find('#' + self.code + '_expiration_yr').val(card.exp_year); + container.find('#' + self.code + '_cc_type').val(card.brand); + container.find('#' + self.code + '_cc_token').val(response.token.id); defer.resolve(); } }); diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index bffff0d..91df5c9 100755 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -1,7 +1,7 @@ var config = { map: { '*': { - stripejs: 'https://js.stripe.com/v2/' + stripejs: 'https://js.stripe.com/v3/' } } }; \ No newline at end of file diff --git a/view/frontend/web/js/view/payment/method-renderer/pmclain_stripe.js b/view/frontend/web/js/view/payment/method-renderer/pmclain_stripe.js index 3d12974..46bfbb9 100755 --- a/view/frontend/web/js/view/payment/method-renderer/pmclain_stripe.js +++ b/view/frontend/web/js/view/payment/method-renderer/pmclain_stripe.js @@ -15,16 +15,33 @@ define( return Component.extend({ defaults: { - template: 'Pmclain_Stripe/payment/form' + template: 'Pmclain_Stripe/payment/form', + stripe: null, + stripeCardElement: null, + stripeCard: null, + token: null }, initialize: function() { this._super(); - Stripe.setPublishableKey(this.getPublishableKey()); + this.stripe = Stripe(this.getPublishableKey()); this.vaultEnabler = new VaultEnabler(); this.vaultEnabler.setPaymentCode(this.getVaultCode()); }, + initStripeElement: function() { + var self = this; + self.stripeCardElement = self.stripe.elements(); + self.stripeCard = self.stripeCardElement.create('card', { + style: { + base: { + fontSize: '20px' + } + } + }); + self.stripeCard.mount('#stripe-card-element'); + }, + placeOrder: function(data, event) { var self = this, placeOrder; @@ -64,20 +81,13 @@ define( createToken: function() { var self = this; - var cardInfo = { - number: this.creditCardNumber(), - exp_month: this.creditCardExpMonth(), - exp_year: this.creditCardExpYear(), - cvc: this.creditCardVerificationNumber() - }; - var deffer = $.Deferred(); - Stripe.card.createToken(cardInfo, function(status, response) { + self.stripe.createToken(self.stripeCard).then(function(response) { if (response.error) { deffer.reject(response.error.message); }else { - self.token = response.id; + self.token = response.token; deffer.resolve(); } }); @@ -96,9 +106,15 @@ define( getData: function() { var data = this._super(); - data.additional_data.cc_last4 = this.creditCardNumber().slice(-4); - delete data.additional_data.cc_number; - data.additional_data.cc_token = this.token; + if (this.token) { + var card = this.token.card; + + data.additional_data.cc_exp_month = card.exp_month; + data.additional_data.cc_exp_year = card.exp_year; + data.additional_data.cc_last4 = card.last4; + data.additional_data.cc_type = card.brand; + data.additional_data.cc_token = this.token.id; + } this.vaultEnabler.visitAdditionalData(data); diff --git a/view/frontend/web/template/payment/form.html b/view/frontend/web/template/payment/form.html index aaa1bae..a13850b 100755 --- a/view/frontend/web/template/payment/form.html +++ b/view/frontend/web/template/payment/form.html @@ -17,7 +17,9 @@
- +
+ +