Skip to content

Commit

Permalink
Merge pull request #62 from square/deanpapastrat/add-input-events
Browse files Browse the repository at this point in the history
Add support for passing the 'inputEventReceived' callback.
  • Loading branch information
deanpapastrat authored Oct 26, 2020
2 parents 1570c02 + d75dcfb commit 42e4472
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
13 changes: 13 additions & 0 deletions addon/components/square-payment-form-styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,19 @@ export default Component.extend({
*/
shippingOptionChanged: null,

/**
* Callback that gets fired whenever a buyer focuses / blurs a field, enters invalid data,
* changes the card brand, or changes the postal code.
*
* See the [Payment Form reference](https://developer.squareup.com/docs/api/paymentform#inputeventreceived)
* for a full list of events.
*
* @action
* @argument inputEventReceived
* @type Action
*/
inputEventReceived: null,

// ADDON INTERNALS

env: null,
Expand Down
18 changes: 18 additions & 0 deletions addon/components/square-payment-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,19 @@ export default Component.extend({
*/
createVerificationDetails: null,

/**
* Callback that gets fired whenever a buyer focuses / blurs a field, enters invalid data,
* changes the card brand, or changes the postal code.
*
* See the [Payment Form reference](https://developer.squareup.com/docs/api/paymentform#inputeventreceived)
* for a full list of events.
*
* @action
* @argument inputEventReceived
* @type Action
*/
inputEventReceived: null,

// COMPONENT INTERNALS

env: null,
Expand Down Expand Up @@ -750,6 +763,11 @@ export default Component.extend({
}
);
},
inputEventReceived: (eventData) => {
if (this.inputEventReceived) {
this.inputEventReceived(eventData);
}
},
paymentFormLoaded: () => {
if (this.onPaymentFormLoaded) {
this.onPaymentFormLoaded();
Expand Down
1 change: 1 addition & 0 deletions addon/templates/components/square-payment-form-styled.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
shippingContactChanged=this.shippingContactChanged
shippingOptionChanged=this.shippingOptionChanged
createVerificationDetails=this.createVerificationDetails
inputEventReceived=this.inputEventReceived
as |PaymentForm|
}}
{{PaymentForm.ApplePayButton
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-square-payment-form",
"version": "0.4.2",
"version": "0.5.0",
"description": "Take payments with Square securely and easily in your Ember app",
"keywords": [
"ember-addon"
Expand Down
12 changes: 12 additions & 0 deletions tests/browser/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ describe('Card-Only Payment Form', () => {
await page.waitFor(1000);

await ccInputFrame.focus('input');

// Ensure input events are bubbled properly
const eventTypeHandle = await page.$('.event-data__event-type');
await expect(
await eventTypeHandle.evaluate(node => node.innerText)
).toMatch('focusClassAdded');

const fieldHandle = await page.$('.event-data__field');
await expect(
await fieldHandle.evaluate(node => node.innerText)
).toMatch('cardNumber');

await page.keyboard.type('4111 1111 1111 1111');

await expDateInputFrame.focus('input');
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/controllers/testing/card-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default Controller.extend({
shippingOption: JSON.stringify(shippingOption, null, ' '),
verificationToken
});
},
handleInputEventReceived(eventData) {
this.set('eventData', eventData);
}
}
});
11 changes: 10 additions & 1 deletion tests/dummy/app/templates/testing/card-only.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@locationId="TC4Z3ZEBKRXRH"
@style="light"
@onCardNonceResponseReceived={{action "handleCardNonceResponse"}}
@inputEventReceived={{action "handleInputEventReceived"}}
/>

{{#if nonceResponse}}
Expand All @@ -17,4 +18,12 @@
<pre class="nonce-response__shipping-option">{{nonceResponse.shippingOption}}</pre>
<pre class="nonce-response__verification-token">{{nonceResponse.verificationToken}}</pre>
</div>
{{/if}}
{{/if}}

{{#if eventData}}
<div class="event-data">
<h3>Events</h3>
<pre class="event-data__event-type">{{eventData.eventType}}</pre>
<pre class="event-data__field">{{eventData.field}}</pre>
</div>
{{/if}}

0 comments on commit 42e4472

Please sign in to comment.