Socket
Socket
Sign inDemoInstall

@google-pay/button-react

Package Overview
Dependencies
10
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.5 to 3.0.6

2

dist/index.es5.min.js

@@ -15,2 +15,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).GooglePayButton=e(t.React)}(this,(function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t),o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)};

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var r=function(){return r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},r.apply(this,arguments)};function i(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}function a(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var s={};function u(t){var e=s[t];if(e)return e;var n=new Promise((function(e,n){var o=document.createElement("script");o.src=t,o.async=!0;var r=function(){e()},i=function(){o.removeEventListener("load",r),o.removeEventListener("error",i),delete s[t],o.remove(),n(new Error("Unable to load script ".concat(t)))};o.addEventListener("load",r),o.addEventListener("error",i),document.body.appendChild(o)}));return s[t]=n,n}var l=function(){function t(t){var e=this;this.handleClick=function(t){return i(e,void 0,void 0,(function(){var e,n,o,r;return a(this,(function(i){switch(i.label){case 0:if(!(e=this.config))throw new Error("google-pay-button: Missing configuration");n=this.createLoadPaymentDataRequest(e),i.label=1;case 1:return i.trys.push([1,3,,4]),e.onClick&&e.onClick(t),t.defaultPrevented?[2]:[4,this.client.loadPaymentData(n)];case 2:return o=i.sent(),e.onLoadPaymentData&&e.onLoadPaymentData(o),[3,4];case 3:return"CANCELED"===(r=i.sent()).statusCode?e.onCancel&&e.onCancel(r):e.onError?e.onError(r):console.error(r),[3,4];case 4:return[2]}}))}))},this.options=t}return t.prototype.getElement=function(){return this.element},t.prototype.isGooglePayLoaded=function(){var t,e;return"google"in(window||global)&&!!(null===(e=null===(t=null===google||void 0===google?void 0:google.payments)||void 0===t?void 0:t.api)||void 0===e?void 0:e.PaymentsClient)},t.prototype.mount=function(t){var e;return i(this,void 0,void 0,(function(){var n;return a(this,(function(o){switch(o.label){case 0:if(this.isGooglePayLoaded())return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,u("https://pay.google.com/gp/p/js/pay.js")];case 2:return o.sent(),[3,4];case 3:return n=o.sent(),(null===(e=this.config)||void 0===e?void 0:e.onError)?this.config.onError(n):console.error(n),[3,4];case 4:return this.element=t,t&&(this.appendStyles(),this.config&&this.updateElement()),[2]}}))}))},t.prototype.unmount=function(){this.element=void 0},t.prototype.configure=function(t){var e=void 0;return this.config=t,this.oldInvalidationValues&&!this.isClientInvalidated(t)||(e=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(t),null!=e?e:Promise.resolve()},t.prototype.createClientOptions=function(t){var e={environment:t.environment,merchantInfo:this.createMerchantInfo(t)};return(t.onPaymentDataChanged||t.onPaymentAuthorized)&&(e.paymentDataCallbacks={},t.onPaymentDataChanged&&(e.paymentDataCallbacks.onPaymentDataChanged=function(e){return t.onPaymentDataChanged(e)||{}}),t.onPaymentAuthorized&&(e.paymentDataCallbacks.onPaymentAuthorized=function(e){return t.onPaymentAuthorized(e)||{}})),e},t.prototype.createIsReadyToPayRequest=function(t){var e=t.paymentRequest;return{apiVersion:e.apiVersion,apiVersionMinor:e.apiVersionMinor,allowedPaymentMethods:e.allowedPaymentMethods,existingPaymentMethodRequired:t.existingPaymentMethodRequired}},t.prototype.createLoadPaymentDataRequest=function(t){return r(r({},t.paymentRequest),{merchantInfo:this.createMerchantInfo(t)})},t.prototype.createMerchantInfo=function(t){var e=r({},t.paymentRequest.merchantInfo);return e.softwareInfo||(e.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),e},t.prototype.isMounted=function(){return null!=this.element&&!1!==this.element.isConnected},t.prototype.removeButton=function(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(var t=0,e=Array.from(this.element.children);t<e.length;t++){var n=e[t];"STYLE"!==n.tagName&&n.remove()}},t.prototype.updateElement=function(){return i(this,void 0,void 0,(function(){var t,e,n,o,r,i,s,u;return a(this,(function(a){switch(a.label){case 0:if(!this.isMounted())return[2];if(t=this.getElement(),!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton(),this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config)),e={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},(n=t.getRootNode())instanceof ShadowRoot&&(e.buttonRootNode=n),o=this.client.createButton(e),this.setClassName(t,[t.className,"not-ready"]),t.appendChild(o),r=!1,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config))];case 2:return i=a.sent(),r=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1,[3,4];case 3:return s=a.sent(),this.config.onError?this.config.onError(s):console.error(s),[3,4];case 4:if(!this.isMounted())return[2];if(r){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(t){console.log("Error with prefetch",t)}this.setClassName(t,(t.className||"").split(" ").filter((function(t){return t&&"not-ready"!==t})))}return this.isReadyToPay===(null==i?void 0:i.result)&&this.paymentMethodPresent===(null==i?void 0:i.paymentMethodPresent)||(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange&&(u={isButtonVisible:r,isReadyToPay:this.isReadyToPay},this.paymentMethodPresent&&(u.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(u))),[2]}}))}))},t.prototype.setClassName=function(t,e){var n=e.filter((function(t){return t})).join(" ");n?t.className=n:t.removeAttribute("class")},t.prototype.appendStyles=function(){var t,e,n;if("undefined"!=typeof document){var o=null===(t=this.element)||void 0===t?void 0:t.getRootNode(),r="default-google-style-".concat(this.options.cssSelector.replace(/[^\w-]+/g,""),"-").concat(null===(e=this.config)||void 0===e?void 0:e.buttonLocale);if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,r))){var i=document.createElement("style");i.id=r,i.type="text/css",i.innerHTML="\n ".concat(this.options.cssSelector," {\n display: inline-block;\n }\n ").concat(this.options.cssSelector,".not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n "),o instanceof Document&&o.head?o.head.appendChild(i):o.appendChild(i)}}},t.prototype.isClientInvalidated=function(t){var e=this;return!this.oldInvalidationValues||this.getInvalidationValues(t).some((function(t,n){return t!==e.oldInvalidationValues[n]}))},t.prototype.getInvalidationValues=function(t){var e,n;return[t.environment,t.existingPaymentMethodRequired,!!t.onPaymentDataChanged,!!t.onPaymentAuthorized,t.buttonColor,t.buttonType,t.buttonLocale,t.buttonSizeMode,t.paymentRequest.merchantInfo.merchantId,t.paymentRequest.merchantInfo.merchantName,null===(e=t.paymentRequest.merchantInfo.softwareInfo)||void 0===e?void 0:e.id,null===(n=t.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,t.paymentRequest.allowedPaymentMethods]},t}(),c="@google-pay/button-react",d="3.0.5",h="google-pay-button-container",f=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.manager=new l({cssSelector:".".concat(h),softwareInfoId:c,softwareInfoVersion:d}),e.elementRef=n.default.createRef(),e}return function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.componentDidMount=function(){return i(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return(t=this.elementRef.current)?[4,this.manager.configure(this.props)]:[3,3];case 1:return e.sent(),[4,this.manager.mount(t)];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},e.prototype.componentWillUnmount=function(){this.manager.unmount()},e.prototype.componentDidUpdate=function(){this.manager.configure(this.props)},e.prototype.render=function(){return n.default.createElement("div",{ref:this.elementRef,className:[h,this.props.className].filter((function(t){return t})).join(" "),style:this.props.style})},e}(n.default.Component);return f}));
***************************************************************************** */var r=function(){return r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},r.apply(this,arguments)};function i(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((o=o.apply(t,e||[])).next())}))}function a(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var s={};function u(t){var e=s[t];if(e)return e;var n=new Promise((function(e,n){var o=document.createElement("script");o.src=t,o.async=!0;var r=function(){e()},i=function(){o.removeEventListener("load",r),o.removeEventListener("error",i),delete s[t],o.remove(),n(new Error("Unable to load script ".concat(t)))};o.addEventListener("load",r),o.addEventListener("error",i),document.body.appendChild(o)}));return s[t]=n,n}var l=function(){function t(t){var e=this;this.handleClick=function(t){return i(e,void 0,void 0,(function(){var e,n,o,r;return a(this,(function(i){switch(i.label){case 0:if(!(e=this.config))throw new Error("google-pay-button: Missing configuration");n=this.createLoadPaymentDataRequest(e),i.label=1;case 1:return i.trys.push([1,3,,4]),e.onClick&&e.onClick(t),t.defaultPrevented?[2]:[4,this.client.loadPaymentData(n)];case 2:return o=i.sent(),e.onLoadPaymentData&&e.onLoadPaymentData(o),[3,4];case 3:return"CANCELED"===(r=i.sent()).statusCode?e.onCancel&&e.onCancel(r):e.onError?e.onError(r):console.error(r),[3,4];case 4:return[2]}}))}))},this.options=t}return t.prototype.getElement=function(){return this.element},t.prototype.isGooglePayLoaded=function(){var t,e;return"google"in(window||global)&&!!(null===(e=null===(t=null===google||void 0===google?void 0:google.payments)||void 0===t?void 0:t.api)||void 0===e?void 0:e.PaymentsClient)},t.prototype.mount=function(t){var e;return i(this,void 0,void 0,(function(){var n;return a(this,(function(o){switch(o.label){case 0:if(this.isGooglePayLoaded())return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,u("https://pay.google.com/gp/p/js/pay.js")];case 2:return o.sent(),[3,4];case 3:return n=o.sent(),(null===(e=this.config)||void 0===e?void 0:e.onError)?this.config.onError(n):console.error(n),[3,4];case 4:return this.element=t,t&&(this.appendStyles(),this.config&&this.updateElement()),[2]}}))}))},t.prototype.unmount=function(){this.element=void 0},t.prototype.configure=function(t){var e=void 0;return this.config=t,this.oldInvalidationValues&&!this.isClientInvalidated(t)||(e=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(t),null!=e?e:Promise.resolve()},t.prototype.createClientOptions=function(t){var e={environment:t.environment,merchantInfo:this.createMerchantInfo(t)};return(t.onPaymentDataChanged||t.onPaymentAuthorized)&&(e.paymentDataCallbacks={},t.onPaymentDataChanged&&(e.paymentDataCallbacks.onPaymentDataChanged=function(e){return t.onPaymentDataChanged(e)||{}}),t.onPaymentAuthorized&&(e.paymentDataCallbacks.onPaymentAuthorized=function(e){return t.onPaymentAuthorized(e)||{}})),e},t.prototype.createIsReadyToPayRequest=function(t){var e=t.paymentRequest;return{apiVersion:e.apiVersion,apiVersionMinor:e.apiVersionMinor,allowedPaymentMethods:e.allowedPaymentMethods,existingPaymentMethodRequired:t.existingPaymentMethodRequired}},t.prototype.createLoadPaymentDataRequest=function(t){return r(r({},t.paymentRequest),{merchantInfo:this.createMerchantInfo(t)})},t.prototype.createMerchantInfo=function(t){var e=r({},t.paymentRequest.merchantInfo);return e.softwareInfo||(e.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),e},t.prototype.isMounted=function(){return null!=this.element&&!1!==this.element.isConnected},t.prototype.removeButton=function(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(var t=0,e=Array.from(this.element.children);t<e.length;t++){var n=e[t];"STYLE"!==n.tagName&&n.remove()}},t.prototype.updateElement=function(){return i(this,void 0,void 0,(function(){var t,e,n,o,r,i,s,u;return a(this,(function(a){switch(a.label){case 0:if(!this.isMounted())return[2];if(t=this.getElement(),!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton(),this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config)),e={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},(n=t.getRootNode())instanceof ShadowRoot&&(e.buttonRootNode=n),o=this.client.createButton(e),this.setClassName(t,[t.className,"not-ready"]),t.appendChild(o),r=!1,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config))];case 2:return i=a.sent(),r=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1,[3,4];case 3:return s=a.sent(),this.config.onError?this.config.onError(s):console.error(s),[3,4];case 4:if(!this.isMounted())return[2];if(r){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(t){console.log("Error with prefetch",t)}this.setClassName(t,(t.className||"").split(" ").filter((function(t){return t&&"not-ready"!==t})))}return this.isReadyToPay===(null==i?void 0:i.result)&&this.paymentMethodPresent===(null==i?void 0:i.paymentMethodPresent)||(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange&&(u={isButtonVisible:r,isReadyToPay:this.isReadyToPay},this.paymentMethodPresent&&(u.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(u))),[2]}}))}))},t.prototype.setClassName=function(t,e){var n=e.filter((function(t){return t})).join(" ");n?t.className=n:t.removeAttribute("class")},t.prototype.appendStyles=function(){var t,e,n;if("undefined"!=typeof document){var o=null===(t=this.element)||void 0===t?void 0:t.getRootNode(),r="default-google-style-".concat(this.options.cssSelector.replace(/[^\w-]+/g,""),"-").concat(null===(e=this.config)||void 0===e?void 0:e.buttonLocale);if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,r))){var i=document.createElement("style");i.id=r,i.type="text/css",i.innerHTML="\n ".concat(this.options.cssSelector," {\n display: inline-block;\n }\n ").concat(this.options.cssSelector,".not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n "),o instanceof Document&&o.head?o.head.appendChild(i):o.appendChild(i)}}},t.prototype.isClientInvalidated=function(t){var e=this;return!this.oldInvalidationValues||this.getInvalidationValues(t).some((function(t,n){return t!==e.oldInvalidationValues[n]}))},t.prototype.getInvalidationValues=function(t){var e,n;return[t.environment,t.existingPaymentMethodRequired,!!t.onPaymentDataChanged,!!t.onPaymentAuthorized,t.buttonColor,t.buttonType,t.buttonLocale,t.buttonSizeMode,t.paymentRequest.merchantInfo.merchantId,t.paymentRequest.merchantInfo.merchantName,null===(e=t.paymentRequest.merchantInfo.softwareInfo)||void 0===e?void 0:e.id,null===(n=t.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,t.paymentRequest.allowedPaymentMethods]},t}(),c="@google-pay/button-react",d="3.0.6",h="google-pay-button-container",f=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.manager=new l({cssSelector:".".concat(h),softwareInfoId:c,softwareInfoVersion:d}),e.elementRef=n.default.createRef(),e}return function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.componentDidMount=function(){return i(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return(t=this.elementRef.current)?[4,this.manager.configure(this.props)]:[3,3];case 1:return e.sent(),[4,this.manager.mount(t)];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},e.prototype.componentWillUnmount=function(){this.manager.unmount()},e.prototype.componentDidUpdate=function(){this.manager.configure(this.props)},e.prototype.render=function(){return n.default.createElement("div",{ref:this.elementRef,className:[h,this.props.className].filter((function(t){return t})).join(" "),style:this.props.style})},e}(n.default.Component);return f}));

