From 9a7af9ef6944764f8d4740d5216b09ca31a2e8ce Mon Sep 17 00:00:00 2001 From: Juan Pablo Buritica Date: Sat, 18 Jul 2015 22:28:13 -0400 Subject: [PATCH 1/3] [improve] ember run loop, as suggested in #17 and #18 --- app/services/stripe.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/app/services/stripe.js b/app/services/stripe.js index 5a9d9d5..70258f3 100644 --- a/app/services/stripe.js +++ b/app/services/stripe.js @@ -31,22 +31,17 @@ function debug() { function createCardToken (card) { debug('card.createToken:', card); - // manually start Ember loop - Ember.run.begin(); - return new Ember.RSVP.Promise(function (resolve, reject) { Stripe.card.createToken(card, function (status, response) { debug('card.createToken handler - status %s, response:', status, response); if (response.error) { - reject(response); - return Ember.run.end(); + return Ember.run(null, reject, response); } - resolve(response); + Ember.run(null, resolve, response); - Ember.run.end(); }); }); } @@ -74,22 +69,16 @@ function createCardTokenDeprecated(card) { function createBankAccountToken(bankAccount) { debug('bankAccount.createToken:', bankAccount); - // manually start Ember loop - Ember.run.begin(); - return new Ember.RSVP.Promise(function (resolve, reject) { Stripe.bankAccount.createToken(bankAccount, function (status, response) { debug('bankAccount.createToken handler - status %s, response:', status, response); if (response.error) { - reject(response); - return Ember.run.end(); + return Ember.run(null, reject, response); } - resolve(response); - - Ember.run.end(); + Ember.run(null, resolve, response); }); }); } From e8bd03db68f6aff026dfac5ac4a46ad0dee5ed47 Mon Sep 17 00:00:00 2001 From: Juan Pablo Buritica Date: Sat, 18 Jul 2015 22:58:16 -0400 Subject: [PATCH 2/3] [fix] breaking tests --- tests/integration/stripe-test.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/integration/stripe-test.js b/tests/integration/stripe-test.js index 79f81dd..98d1a47 100644 --- a/tests/integration/stripe-test.js +++ b/tests/integration/stripe-test.js @@ -1,6 +1,5 @@ /* global Stripe */ -import Ember from 'ember'; import { moduleFor, test } from 'ember-qunit'; import env from 'dummy/config/environment'; @@ -28,22 +27,20 @@ Stripe.setPublishableKey(env.stripe.publishableKey); test('card.createToken sets the token and returns a promise', function(assert) { var service = this.subject(); - Ember.run(function(){ - service.card.createToken(cc) - .then(function(res) { - assert.ok(res.id, 'correct token set'); - }); + return service.card.createToken(cc) + .then(function(res) { + console.log('res', res); + assert.ok(res.id, 'correct token set'); }); }); test('bankAccount.createToken sets the token and returns a promise', function(assert) { var service = this.subject(); - Ember.run(function(){ - service.bankAccount.createToken(bankAccount) - .then(function(res) { - assert.ok(res.id, 'correct token set'); - }); + return service.bankAccount.createToken(bankAccount) + .then(function(res) { + console.log('res', res); + assert.ok(res.id, 'correct token set'); }); }); From c1907ef46c8946c2c88a70d3f2ff2a70b3b810df Mon Sep 17 00:00:00 2001 From: Juan Pablo Buritica Date: Sat, 18 Jul 2015 23:08:05 -0400 Subject: [PATCH 3/3] [remmove] deprecated method `Stripe.createtoken` --- app/services/stripe.js | 14 -------------- tests/integration/stripe-test.js | 2 -- tests/unit/services/stripe-test.js | 18 ------------------ 3 files changed, 34 deletions(-) diff --git a/app/services/stripe.js b/app/services/stripe.js index 70258f3..da86737 100644 --- a/app/services/stripe.js +++ b/app/services/stripe.js @@ -46,19 +46,6 @@ function createCardToken (card) { }); } -/** - * Alias to `card.createToken`, exposed as `createCardToken` - * @deprecated please see `card.createToken` for usage - */ -function createCardTokenDeprecated(card) { - Ember.deprecate( - '`EmberStripeService.createToken` has been deprecated in ' + - 'favor of `EmberStripeService.card.createToken` to match ' + - 'the Stripe API.' - ); - return createCardToken(card); -} - /** * Creates a BankAccout token using Stripe.js API, exposed as `bankAccount.createToken` * @param {ojbect} bankAccount @@ -87,7 +74,6 @@ function createBankAccountToken(bankAccount) { * Expose module */ export default Ember.Service.extend({ - createToken: createCardTokenDeprecated, card: { createToken: createCardToken, }, diff --git a/tests/integration/stripe-test.js b/tests/integration/stripe-test.js index 98d1a47..85505c7 100644 --- a/tests/integration/stripe-test.js +++ b/tests/integration/stripe-test.js @@ -29,7 +29,6 @@ test('card.createToken sets the token and returns a promise', function(assert) { return service.card.createToken(cc) .then(function(res) { - console.log('res', res); assert.ok(res.id, 'correct token set'); }); }); @@ -39,7 +38,6 @@ test('bankAccount.createToken sets the token and returns a promise', function(as return service.bankAccount.createToken(bankAccount) .then(function(res) { - console.log('res', res); assert.ok(res.id, 'correct token set'); }); }); diff --git a/tests/unit/services/stripe-test.js b/tests/unit/services/stripe-test.js index 80dca09..e200f02 100644 --- a/tests/unit/services/stripe-test.js +++ b/tests/unit/services/stripe-test.js @@ -58,24 +58,6 @@ test('card.createToken rejects the promise if Stripe errors', function(assert) { }); }); -test('createToken syntax is still supported', function(assert) { - var service = this.subject(); - var response = { - id: 'the_token' - }; - - var createToken = sinon.stub(Stripe.card, 'createToken', function(card, cb) { - assert.equal(card, cc, 'called with sample creditcard'); - cb(200, response); - }); - - return service.createToken(cc) - .then(function(res) { - assert.equal(res.id, 'the_token'); - createToken.restore(); - }); -}); - // Bank accounts var ba = {