Skip to content

Commit

Permalink
feat: pass allowedPaymentMethods to the createButton api
Browse files Browse the repository at this point in the history
  • Loading branch information
Soc Sieng authored and socsieng committed Aug 13, 2021
1 parent 4c7b711 commit 9073f06
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
43 changes: 42 additions & 1 deletion examples/react/src/examples/BasicExample.tsx
Expand Up @@ -31,7 +31,48 @@ export default function BasicExample(props: any): React.ReactElement {
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD', 'VISA'],
allowedCardNetworks: ['MASTERCARD'],
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'example',
gatewayMerchantId: 'exampleGatewayMerchantId',
},
},
},
],
merchantInfo: {
merchantId: '12345678901234567890',
merchantName: 'Demo Merchant',
},
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPriceLabel: 'Total',
totalPrice: props.amount,
currencyCode: 'USD',
countryCode: 'US',
},
}}
onLoadPaymentData={paymentRequest => {
console.log('Success', paymentRequest);
}}
existingPaymentMethodRequired={props.existingPaymentMethodRequired}
buttonColor={props.buttonColor}
buttonType={props.buttonType}
buttonLocale={props.buttonLocale}
/>
<GooglePayButton
environment="TEST"
paymentRequest={{
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['VISA'],
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
Expand Down
64 changes: 64 additions & 0 deletions examples/svelte/src/App.svelte
Expand Up @@ -45,6 +45,44 @@
function updatePaymentRequests() {
paymentRequests = {
basic: buildPaymentRequest(),
mastercard: {
...buildPaymentRequest(),
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD'],
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'example',
gatewayMerchantId: 'exampleGatewayMerchantId',
},
},
},
],
},
visa: {
...buildPaymentRequest(),
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['VISA'],
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'example',
gatewayMerchantId: 'exampleGatewayMerchantId',
},
},
},
],
},
authorize: {
...buildPaymentRequest(),
callbackIntents: ['PAYMENT_AUTHORIZATION'],
Expand Down Expand Up @@ -228,6 +266,32 @@
on:error={onError} />
</div>
</div>
<div class="example">
<div class="title">Mastercard only</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type={buttonType}
button-color={buttonColor}
{existingPaymentMethodRequired}
paymentRequest={paymentRequests.mastercard}
on:loadpaymentdata={onLoadPaymentData}
on:error={onError} />
</div>
</div>
<div class="example">
<div class="title">VISA only</div>
<div class="demo">
<google-pay-button
environment="TEST"
button-type={buttonType}
button-color={buttonColor}
{existingPaymentMethodRequired}
paymentRequest={paymentRequests.visa}
on:loadpaymentdata={onLoadPaymentData}
on:error={onError} />
</div>
</div>
<div class="example">
<div class="title">Payment Authorization</div>
<div class="demo">
Expand Down
2 changes: 2 additions & 0 deletions src/lib/button-manager.ts
Expand Up @@ -228,6 +228,7 @@ export class ButtonManager {
buttonSizeMode: this.config.buttonSizeMode,
buttonLocale: this.config.buttonLocale,
onClick: this.handleClick,
allowedPaymentMethods: this.config.paymentRequest.allowedPaymentMethods,
};

const rootNode = element.getRootNode();
Expand Down Expand Up @@ -400,6 +401,7 @@ export class ButtonManager {
config.paymentRequest.merchantInfo.merchantName,
config.paymentRequest.merchantInfo.softwareInfo?.id,
config.paymentRequest.merchantInfo.softwareInfo?.version,
config.paymentRequest.allowedPaymentMethods,
];
}
}

0 comments on commit 9073f06

Please sign in to comment.