@@ -424,3 +424,3 @@ import React from 'react';

var name = "@google-pay/button-react";
var version = "3.0.5";
var version = "3.0.6";

@@ -427,0 +427,0 @@ /**

@@ -15,2 +15,2 @@ import e from"react";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function t(e,t,n,o){return new(n||(n=Promise))((function(i,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}l((o=o.apply(e,t||[])).next())}))}let n={};function o(e){const t=n[e];if(t)return t;const o=new Promise(((t,o)=>{const i=document.createElement("script");i.src=e,i.async=!0;const a=()=>{t()},s=()=>{i.removeEventListener("load",a),i.removeEventListener("error",s),delete n[e],i.remove(),o(new Error(`Unable to load script ${e}`))};i.addEventListener("load",a),i.addEventListener("error",s),document.body.appendChild(i)}));return n[e]=o,o}class i{constructor(e){this.handleClick=e=>t(this,void 0,void 0,(function*(){const t=this.config;if(!t)throw new Error("google-pay-button: Missing configuration");const n=this.createLoadPaymentDataRequest(t);try{if(t.onClick&&t.onClick(e),e.defaultPrevented)return;const o=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(o)}catch(e){"CANCELED"===e.statusCode?t.onCancel&&t.onCancel(e):t.onError?t.onError(e):console.error(e)}})),this.options=e}getElement(){return this.element}isGooglePayLoaded(){var e,t;return"google"in(window||global)&&!!(null===(t=null===(e=null===google||void 0===google?void 0:google.payments)||void 0===e?void 0:e.api)||void 0===t?void 0:t.PaymentsClient)}mount(e){var n;return t(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield o("https://pay.google.com/gp/p/js/pay.js")}catch(e){(null===(n=this.config)||void 0===n?void 0:n.onError)?this.config.onError(e):console.error(e)}this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t;return this.config=e,this.oldInvalidationValues&&!this.isClientInvalidated(e)||(t=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(e),null!=t?t:Promise.resolve()}createClientOptions(e){const t={environment:e.environment,merchantInfo:this.createMerchantInfo(e)};return(e.onPaymentDataChanged||e.onPaymentAuthorized)&&(t.paymentDataCallbacks={},e.onPaymentDataChanged&&(t.paymentDataCallbacks.onPaymentDataChanged=t=>e.onPaymentDataChanged(t)||{}),e.onPaymentAuthorized&&(t.paymentDataCallbacks.onPaymentAuthorized=t=>e.onPaymentAuthorized(t)||{})),t}createIsReadyToPayRequest(e){const t=e.paymentRequest;return{apiVersion:t.apiVersion,apiVersionMinor:t.apiVersionMinor,allowedPaymentMethods:t.allowedPaymentMethods,existingPaymentMethodRequired:e.existingPaymentMethodRequired}}createLoadPaymentDataRequest(e){return Object.assign(Object.assign({},e.paymentRequest),{merchantInfo:this.createMerchantInfo(e)})}createMerchantInfo(e){const t=Object.assign({},e.paymentRequest.merchantInfo);return t.softwareInfo||(t.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),t}isMounted(){return null!=this.element&&!1!==this.element.isConnected}removeButton(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(const e of Array.from(this.element.children))"STYLE"!==e.tagName&&e.remove()}updateElement(){return t(this,void 0,void 0,(function*(){if(!this.isMounted())return;const e=this.getElement();if(!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton(),this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config));const t={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},n=e.getRootNode();n instanceof ShadowRoot&&(t.buttonRootNode=n);const o=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(o);let i,a=!1;try{i=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),a=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(a){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(e){console.log("Error with prefetch",e)}this.setClassName(e,(e.className||"").split(" ").filter((e=>e&&"not-ready"!==e)))}if((this.isReadyToPay!==(null==i?void 0:i.result)||this.paymentMethodPresent!==(null==i?void 0:i.paymentMethodPresent))&&(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:a,isReadyToPay:this.isReadyToPay};this.paymentMethodPresent&&(e.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(e)}}}))}setClassName(e,t){const n=t.filter((e=>e)).join(" ");n?e.className=n:e.removeAttribute("class")}appendStyles(){var e,t,n;if("undefined"==typeof document)return;const o=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),i=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,i))){const e=document.createElement("style");e.id=i,e.type="text/css",e.innerHTML=`\n ${this.options.cssSelector} {\n display: inline-block;\n }\n ${this.options.cssSelector}.not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n `,o instanceof Document&&o.head?o.head.appendChild(e):o.appendChild(e)}}isClientInvalidated(e){if(!this.oldInvalidationValues)return!0;return this.getInvalidationValues(e).some(((e,t)=>e!==this.oldInvalidationValues[t]))}getInvalidationValues(e){var t,n;return[e.environment,e.existingPaymentMethodRequired,!!e.onPaymentDataChanged,!!e.onPaymentAuthorized,e.buttonColor,e.buttonType,e.buttonLocale,e.buttonSizeMode,e.paymentRequest.merchantInfo.merchantId,e.paymentRequest.merchantInfo.merchantName,null===(t=e.paymentRequest.merchantInfo.softwareInfo)||void 0===t?void 0:t.id,null===(n=e.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,e.paymentRequest.allowedPaymentMethods]}}const a="google-pay-button-container";class s extends e.Component{constructor(){super(...arguments),this.manager=new i({cssSelector:`.${a}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.0.5"}),this.elementRef=e.createRef()}componentDidMount(){return t(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.configure(this.props),yield this.manager.mount(e))}))}componentWillUnmount(){this.manager.unmount()}componentDidUpdate(){this.manager.configure(this.props)}render(){return e.createElement("div",{ref:this.elementRef,className:[a,this.props.className].filter((e=>e)).join(" "),style:this.props.style})}}export{s as default};
***************************************************************************** */function t(e,t,n,o){return new(n||(n=Promise))((function(i,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}l((o=o.apply(e,t||[])).next())}))}let n={};function o(e){const t=n[e];if(t)return t;const o=new Promise(((t,o)=>{const i=document.createElement("script");i.src=e,i.async=!0;const a=()=>{t()},s=()=>{i.removeEventListener("load",a),i.removeEventListener("error",s),delete n[e],i.remove(),o(new Error(`Unable to load script ${e}`))};i.addEventListener("load",a),i.addEventListener("error",s),document.body.appendChild(i)}));return n[e]=o,o}class i{constructor(e){this.handleClick=e=>t(this,void 0,void 0,(function*(){const t=this.config;if(!t)throw new Error("google-pay-button: Missing configuration");const n=this.createLoadPaymentDataRequest(t);try{if(t.onClick&&t.onClick(e),e.defaultPrevented)return;const o=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(o)}catch(e){"CANCELED"===e.statusCode?t.onCancel&&t.onCancel(e):t.onError?t.onError(e):console.error(e)}})),this.options=e}getElement(){return this.element}isGooglePayLoaded(){var e,t;return"google"in(window||global)&&!!(null===(t=null===(e=null===google||void 0===google?void 0:google.payments)||void 0===e?void 0:e.api)||void 0===t?void 0:t.PaymentsClient)}mount(e){var n;return t(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield o("https://pay.google.com/gp/p/js/pay.js")}catch(e){(null===(n=this.config)||void 0===n?void 0:n.onError)?this.config.onError(e):console.error(e)}this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t;return this.config=e,this.oldInvalidationValues&&!this.isClientInvalidated(e)||(t=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(e),null!=t?t:Promise.resolve()}createClientOptions(e){const t={environment:e.environment,merchantInfo:this.createMerchantInfo(e)};return(e.onPaymentDataChanged||e.onPaymentAuthorized)&&(t.paymentDataCallbacks={},e.onPaymentDataChanged&&(t.paymentDataCallbacks.onPaymentDataChanged=t=>e.onPaymentDataChanged(t)||{}),e.onPaymentAuthorized&&(t.paymentDataCallbacks.onPaymentAuthorized=t=>e.onPaymentAuthorized(t)||{})),t}createIsReadyToPayRequest(e){const t=e.paymentRequest;return{apiVersion:t.apiVersion,apiVersionMinor:t.apiVersionMinor,allowedPaymentMethods:t.allowedPaymentMethods,existingPaymentMethodRequired:e.existingPaymentMethodRequired}}createLoadPaymentDataRequest(e){return Object.assign(Object.assign({},e.paymentRequest),{merchantInfo:this.createMerchantInfo(e)})}createMerchantInfo(e){const t=Object.assign({},e.paymentRequest.merchantInfo);return t.softwareInfo||(t.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),t}isMounted(){return null!=this.element&&!1!==this.element.isConnected}removeButton(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(const e of Array.from(this.element.children))"STYLE"!==e.tagName&&e.remove()}updateElement(){return t(this,void 0,void 0,(function*(){if(!this.isMounted())return;const e=this.getElement();if(!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton(),this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config));const t={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},n=e.getRootNode();n instanceof ShadowRoot&&(t.buttonRootNode=n);const o=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(o);let i,a=!1;try{i=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),a=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(a){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(e){console.log("Error with prefetch",e)}this.setClassName(e,(e.className||"").split(" ").filter((e=>e&&"not-ready"!==e)))}if((this.isReadyToPay!==(null==i?void 0:i.result)||this.paymentMethodPresent!==(null==i?void 0:i.paymentMethodPresent))&&(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:a,isReadyToPay:this.isReadyToPay};this.paymentMethodPresent&&(e.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(e)}}}))}setClassName(e,t){const n=t.filter((e=>e)).join(" ");n?e.className=n:e.removeAttribute("class")}appendStyles(){var e,t,n;if("undefined"==typeof document)return;const o=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),i=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,i))){const e=document.createElement("style");e.id=i,e.type="text/css",e.innerHTML=`\n ${this.options.cssSelector} {\n display: inline-block;\n }\n ${this.options.cssSelector}.not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n `,o instanceof Document&&o.head?o.head.appendChild(e):o.appendChild(e)}}isClientInvalidated(e){if(!this.oldInvalidationValues)return!0;return this.getInvalidationValues(e).some(((e,t)=>e!==this.oldInvalidationValues[t]))}getInvalidationValues(e){var t,n;return[e.environment,e.existingPaymentMethodRequired,!!e.onPaymentDataChanged,!!e.onPaymentAuthorized,e.buttonColor,e.buttonType,e.buttonLocale,e.buttonSizeMode,e.paymentRequest.merchantInfo.merchantId,e.paymentRequest.merchantInfo.merchantName,null===(t=e.paymentRequest.merchantInfo.softwareInfo)||void 0===t?void 0:t.id,null===(n=e.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,e.paymentRequest.allowedPaymentMethods]}}const a="google-pay-button-container";class s extends e.Component{constructor(){super(...arguments),this.manager=new i({cssSelector:`.${a}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.0.6"}),this.elementRef=e.createRef()}componentDidMount(){return t(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.configure(this.props),yield this.manager.mount(e))}))}componentWillUnmount(){this.manager.unmount()}componentDidUpdate(){this.manager.configure(this.props)}render(){return e.createElement("div",{ref:this.elementRef,className:[a,this.props.className].filter((e=>e)).join(" "),style:this.props.style})}}export{s as default};

@@ -432,3 +432,3 @@ (function (global, factory) {

var name = "@google-pay/button-react";
var version = "3.0.5";
var version = "3.0.6";

@@ -435,0 +435,0 @@ /**

@@ -15,2 +15,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).GooglePayButton=t(e.React)}(this,(function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e);

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function o(e,t,n,o){return new(n||(n=Promise))((function(i,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}l((o=o.apply(e,t||[])).next())}))}let i={};function a(e){const t=i[e];if(t)return t;const n=new Promise(((t,n)=>{const o=document.createElement("script");o.src=e,o.async=!0;const a=()=>{t()},s=()=>{o.removeEventListener("load",a),o.removeEventListener("error",s),delete i[e],o.remove(),n(new Error(`Unable to load script ${e}`))};o.addEventListener("load",a),o.addEventListener("error",s),document.body.appendChild(o)}));return i[e]=n,n}class s{constructor(e){this.handleClick=e=>o(this,void 0,void 0,(function*(){const t=this.config;if(!t)throw new Error("google-pay-button: Missing configuration");const n=this.createLoadPaymentDataRequest(t);try{if(t.onClick&&t.onClick(e),e.defaultPrevented)return;const o=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(o)}catch(e){"CANCELED"===e.statusCode?t.onCancel&&t.onCancel(e):t.onError?t.onError(e):console.error(e)}})),this.options=e}getElement(){return this.element}isGooglePayLoaded(){var e,t;return"google"in(window||global)&&!!(null===(t=null===(e=null===google||void 0===google?void 0:google.payments)||void 0===e?void 0:e.api)||void 0===t?void 0:t.PaymentsClient)}mount(e){var t;return o(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield a("https://pay.google.com/gp/p/js/pay.js")}catch(e){(null===(t=this.config)||void 0===t?void 0:t.onError)?this.config.onError(e):console.error(e)}this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t;return this.config=e,this.oldInvalidationValues&&!this.isClientInvalidated(e)||(t=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(e),null!=t?t:Promise.resolve()}createClientOptions(e){const t={environment:e.environment,merchantInfo:this.createMerchantInfo(e)};return(e.onPaymentDataChanged||e.onPaymentAuthorized)&&(t.paymentDataCallbacks={},e.onPaymentDataChanged&&(t.paymentDataCallbacks.onPaymentDataChanged=t=>e.onPaymentDataChanged(t)||{}),e.onPaymentAuthorized&&(t.paymentDataCallbacks.onPaymentAuthorized=t=>e.onPaymentAuthorized(t)||{})),t}createIsReadyToPayRequest(e){const t=e.paymentRequest;return{apiVersion:t.apiVersion,apiVersionMinor:t.apiVersionMinor,allowedPaymentMethods:t.allowedPaymentMethods,existingPaymentMethodRequired:e.existingPaymentMethodRequired}}createLoadPaymentDataRequest(e){return Object.assign(Object.assign({},e.paymentRequest),{merchantInfo:this.createMerchantInfo(e)})}createMerchantInfo(e){const t=Object.assign({},e.paymentRequest.merchantInfo);return t.softwareInfo||(t.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),t}isMounted(){return null!=this.element&&!1!==this.element.isConnected}removeButton(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(const e of Array.from(this.element.children))"STYLE"!==e.tagName&&e.remove()}updateElement(){return o(this,void 0,void 0,(function*(){if(!this.isMounted())return;const e=this.getElement();if(!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton(),this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config));const t={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},n=e.getRootNode();n instanceof ShadowRoot&&(t.buttonRootNode=n);const o=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(o);let i,a=!1;try{i=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),a=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(a){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(e){console.log("Error with prefetch",e)}this.setClassName(e,(e.className||"").split(" ").filter((e=>e&&"not-ready"!==e)))}if((this.isReadyToPay!==(null==i?void 0:i.result)||this.paymentMethodPresent!==(null==i?void 0:i.paymentMethodPresent))&&(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:a,isReadyToPay:this.isReadyToPay};this.paymentMethodPresent&&(e.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(e)}}}))}setClassName(e,t){const n=t.filter((e=>e)).join(" ");n?e.className=n:e.removeAttribute("class")}appendStyles(){var e,t,n;if("undefined"==typeof document)return;const o=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),i=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,i))){const e=document.createElement("style");e.id=i,e.type="text/css",e.innerHTML=`\n ${this.options.cssSelector} {\n display: inline-block;\n }\n ${this.options.cssSelector}.not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n `,o instanceof Document&&o.head?o.head.appendChild(e):o.appendChild(e)}}isClientInvalidated(e){if(!this.oldInvalidationValues)return!0;return this.getInvalidationValues(e).some(((e,t)=>e!==this.oldInvalidationValues[t]))}getInvalidationValues(e){var t,n;return[e.environment,e.existingPaymentMethodRequired,!!e.onPaymentDataChanged,!!e.onPaymentAuthorized,e.buttonColor,e.buttonType,e.buttonLocale,e.buttonSizeMode,e.paymentRequest.merchantInfo.merchantId,e.paymentRequest.merchantInfo.merchantName,null===(t=e.paymentRequest.merchantInfo.softwareInfo)||void 0===t?void 0:t.id,null===(n=e.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,e.paymentRequest.allowedPaymentMethods]}}const r="google-pay-button-container";class l extends n.default.Component{constructor(){super(...arguments),this.manager=new s({cssSelector:`.${r}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.0.5"}),this.elementRef=n.default.createRef()}componentDidMount(){return o(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.configure(this.props),yield this.manager.mount(e))}))}componentWillUnmount(){this.manager.unmount()}componentDidUpdate(){this.manager.configure(this.props)}render(){return n.default.createElement("div",{ref:this.elementRef,className:[r,this.props.className].filter((e=>e)).join(" "),style:this.props.style})}}return l}));
***************************************************************************** */function o(e,t,n,o){return new(n||(n=Promise))((function(i,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}l((o=o.apply(e,t||[])).next())}))}let i={};function a(e){const t=i[e];if(t)return t;const n=new Promise(((t,n)=>{const o=document.createElement("script");o.src=e,o.async=!0;const a=()=>{t()},s=()=>{o.removeEventListener("load",a),o.removeEventListener("error",s),delete i[e],o.remove(),n(new Error(`Unable to load script ${e}`))};o.addEventListener("load",a),o.addEventListener("error",s),document.body.appendChild(o)}));return i[e]=n,n}class s{constructor(e){this.handleClick=e=>o(this,void 0,void 0,(function*(){const t=this.config;if(!t)throw new Error("google-pay-button: Missing configuration");const n=this.createLoadPaymentDataRequest(t);try{if(t.onClick&&t.onClick(e),e.defaultPrevented)return;const o=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(o)}catch(e){"CANCELED"===e.statusCode?t.onCancel&&t.onCancel(e):t.onError?t.onError(e):console.error(e)}})),this.options=e}getElement(){return this.element}isGooglePayLoaded(){var e,t;return"google"in(window||global)&&!!(null===(t=null===(e=null===google||void 0===google?void 0:google.payments)||void 0===e?void 0:e.api)||void 0===t?void 0:t.PaymentsClient)}mount(e){var t;return o(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield a("https://pay.google.com/gp/p/js/pay.js")}catch(e){(null===(t=this.config)||void 0===t?void 0:t.onError)?this.config.onError(e):console.error(e)}this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t;return this.config=e,this.oldInvalidationValues&&!this.isClientInvalidated(e)||(t=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(e),null!=t?t:Promise.resolve()}createClientOptions(e){const t={environment:e.environment,merchantInfo:this.createMerchantInfo(e)};return(e.onPaymentDataChanged||e.onPaymentAuthorized)&&(t.paymentDataCallbacks={},e.onPaymentDataChanged&&(t.paymentDataCallbacks.onPaymentDataChanged=t=>e.onPaymentDataChanged(t)||{}),e.onPaymentAuthorized&&(t.paymentDataCallbacks.onPaymentAuthorized=t=>e.onPaymentAuthorized(t)||{})),t}createIsReadyToPayRequest(e){const t=e.paymentRequest;return{apiVersion:t.apiVersion,apiVersionMinor:t.apiVersionMinor,allowedPaymentMethods:t.allowedPaymentMethods,existingPaymentMethodRequired:e.existingPaymentMethodRequired}}createLoadPaymentDataRequest(e){return Object.assign(Object.assign({},e.paymentRequest),{merchantInfo:this.createMerchantInfo(e)})}createMerchantInfo(e){const t=Object.assign({},e.paymentRequest.merchantInfo);return t.softwareInfo||(t.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),t}isMounted(){return null!=this.element&&!1!==this.element.isConnected}removeButton(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(const e of Array.from(this.element.children))"STYLE"!==e.tagName&&e.remove()}updateElement(){return o(this,void 0,void 0,(function*(){if(!this.isMounted())return;const e=this.getElement();if(!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton(),this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config));const t={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},n=e.getRootNode();n instanceof ShadowRoot&&(t.buttonRootNode=n);const o=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(o);let i,a=!1;try{i=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),a=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(a){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(e){console.log("Error with prefetch",e)}this.setClassName(e,(e.className||"").split(" ").filter((e=>e&&"not-ready"!==e)))}if((this.isReadyToPay!==(null==i?void 0:i.result)||this.paymentMethodPresent!==(null==i?void 0:i.paymentMethodPresent))&&(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:a,isReadyToPay:this.isReadyToPay};this.paymentMethodPresent&&(e.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(e)}}}))}setClassName(e,t){const n=t.filter((e=>e)).join(" ");n?e.className=n:e.removeAttribute("class")}appendStyles(){var e,t,n;if("undefined"==typeof document)return;const o=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),i=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,i))){const e=document.createElement("style");e.id=i,e.type="text/css",e.innerHTML=`\n ${this.options.cssSelector} {\n display: inline-block;\n }\n ${this.options.cssSelector}.not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n `,o instanceof Document&&o.head?o.head.appendChild(e):o.appendChild(e)}}isClientInvalidated(e){if(!this.oldInvalidationValues)return!0;return this.getInvalidationValues(e).some(((e,t)=>e!==this.oldInvalidationValues[t]))}getInvalidationValues(e){var t,n;return[e.environment,e.existingPaymentMethodRequired,!!e.onPaymentDataChanged,!!e.onPaymentAuthorized,e.buttonColor,e.buttonType,e.buttonLocale,e.buttonSizeMode,e.paymentRequest.merchantInfo.merchantId,e.paymentRequest.merchantInfo.merchantName,null===(t=e.paymentRequest.merchantInfo.softwareInfo)||void 0===t?void 0:t.id,null===(n=e.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,e.paymentRequest.allowedPaymentMethods]}}const r="google-pay-button-container";class l extends n.default.Component{constructor(){super(...arguments),this.manager=new s({cssSelector:`.${r}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.0.6"}),this.elementRef=n.default.createRef()}componentDidMount(){return o(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.configure(this.props),yield this.manager.mount(e))}))}componentWillUnmount(){this.manager.unmount()}componentDidUpdate(){this.manager.configure(this.props)}render(){return n.default.createElement("div",{ref:this.elementRef,className:[r,this.props.className].filter((e=>e)).join(" "),style:this.props.style})}}return l}));
{
"name": "@google-pay/button-react",
"version": "3.0.5",
"version": "3.0.6",
"description": "React component for Google Pay button",

@@ -21,3 +21,3 @@ "main": "dist/index.es5.min.js",

"dependencies": {
"@types/googlepay": "^0.6.3"
"@types/googlepay": "^0.7.0"
},

@@ -24,0 +24,0 @@ "peerDependencies": {

@@ -57,3 +57,3 @@ # Google Pay React button

Try it out on [StackBlitz](https://stackblitz.com/edit/google-pay-react), or see it in action with a
Try it out on [StackBlitz](https://stackblitz.com/edit/google-pay-react-ecbhkg), or see it in action with a
[React sample store](https://payments-react-store.web.app/)

@@ -76,11 +76,2 @@ ([source code](https://github.com/google-pay/react-store/tree/google-pay)).

<tr>
<td><p>buttonColor</p></td>
<td><p><code>"default" | "black" | "white"</code></p></td>
<td>
<p>Optional.</p>
<p><code>"default"</code>/<code>"black"</code> buttons are suitable to be used on light colored backgrounds, with <code>"white"</code> being appropriate for dark colored backgrounds.</p>
<p>Default value <code>"default"</code>.</p>
</td>
</tr>
<tr>
<td><p>buttonLocale</p></td>

@@ -87,0 +78,0 @@ <td><p><code>string</code></p></td>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc