Skip to content

Commit 5b674b2

Browse files
authored
Merge pull request #23 from snewcomer/fix-error
rearrange error setter close #22
2 parents 77a2aff + 2543833 commit 5b674b2

File tree

9 files changed

+31
-19
lines changed

9 files changed

+31
-19
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Every component will:
9898
The components bubble up all of [the JavaScript events that can be handled by the Stripe Element in `element.on()`](https://stripe.com/docs/elements/reference#element-on) from the Ember component using the following actions:
9999

100100
- `blur`
101-
- `change` (also sets/unsets the `error` property on the component, which can be yielded with the block)
101+
- `change` (also sets/unsets the `stripeError` property on the component, which can be yielded with the block)
102102
- `focus`
103103

104104
You could handle these actions yourself, for example:
@@ -119,14 +119,14 @@ This addon gives you components that match the different [Element types](https:/
119119

120120
### Block usage with `options`
121121

122-
In addition to the simple usage above, like `{{stripe-card}}`, you can also yield to a block, which will yield both an `error` object and [the `stripeElement` itself](https://stripe.com/docs/elements/reference#the-element).
122+
In addition to the simple usage above, like `{{stripe-card}}`, you can also yield to a block, which will yield both an `stripeError` object and [the `stripeElement` itself](https://stripe.com/docs/elements/reference#the-element).
123123

124-
For example, you can choose to render out the `error`, as below (runnable in our dummy app).
124+
For example, you can choose to render out the `stripeError`, as below (runnable in our dummy app).
125125

126126
```hbs
127-
{{#stripe-card options=options as |stripeElement error|}}
128-
{{#if error}}
129-
<p class="error">{{error.message}}</p>
127+
{{#stripe-card options=options as |stripeElement stripeError|}}
128+
{{#if stripeError}}
129+
<p class="error">{{stripeError.message}}</p>
130130
{{/if}}
131131
<button {{action "submit" stripeElement}}>Submit</button>
132132
{{#if token}}

addon/components/stripe-element.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export default Component.extend({
66
classNames: ['ember-stripe-element'],
77

88
autofocus: false,
9-
error: null,
109
options: {},
1110
stripeElement: null,
11+
stripeError: null,
1212
type: null, // Set in components that extend from `stripe-element`
1313

1414
stripev3: service(),
@@ -68,15 +68,16 @@ export default Component.extend({
6868
stripeElement.on('blur', (event) => this.sendAction('blur', stripeElement, event));
6969
stripeElement.on('focus', (event) => this.sendAction('focus', stripeElement, event));
7070
stripeElement.on('change', (...args) => {
71-
let { error, complete } = args[0];
72-
set(this, 'error', error);
71+
let [{ complete, error: stripeError }] = args;
7372
this.sendAction('change', stripeElement, ...args);
7473

7574
if (complete) {
7675
this.sendAction('complete', stripeElement);
77-
} else if (error) {
78-
this.sendAction('error', error);
76+
} else if (stripeError) {
77+
this.sendAction('error', stripeError);
7978
}
79+
80+
set(this, 'stripeError', stripeError);
8081
});
8182
}
8283
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div role="mount-point"></div>
22
{{#if hasBlock}}
3-
{{yield stripeElement error}}
3+
{{yield stripeElement stripeError}}
44
{{/if}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div role="mount-point"></div>
22
{{#if hasBlock}}
3-
{{yield stripeElement error}}
3+
{{yield stripeElement stripeError}}
44
{{/if}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div role="mount-point"></div>
22
{{#if hasBlock}}
3-
{{yield stripeElement error}}
3+
{{yield stripeElement stripeError}}
44
{{/if}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div role="mount-point"></div>
22
{{#if hasBlock}}
3-
{{yield stripeElement error}}
3+
{{yield stripeElement stripeError}}
44
{{/if}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div role="mount-point"></div>
22
{{#if hasBlock}}
3-
{{yield stripeElement error}}
3+
{{yield stripeElement stripeError}}
44
{{/if}}

tests/dummy/app/templates/application.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
</p>
44

55
<div class="input-group">
6-
{{#stripe-card autofocus=true options=cardOptions as |stripeElement error|}}
7-
{{#if error}}
8-
<p class="error">{{error.message}}</p>
6+
{{#stripe-card autofocus=true options=cardOptions as |stripeElement stripeError|}}
7+
{{#if stripeError}}
8+
<p class="error">{{stripeError.message}}</p>
99
{{/if}}
1010
<button {{action "submit" stripeElement}}>Submit</button>
1111
{{#if token}}

tests/integration/components/stripe-card-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,14 @@ test('it renders', function(assert) {
2828

2929
assert.equal(this.$().text().trim(), 'template block text');
3030
});
31+
32+
test('yields out error message', function(assert) {
33+
this.stripeError = { message: 'oops' };
34+
this.render(hbs`
35+
{{#stripe-card stripeError=stripeError as |stripeElement stripeError|}}
36+
{{stripeError.message}}
37+
{{/stripe-card}}
38+
`);
39+
40+
assert.equal(this.$().text().trim(), 'oops');
41+
});

0 commit comments

Comments
 (0)