Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@google-pay/button-angular

google-pay27.7kApache-2.03.1.0TypeScript support: included

Angular component for Google Pay button

googlepay, google-pay, google-pay-button, button, angular

readme

Google Pay Angular button

This is the Angular component for the Google Pay button.

Installation

npm install @google-pay/button-angular

Example usage: Angular website

<google-pay-button
  environment="TEST"
  buttonType="buy"
  buttonColor="black"
  [paymentRequest]="{
    apiVersion: 2,
    apiVersionMinor: 0,
    allowedPaymentMethods: [
      {
        type: 'CARD',
        parameters: {
          allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
          allowedCardNetworks: ['AMEX', 'VISA', 'MASTERCARD']
        },
        tokenizationSpecification: {
          type: 'PAYMENT_GATEWAY',
          parameters: {
            gateway: 'example',
            gatewayMerchantId: 'exampleGatewayMerchantId'
          }
        }
      }
    ],
    merchantInfo: {
      merchantId: '12345678901234567890',
      merchantName: 'Demo Merchant'
    },
    transactionInfo: {
      totalPriceStatus: 'FINAL',
      totalPriceLabel: 'Total',
      totalPrice: '100.00',
      currencyCode: 'USD',
      countryCode: 'US'
    }
  }"
  (loadpaymentdata)="onLoadPaymentData($event)"
></google-pay-button>

More Angular examples can be found in the examples folder of this repository.

Try it out on StackBlitz.

Documentation

Visit the Google Pay developer site for more information about integrating Google Pay into your website.

Properties

Property Type Remarks

buttonColor

"default" | "black" | "white"

Optional.

"default"/"black" buttons are suitable to be used on light colored backgrounds, with "white" being appropriate for dark colored backgrounds.

Default value "default".

buttonLocale

string

Optional.

This ISO 639-1 code represents the desired button language.

Supported locales include en, ar, bg, ca, cs, da, de, el, es, et, fi, fr, hr, id, it, ja, ko, ms, nl, no, pl, pt, ru, sk, sl, sr, sv, th, tr, uk, and zh.

Default value is determined by the browser/operating system locale.

buttonSizeMode

"static" | "fill"

Optional.

"static" buttons will be sized according to the translated buttonType.

"fill" buttons will be styled according the the element's size. Use this mode when resizing the button with CSS width and height properties.

Default value "static".

buttonType

"book" | "buy" | "checkout" | "donate" | "order" | "pay" | "plain" | "subscribe" | "long" | "short"

Optional.

