Web component for Google Pay button
npm install @google-pay/button-elementThis is the web component for the Google Pay button. This component can be used in standard HTML websites as well as
websites built with many popular JavaScript frameworks.
Note that React and Angular developers should use the @google-pay/button-react and @google-pay/button-angular versions
of this component.
``sh`
npm install @google-pay/button-element
`html`
More HTML examples can be found in the
examples folder of this repository.
Try it out on StackBlitz.
`html`
button-type="buy"
button-color="black"
v-bind:paymentRequest.prop="{
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'
}
}
}
],
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPriceLabel: 'Total',
totalPrice: '100.00',
currencyCode: 'USD',
countryCode: 'US'
}
}"
v-on:loadpaymentdata="onLoadPaymentData"
v-on:error="onError"
>
More Vue examples can be found in the
examples folder of this
repository.
Try it out on StackBlitz.
`jsx`
button-type="buy"
button-color="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',
},
},
},
],
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPriceLabel: 'Total',
totalPrice: '100.00',
currencyCode: 'USD',
countryCode: 'US',
},
}}
on:loadpaymentdata={event => {
console.log('load payment data', event.detail);
}}
>
More Svelte examples can be found in the
examples folder of this repository.
Try it out on StackBlitz (note:
limited browser support).
Visit the Google Pay developer site for more information about
integrating Google Pay into your website.
| Property | Type | Remarks |
|---|---|---|
buttonColor |
| Optional.
Default value |
buttonLocale |
| Optional. This ISO 639-1 code represents the desired button language. Supported locales include Default value is determined by the browser/operating system locale. |
buttonSizeMode |
| Optional.
Default value |
buttonType |
| Optional. Displays their respective prompts (localized based on the user's browser settings) with the Google Pay logo. The
Default value |
buttonRadius |
| 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 |
buttonBorderType |
| Optional.
Default value |
environment |
| Required. The Google Pay environment to target. Note: in the |
existingPaymentMethodRequired |
| Optional. When set to Default value |
paymentRequest | Required. Request parameters that define the type of payment information requested from Google Pay. See |
| Callback | Arguments | Remarks |
|---|---|---|
onCancel | reason | Invoked when a user cancels or closes the Google Pay payment sheet. Also raised as event |
onClick | 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 |
onError | 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 |
onLoadPaymentData | paymentData | Invoked when a user has successfully nominated payment details. This callback receives the Also raised as event |
onPaymentAuthorized | 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 See payment authorization reference for more information. |
onPaymentDataChanged | 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 Note that in order to use this callback See payment data changed reference for more information. |
onReadyToPayChange | result | Invoked when the user's Note that when
Also raised as event |
Note that this folder does not contain a package.json file. The package.json file is generated during the buildpackage-template.json
process using the where the version number is read from the package.json`
file defined in the root of this repository.