-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from code-corps/issue49
Add contextual component for using individual Stripe elements
- Loading branch information
Showing
6 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Component from '@ember/component'; | ||
import layout from '../templates/components/stripe-elements'; | ||
import { inject as service } from '@ember/service'; | ||
import { get, set } from '@ember/object'; | ||
|
||
export default Component.extend({ | ||
stripe: service('stripev3'), | ||
tagName: '', | ||
layout, | ||
|
||
init() { | ||
this._super(...arguments); | ||
let options = get(this, 'options') || {}; | ||
let elements = get(this, 'stripe').elements(options); | ||
set(this, 'elements', elements); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{yield (hash | ||
card=(component "stripe-card" | ||
elements=elements | ||
) | ||
cardNumber=(component "stripe-card-number" | ||
elements=elements | ||
) | ||
cardExpiry=(component "stripe-card-expiry" | ||
elements=elements | ||
) | ||
cardCvc=(component "stripe-card-cvc" | ||
elements=elements | ||
) | ||
postalCode=(component "stripe-postal-code" | ||
elements=elements | ||
) | ||
)}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-stripe-elements/components/stripe-elements'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, find } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import StripeMock from 'ember-stripe-elements/utils/stripe-mock'; | ||
import StripeService from 'dummy/services/stripev3'; | ||
import env from 'dummy/config/environment'; | ||
|
||
module('Integration | Component | stripe-elements', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(function() { | ||
window.Stripe = StripeMock; | ||
const config = { | ||
mock: true, | ||
publishableKey: env.stripe.publishableKey, | ||
}; | ||
|
||
this.owner.register( | ||
'service:stripev3', | ||
StripeService.create({ config }), | ||
{ instantiate: false } | ||
); | ||
}); | ||
|
||
test('it renders single-line element', async function (assert) { | ||
await render(hbs` | ||
{{#stripe-elements as |elements|}} | ||
{{elements.card}} | ||
{{/stripe-elements}} | ||
`); | ||
|
||
assert.ok(find('.ember-stripe-card > [role="mount-point"]')); | ||
}); | ||
|
||
test('it renders individual elements', async function (assert) { | ||
await render(hbs` | ||
{{#stripe-elements as |elements|}} | ||
{{elements.cardNumber}} | ||
{{elements.cardExpiry}} | ||
{{elements.cardCvc}} | ||
{{elements.postalCode}} | ||
{{/stripe-elements}} | ||
`); | ||
|
||
let tests = [ | ||
'card-number', | ||
'card-expiry', | ||
'card-cvc', | ||
'postal-code' | ||
]; | ||
|
||
do { | ||
let el = tests.shift(); | ||
assert.ok(find(`.ember-stripe-${el} > [role="mount-point"]`), el); | ||
} while(tests.length); | ||
}); | ||
}); |