Displays their respective prompts (localized based on the user's browser settings) with the Google Pay logo. The "plain" button only displays the Google Pay logo.

"long" and "short" button types have been renamed to "buy" and "plain", but are still valid button types for backwards compatability.

Default value "buy".

buttonRadius

number

Optional.

Specifies the button corner radius in pixels. The minimum is 0 and the maximum depends on the height of the button. If the height is 40px (default height) then the maximum value for the buttonRadius is 20.

environment

"TEST" | "PRODUCTION"

Required.

The Google Pay environment to target.

Note: in the "TEST" environment, fake payment credentials are returned. In order to use the "PRODUCTION" environment, your website must be registered with Google Pay. This can be done through the Google Pay Business Console.

existingPaymentMethodRequired

boolean

Optional.

When set to true (and environment is Production), the Google Pay button will only be displayed if the user already has an existing payment that they can use to make a purchase.

Default value false.

paymentRequest

PaymentDataRequest

Required.

Request parameters that define the type of payment information requested from Google Pay.

See PaymentDataRequest reference for more information.

Callbacks/events

Callback Arguments Remarks

cancelCallback

reason

Invoked when a user cancels or closes the Google Pay payment sheet.

Also raised as event "cancel".

clickCallback

event

Invoked when the Google Pay button is clicked, before the payment sheet is displayed.

Display of the payment sheet can be prevented by calling event.preventDefault().

errorCallback

reason

Invoked when an error is encountered in the process of presenting and collecting payment options from the Google Pay payment sheet.

Also raised as event "error".

loadPaymentDataCallback

paymentData

Invoked when a user has successfully nominated payment details. This callback receives the PaymentData response which includes the PaymentMethodData that can be sent to supported payment processors.

Also raised as event "loadpaymentdata".

paymentAuthorizedCallback

paymentData

Invoked when a user chooses a payment method. This callback should be used to validate whether or not the payment method can be used to complete a payment.

This would be typically used to perform pre-authorization to ensure that the card is valid and has sufficient funds.

Note that in order to use this callback paymentRequest.callbackIntents must include PAYMENT_AUTHORIZATION.

See payment authorization reference for more information.

paymentDataChangedCallback

intermediatePaymentData

Invoked when payment the user changes payment data options including payment method, shipping details, and contact details. This callback can be used to dynamically update transactionInfo when payment details, shipping address, or shipping options change.

Note that in order to use this callback paymentRequest.callbackIntents must include either SHIPPING_ADDRESS or SHIPPING_OPTION.

See payment data changed reference for more information.

readyToPayChangeCallback

result

Invoked when the user's isReadyToPay state changes. This callback can be used to change the application's behaviour based on whether or not the user is ready to pay.

Note that when existingPaymentMethodRequired is true, you will need to inspect both result.isReadyToPay and result.paymentMethodPresent to determine if the user isReadyToPay and has a paymentMethodPresent. Alternatively, result.isButtonVisible can be used to determine whether or Google Pay button will be displayed.

existingPaymentMethodRequired is taken into account with result.isButtonVisible.

Also raised as event "readytopaychange".

About this package

Note that this folder does not contain a package.json file. The package.json file is generated during the build process using the package-template.json where the version number is read from the package.json file defined in the root of this repository.

changelog

Changelog

3.1.0 (2024-03-28)

Features

  • add support for buttonRadius (89dbbc6)

3.0.10 (2023-07-17)

Bug Fixes

  • invalidation values comparison for objects (3e8b7ac)

3.0.9 (2023-05-02)

Bug Fixes

  • added error handling if google is not defined (b03a03e)

3.0.8 (2023-04-24)

Bug Fixes

  • only return from mount() if there was an error (b730f33)

3.0.7 (2023-04-21)

Bug Fixes

  • do not reference undefined google during component mounting (8d2fc32)

3.0.6 (2023-02-28)

Bug Fixes

  • new release 3.0.6 with @types/googlepay 0.7.0 (98e9a39)

3.0.5 (2022-12-13)

Bug Fixes

  • angular - remove main entrypoint (f8de638)

3.0.4 (2022-12-13)

Bug Fixes

  • broken angular packaging (4ca7abe)

3.0.3 (2022-12-13)

Bug Fixes

  • include all files from dist for angular component publishing (18954f2)

3.0.2 (2022-12-12)

Bug Fixes

  • using angular "compilationMode": "partial" (5694870)

3.0.2 (2022-12-12)

Bug Fixes

  • onError callback not called for @google-pay/button-react - fixes #170 (73c518c)

3.0.1 (2022-12-05)

Bug Fixes

  • remove history in gitignore and keep the if clause outside of the try block (77ac315)
  • remove some blanks (0670607)
  • trigger onError callback when loading googlepay js faild (e06dcf7)

3.0.0 (2021-10-01)

⚠ BREAKING CHANGES

  • update onError callback signature to match runtime values

Bug Fixes

  • update onError callback signature to match runtime values (edbbc02), closes #101

2.6.0 (2021-08-13)

Features

  • pass allowedPaymentMethods to the createButton api (9073f06)

2.5.0 (2021-07-09)

Features

  • add callback to be executed when Google Pay button is clicked (4720041), closes #92

2.4.1 (2021-06-24)

Features

  • update @types/googlepay to support new button types (e017ab0)

2.4.0 (2021-06-11)

Features

2.3.0 (2021-03-05)

Features

  • add support for setting buttonLocale (00af174)

2.2.1 (2021-02-17)

Bug Fixes

  • call config.onError if present if isReadyToPay throws (#73) (63fee4f)

2.2.0 (2021-02-06)

Features

  • add es5 build output (5eb243b), closes #60
  • add support for main, browser, and module entry points (8d72f50), closes #60 #71

2.1.5 (2020-11-19)

Bug Fixes

  • docs: update Angular component readme file (faeee50)

2.1.4 (2020-11-14)

Bug Fixes

  • add @types/googlepay as a direct dependenct for @google-pay/button-angular (d796162)

2.1.3 (2020-11-11)

Bug Fixes

  • include pissing files from package.json (57b0cdc)

2.1.2 (2020-11-11)

Bug Fixes

  • build: publish angular dist folder instead of root (2b8413b)

2.1.1 (2020-11-11)

Bug Fixes

  • build: publish @google-pay/button-angular using angular token (25195f7)

2.1.0 (2020-11-11)

Features

  • implement Angular specific package (12d021a)

Bug Fixes

  • enable ivy for Angular (a12b02a)
  • remove shadow DOM workaround (4a7a710), closes #19

2.0.1 (2020-09-10)

Bug Fixes

  • update @types/googlepay package dependency (eddc588)

2.0.0 (2020-09-10)

⚠ BREAKING CHANGES

  • make environment a required property

Features

  • add support for buttonSizeMode (0e85f04)
  • make environment a required property (94e51c0), closes #45

1.1.7 (2020-09-04)

Bug Fixes

  • build: update build pipeline to fix broken publish (attempt 2) (08c7482)

1.1.6 (2020-09-04)

Bug Fixes

  • build: update build pipeline to fix broken publish (c7ba3a0)

1.1.5 (2020-09-04)

Features

  • build: setup publish workflow for bit.dev (9ad66aa)

1.1.4 (2020-08-28)

Bug Fixes

  • docs: remove webcomponent.org demo as it doesn't work in their iframe (168f217)

1.1.3 (2020-08-28)

Bug Fixes

  • docs: add webcomponent.org demo snippet (68a6dbc)

1.1.2 (2020-08-27)

Bug Fixes

  • docs: use absolute example urls to to ensure links work on npm (d9bbec0)

1.1.1 (2020-08-22)

Bug Fixes

  • docs: update button types from long/short to buy/plain (b28c48e)

1.1.0 (2020-08-21)

Features

  • add support for donate button (193c781), closes #34

1.0.4 (2020-07-22)

Bug Fixes

  • add lowercase property aliases for button-element (7b1f623)

1.0.3 (2020-06-25)

Bug Fixes

  • remove paymentRequest and merchantInfo from invalidation properties (ecafb34)

1.0.2 (2020-06-24)

Bug Fixes

  • add try/catch around prefetchPaymentData (be06a76)
  • update fill button styling (27a1d82)

1.0.1 (2020-06-23)

Bug Fixes

  • add support for when dynamic button is rendered (3264778)

1.0.0 (2020-06-21)

Features

  • promote to stable public release 1.0 (#22) (a532e15)

0.11.0 (2020-06-19)

Features

  • add prefetchPaymentData integration (7b0e4dd)

0.10.1 (2020-06-19)

Bug Fixes

  • update homepage property of package.json from master to main (0ab5994)

0.10.0 (2020-06-18)

Features

  • generate minified resources (f1a9165)

0.9.1 (2020-06-18)

Bug Fixes

  • include LICENSE file to npm packages (f180377)

0.9.0 (2020-06-17)

⚠ BREAKING CHANGES

  • remove logic to infer paymentRequest properties

Features

  • remove logic to infer paymentRequest properties (3261957), closes #13

Bug Fixes

  • restore primaryBranch configuration (b2fce29)

0.8.0 (2020-06-16)

⚠ BREAKING CHANGES

  • remove logic to infer callbackIntents based on callback methods
  • convert button-react to es modules

Features

  • examples: replace http-server with serve (f9e9643)
  • include umd modules in npm packages (48582dd)
  • remove logic to infer callbackIntents based on callback methods (49e5ad2), closes #13

Bug Fixes

  • add keywords to npm package (eb7e1cb)
  • convert button-react to es modules (c6ddb0a)
  • update package dependency for @types/googlepay to 0.4.1 (89f48fc)

0.7.0 (2020-06-16)

Features

0.6.0 (2020-06-11)

⚠ BREAKING CHANGES

  • return paymentMethodPresent when ready to pay changes

Bug Fixes

  • don't set className if className is empty (b288b5e)
  • return paymentMethodPresent when ready to pay changes (0219559)

0.5.4 (2020-06-08)

Bug Fixes

  • don't load pay.js if already loaded (1e457b6)