Skip to content

Commit

Permalink
feat!: make environment a required property
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
Soc Sieng committed Sep 10, 2020
1 parent 0e85f04 commit 94e51c0
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 8 deletions.
4 changes: 4 additions & 0 deletions examples/angular/src/app/app.component.html
Expand Up @@ -54,6 +54,7 @@
<div class="title">Basic Example</div>
<div class="demo">
<google-pay-button
environment="TEST"
[buttonType]="buttonType"
[buttonColor]="buttonColor"
[existingPaymentMethodRequired]="existingPaymentMethodRequired"
Expand All @@ -79,6 +80,7 @@
<div class="title">Payment Authorization</div>
<div class="demo">
<google-pay-button
environment="TEST"
[buttonType]="buttonType"
[buttonColor]="buttonColor"
[existingPaymentMethodRequired]="existingPaymentMethodRequired"
Expand Down Expand Up @@ -106,6 +108,7 @@
<div class="title">Cryptogram 3ds</div>
<div class="demo">
<google-pay-button
environment="TEST"
[buttonType]="buttonType"
[buttonColor]="buttonColor"
[existingPaymentMethodRequired]="existingPaymentMethodRequired"
Expand Down Expand Up @@ -148,6 +151,7 @@
<div class="title">Require Shipping</div>
<div class="demo">
<google-pay-button
environment="TEST"
[buttonType]="buttonType"
[buttonColor]="buttonColor"
[existingPaymentMethodRequired]="existingPaymentMethodRequired"
Expand Down
1 change: 1 addition & 0 deletions examples/html/dynamic-examples.js
Expand Up @@ -219,6 +219,7 @@ function updateGooglePayButtons() {
if (!button) {
button = new GooglePayButton();
button.id = id;
button.environment = 'TEST';

const container = document.getElementById('examples');
container.appendChild(createExample(gpay.title, button));
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/AmexExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="American Express">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/BasicExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Mastercard and VISA">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/ButtonSizeExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Button Size">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/CryptogramExample.tsx
Expand Up @@ -24,6 +24,7 @@ export default (props: any) => {
return (
<Example title="Cryptogram 3ds">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/DirectIntegrationExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Direct Integration">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/DisplayItemsExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Display Items">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/DynamicPriceUpdateExample.tsx
Expand Up @@ -98,6 +98,7 @@ export default (props: any) => {
return (
<Example title="Dynamic Price Updates">
<GooglePayButton
environment="TEST"
paymentRequest={paymentRequest}
onLoadPaymentData={paymentRequest => {
console.log('Success', paymentRequest);
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/EmailRequiredExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Email Required">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/OnCancelExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="On Cancel">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Payment Authorization (insufficient funds)">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Payment Authorization">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Payment Data Changed Error (no US address)">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/PaymentDataChangedExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Payment Data Changed">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/RequireShippingExample.tsx
Expand Up @@ -22,6 +22,7 @@ export default (props: any) => {
return (
<Example title="Require Shipping">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
1 change: 1 addition & 0 deletions examples/react/src/examples/ShippingOptionsExample.tsx
Expand Up @@ -37,6 +37,7 @@ export default (props: any) => {
return (
<Example title="Shipping Options">
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
Expand Down
4 changes: 4 additions & 0 deletions examples/svelte/src/App.svelte
Expand Up @@ -207,6 +207,7 @@
<div class="title">Basic Example</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type={buttonType}
button-color={buttonColor}
{existingPaymentMethodRequired}
Expand All @@ -219,6 +220,7 @@
<div class="title">Payment Authorization</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type={buttonType}
button-color={buttonColor}
{existingPaymentMethodRequired}
Expand All @@ -232,6 +234,7 @@
<div class="title">Cryptogram 3ds</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type={buttonType}
button-color={buttonColor}
{existingPaymentMethodRequired}
Expand All @@ -245,6 +248,7 @@
<div class="title">Require Shipping</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type={buttonType}
button-color={buttonColor}
{existingPaymentMethodRequired}
Expand Down
4 changes: 4 additions & 0 deletions examples/vue/src/components/Examples.vue
Expand Up @@ -53,6 +53,7 @@
<div class="title">Basic Example</div>
<div class="demo">
<google-pay-button
environment="TEST"
v-bind:button-type="buttonType"
v-bind:button-color="buttonColor"
v-bind:existing-payment-method-required="existingPaymentMethodRequired"
Expand All @@ -78,6 +79,7 @@
<div class="title">Payment Authorization</div>
<div class="demo">
<google-pay-button
environment="TEST"
v-bind:button-type="buttonType"
v-bind:button-color="buttonColor"
v-bind:existing-payment-method-required="existingPaymentMethodRequired"
Expand All @@ -104,6 +106,7 @@
<div class="title">Cryptogram 3ds</div>
<div class="demo">
<google-pay-button
environment="TEST"
v-bind:button-type="buttonType"
v-bind:button-color="buttonColor"
v-bind:existing-payment-method-required="existingPaymentMethodRequired"
Expand Down Expand Up @@ -146,6 +149,7 @@
<div class="title">Require Shipping</div>
<div class="demo">
<google-pay-button
environment="TEST"
v-bind:button-type="buttonType"
v-bind:button-color="buttonColor"
v-bind:existing-payment-method-required="existingPaymentMethodRequired"
Expand Down
1 change: 1 addition & 0 deletions examples/vue/src/components/StaticExample.vue
Expand Up @@ -21,6 +21,7 @@
<div class="title">Static Example</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type="plain"
button-color="black"
v-bind:paymentRequest.prop="{
Expand Down
10 changes: 7 additions & 3 deletions src/button-element/GooglePayButton.ts
Expand Up @@ -33,10 +33,10 @@ class GooglePayButton extends HTMLElement {

@Notify()
@Alias('paymentrequest')
paymentRequest?: google.payments.api.PaymentDataRequest;
paymentRequest!: google.payments.api.PaymentDataRequest;

@NotifyAttribute()
environment?: google.payments.api.Environment;
environment!: google.payments.api.Environment;

@NotifyBooleanAttribute()
@Alias('existingpaymentmethodrequired')
Expand Down Expand Up @@ -138,8 +138,12 @@ class GooglePayButton extends HTMLElement {
return;
}

if (!this.assertRequiredProperty('environment')) {
return;
}

const config: Config = {
paymentRequest: this.paymentRequest!,
paymentRequest: this.paymentRequest,
environment: this.environment,
existingPaymentMethodRequired: this.existingPaymentMethodRequired,
onPaymentDataChanged: this.onPaymentDataChanged,
Expand Down
5 changes: 3 additions & 2 deletions src/button-element/README.md
Expand Up @@ -66,6 +66,7 @@ Try it out on [JSFiddle](https://jsfiddle.net/wupkceL4/).

```html
<google-pay-button
environment="TEST"
button-type="buy"
button-color="black"
[paymentRequest]="{
Expand Down Expand Up @@ -110,6 +111,7 @@ repository.

```html
<google-pay-button
environment="TEST"
button-type="buy"
button-color="black"
v-bind:paymentRequest.prop="{
Expand Down Expand Up @@ -201,10 +203,9 @@ integrating Google Pay into your website.
<td><p>environment</p></td>
<td><p><code>"TEST" | "PRODUCTION"</code></p></td>
<td>
<p>Optional.</p>
<p>Required.</p>
<p>The Google Pay environment to target.</p>
<p>Note: in the <code>"TEST"</code> environment, fake payment credentials are returned. In order to use the <code>"PRODUCTION"</code> environment, your website must be registered with Google Pay. This can be done through the <a href="https://pay.google.com/business/console/">Google Pay Business Console</a>.</p>
<p>Default value <code>"TEST"</code>.</p>
</td>
</tr>
<tr>
Expand Down
3 changes: 1 addition & 2 deletions src/button-react/README.md
Expand Up @@ -111,10 +111,9 @@ integrating Google Pay into your website.
<td><p>environment</p></td>
<td><p><code>"TEST" | "PRODUCTION"</code></p></td>
<td>
<p>Optional.</p>
<p>Required.</p>
<p>The Google Pay environment to target.</p>
<p>Note: in the <code>"TEST"</code> environment, fake payment credentials are returned. In order to use the <code>"PRODUCTION"</code> environment, your website must be registered with Google Pay. This can be done through the <a href="https://pay.google.com/business/console/">Google Pay Business Console</a>.</p>
<p>Default value <code>"TEST"</code>.</p>
</td>
</tr>
<tr>
Expand Down
16 changes: 16 additions & 0 deletions src/lib/button-manager.test.ts
Expand Up @@ -491,6 +491,22 @@ describe('Google Pay client invalidation', () => {
expect(updateElementSpy).toBeCalledTimes(2);
});

it('invalidates client when buttonSizeMode changes', () => {
const manager = new ButtonManager(managerOptions);
const config1: Config = {
...defaults,
};
const config2: Config = {
...defaults,
buttonSizeMode: 'static',
};

manager.configure(config1);
manager.configure(config2);

expect(updateElementSpy).toBeCalledTimes(2);
});

it('invalidates client when buttonColor changes', () => {
const manager = new ButtonManager(managerOptions);
const config1: Config = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/button-manager.ts
Expand Up @@ -25,7 +25,7 @@ export interface ReadyToPayChangeResponse {
}

export interface Config {
environment?: google.payments.api.Environment;
environment: google.payments.api.Environment;
existingPaymentMethodRequired?: boolean;
paymentRequest: google.payments.api.PaymentDataRequest;
onPaymentDataChanged?: google.payments.api.PaymentDataChangedHandler;
Expand Down

0 comments on commit 94e51c0

Please sign in to comment.