Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Features

- Inject `<script src="https://js.stripe.com/v3/"></script>` into your application's `<body>`
- Initialize `Stripe` with your publishable key
- Inject a `stripev3` service into your controllers so you can use the functions usually available on the `stripe` object (see https://stripe.com/docs/stripe-js/reference#the-stripe-object):
- Inject a `stripe` service into your controllers so you can use the functions usually available on the `stripe` object (see https://stripe.com/docs/stripe-js/reference#the-stripe-object):
- `stripe.elements()`
- `stripe.confirmCardPayment()`
- `stripe.createToken()`
Expand Down Expand Up @@ -103,11 +103,11 @@ When enabled, a [mock Stripe object](https://github.com/adopted-ember-addons/emb
When using the Stripe mock in tests you will likely need to override the mock's methods according to the needs of your test like so:

```js
this.owner.lookup('service:stripev3').createToken = () => ({ token: { id: 'token' } });
this.owner.lookup('service:stripe').createToken = () => ({ token: { id: 'token' } });
```
### Testing and Simulating User Input

When a {{stripe-element}} is instantiated and in the DOM, the underlying `stripeElement` is available via the `stripev3` service. Calling `stripeService.getActiveElements()` will return an array of those native stripeElements.
When a {{stripe-element}} is instantiated and in the DOM, the underlying `stripeElement` is available via the `stripe` service. Calling `stripeService.getActiveElements()` will return an array of those native stripeElements.

This is primarily useful in testing. Stripe renders an iframe which is mostly inaccessible in a test environment, making simulating user input impossible.

Expand Down Expand Up @@ -170,7 +170,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class SubscriptionRoute extends Route {
@service('stripev3') stripe;
@service stripe;

beforeModel() {
return this.stripe.load();
Expand Down Expand Up @@ -202,7 +202,7 @@ Every component will:
- Bubble the proper JavaScript events into actions
- Mount Stripe's own `StripeElement` in a `<div role="mount-point">` on `didInsertElement`
- Unmount on `willDestroyElement`
- Provide access to the `stripev3` service
- Provide access to the `stripe` service
- Have the base CSS class name `.ember-stripe-element`
- Have a CSS class for the specific element that matches the component's name, e.g. `<EmberStripeCard/>` has the class `.ember-stripe-card`
- Yield to a block
Expand Down Expand Up @@ -342,7 +342,7 @@ import { tracked } from "@glimmer/tracking";
import { action } from '@ember/object';

export default class SubscriptionController extends Controller {
@service stripev3;
@service stripe;

options = {
hidePostalCode: true,
Expand Down
8 changes: 4 additions & 4 deletions addon/components/stripe-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class StripeElement extends Component {
@tracked type = null; // Set in components that extend from `stripe-element`
@tracked _stripeError = null;

@service stripev3;
@service stripe;

get autofocus() {
return this.args.autofocus;
Expand All @@ -23,7 +23,7 @@ export default class StripeElement extends Component {
return this.args._elements;
}

return this.stripev3.elements();
return this.stripe.elements();
}

get stripeError() {
Expand Down Expand Up @@ -53,7 +53,7 @@ export default class StripeElement extends Component {

// Make the element available to the component
this.stripeElement = stripeElement;
this.stripev3.addStripeElement(stripeElement);
this.stripe.addStripeElement(stripeElement);
}

focusElement(element) {
Expand Down Expand Up @@ -117,7 +117,7 @@ export default class StripeElement extends Component {

willDestroy() {
this.stripeElement.unmount();
this.stripev3.removeStripeElement(this.stripeElement);
this.stripe.removeStripeElement(this.stripeElement);
super.willDestroy(...arguments);
}
}
2 changes: 1 addition & 1 deletion addon/components/stripe-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

export default class StripeElements extends Component {
@service('stripev3') stripe;
@service stripe;

get options() {
return this.args.options || {};
Expand Down
2 changes: 1 addition & 1 deletion addon/services/stripev3.js → addon/services/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class StripeService extends Service {

if (!publishableKey) {
throw new Error(
'stripev3: Missing Stripe key, please set `ENV.stripe.publishableKey` in config/environment.js'
'stripe: Missing Stripe key, please set `ENV.stripe.publishableKey` in config/environment.js'
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/services/stripev3.js → app/services/stripe.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from '@adopted-ember-addons/ember-stripe-elements/services/stripev3';
export { default } from '@adopted-ember-addons/ember-stripe-elements/services/stripe';
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let style = {
};

export default class Application extends Controller {
@service('stripev3') stripe;
@service stripe;

@tracked token = null;
@tracked cardOptions = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class ApplicationRoute extends Route {
@service('stripev3') stripe;
@service stripe;

beforeModel() {
return this.stripe.load();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/stripe-card-cvc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module('Integration | Component | stripe-card-cvc', function (hooks) {

hooks.beforeEach(function () {
window.Stripe = StripeMock;
this.stripe = this.owner.lookup('service:stripev3');
this.stripe = this.owner.lookup('service:stripe');
this.stripe.configure();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/stripe-card-expiry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module('Integration | Component | stripe-card-expiry', function (hooks) {
hooks.beforeEach(function () {
window.Stripe = StripeMock;

this.stripe = this.owner.lookup('service:stripev3');
this.stripe = this.owner.lookup('service:stripe');
this.stripe.configure();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/stripe-card-number-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module('Integration | Component | stripe card number', function (hooks) {

hooks.beforeEach(function () {
window.Stripe = StripeMock;
this.stripe = this.owner.lookup('service:stripev3');
this.stripe = this.owner.lookup('service:stripe');
this.stripe.configure();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/stripe-card-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module('Integration | Component | stripe-card', function (hooks) {

hooks.beforeEach(function () {
window.Stripe = StripeMock;
this.stripe = this.owner.lookup('service:stripev3');
this.stripe = this.owner.lookup('service:stripe');
this.stripe.configure();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/stripe-elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module('Integration | Component | stripe-elements', function (hooks) {

hooks.beforeEach(function () {
window.Stripe = StripeMock;
this.stripe = this.owner.lookup('service:stripev3');
this.stripe = this.owner.lookup('service:stripe');
this.stripe.configure();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/stripe-postal-code-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module('Integration | Component | stripe-postal-code', function (hooks) {

hooks.beforeEach(function () {
window.Stripe = StripeMock;
this.stripe = this.owner.lookup('service:stripev3');
this.stripe = this.owner.lookup('service:stripe');
this.stripe.configure();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { setupTest } from 'ember-qunit';
import sinon from 'sinon';
import StripeMock from '@adopted-ember-addons/ember-stripe-elements/test-support';

module('Unit | Service | stripev3', function (hooks) {
module('Unit | Service | stripe', function (hooks) {
setupTest(hooks);

hooks.beforeEach(function () {
window.Stripe = StripeMock;
this.subject = this.owner.lookup('service:stripev3');
this.subject = this.owner.lookup('service:stripe');
});

test('it proxies stripe.elements', function (assert) {
Expand Down Expand Up @@ -629,7 +629,7 @@ module('Unit | Service | stripev3', function (hooks) {
this.subject.configure();
},
new Error(
'stripev3: Missing Stripe key, please set `ENV.stripe.publishableKey` in config/environment.js'
'stripe: Missing Stripe key, please set `ENV.stripe.publishableKey` in config/environment.js'
),
'Missing config.stripe.publishableKey should throw an error'
);
Expand Down