@google-pay/button-react
Advanced tools
Comparing version 2.6.0 to 3.0.0
@@ -33,3 +33,3 @@ /// <reference types="googlepay" /> | ||
onCancel?: (reason: google.payments.api.PaymentsError) => void; | ||
onError?: (error: Error) => void; | ||
onError?: (error: Error | google.payments.api.PaymentsError) => void; | ||
onReadyToPayChange?: (result: ReadyToPayChangeResponse) => void; | ||
@@ -36,0 +36,0 @@ onClick?: (event: Event) => void; |
@@ -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])})(t,e)}; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var i=function(){return(i=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(i,r){function a(t){try{l(o.next(t))}catch(t){r(t)}}function s(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}l((o=o.apply(t,e||[])).next())}))}function a(t,e){var n,o,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(r){return function(s){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return a.label++,{value:r[1],done:!1};case 5:a.label++,o=r[1],r=[0];continue;case 7:r=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){a=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){a.label=r[1];break}if(6===r[0]&&a.label<i[1]){a.label=i[1],i=r;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(r);break}i[2]&&a.ops.pop(),a.trys.pop();continue}r=e.call(t,a)}catch(t){r=[6,t],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,s])}}}var s={};function l(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 i=function(){e()},r=function(){o.removeEventListener("load",i),o.removeEventListener("error",r),delete s[t],o.remove(),n(new Error("Unable to load script "+t))};o.addEventListener("load",i),o.addEventListener("error",r),document.body.appendChild(o)}));return s[t]=n,n}var u=function(){function t(t){var e=this;this.handleClick=function(t){return r(e,void 0,void 0,(function(){var e,n,o,i;return a(this,(function(r){switch(r.label){case 0:if(!(e=this.config))throw new Error("google-pay-button: Missing configuration");n=this.createLoadPaymentDataRequest(e),r.label=1;case 1:return r.trys.push([1,3,,4]),e.onClick&&e.onClick(t),t.defaultPrevented?[2]:[4,this.client.loadPaymentData(n)];case 2:return o=r.sent(),e.onLoadPaymentData&&e.onLoadPaymentData(o),[3,4];case 3:return"CANCELED"===(i=r.sent()).statusCode?e.onCancel&&e.onCancel(i):e.onError?e.onError(i):console.error(i),[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){return r(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return this.isGooglePayLoaded()?[3,2]:[4,l("https://pay.google.com/gp/p/js/pay.js")];case 1:e.sent(),e.label=2;case 2: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 i(i({},t.paymentRequest),{merchantInfo:this.createMerchantInfo(t)})},t.prototype.createMerchantInfo=function(t){var e=i({},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 r(this,void 0,void 0,(function(){var t,e,n,o,i,r,s,l;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),i=!1,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config))];case 2:return r=a.sent(),i=r.result&&!this.config.existingPaymentMethodRequired||r.result&&r.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(i){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==r?void 0:r.result)&&this.paymentMethodPresent===(null==r?void 0:r.paymentMethodPresent)||(this.isReadyToPay=!!(null==r?void 0:r.result),this.paymentMethodPresent=null==r?void 0:r.paymentMethodPresent,this.config.onReadyToPayChange&&(l={isButtonVisible:i,isReadyToPay:this.isReadyToPay},this.paymentMethodPresent&&(l.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(l))),[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(),i="default-google-style-"+this.options.cssSelector.replace(/[^\w-]+/g,"")+"-"+(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,i))){var r=document.createElement("style");r.id=i,r.type="text/css",r.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(r):o.appendChild(r)}}},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="google-pay-button-container";return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.manager=new u({cssSelector:"."+d,softwareInfoId:c,softwareInfoVersion:"2.6.0"}),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 r(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.mount(t)]:[3,2];case 1:e.sent(),this.manager.configure(this.props),e.label=2;case 2: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:[d,this.props.className].filter((function(t){return t})).join(" "),style:this.props.style})},e}(n.default.Component)})); | ||
***************************************************************************** */var i=function(){return(i=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e,n,o){return new(n||(n=Promise))((function(i,r){function a(t){try{l(o.next(t))}catch(t){r(t)}}function s(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}l((o=o.apply(t,e||[])).next())}))}function a(t,e){var n,o,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(r){return function(s){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return a.label++,{value:r[1],done:!1};case 5:a.label++,o=r[1],r=[0];continue;case 7:r=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){a=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){a.label=r[1];break}if(6===r[0]&&a.label<i[1]){a.label=i[1],i=r;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(r);break}i[2]&&a.ops.pop(),a.trys.pop();continue}r=e.call(t,a)}catch(t){r=[6,t],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,s])}}}var s={};function l(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 i=function(){e()},r=function(){o.removeEventListener("load",i),o.removeEventListener("error",r),delete s[t],o.remove(),n(new Error("Unable to load script "+t))};o.addEventListener("load",i),o.addEventListener("error",r),document.body.appendChild(o)}));return s[t]=n,n}var u=function(){function t(t){var e=this;this.handleClick=function(t){return r(e,void 0,void 0,(function(){var e,n,o,i;return a(this,(function(r){switch(r.label){case 0:if(!(e=this.config))throw new Error("google-pay-button: Missing configuration");n=this.createLoadPaymentDataRequest(e),r.label=1;case 1:return r.trys.push([1,3,,4]),e.onClick&&e.onClick(t),t.defaultPrevented?[2]:[4,this.client.loadPaymentData(n)];case 2:return o=r.sent(),e.onLoadPaymentData&&e.onLoadPaymentData(o),[3,4];case 3:return"CANCELED"===(i=r.sent()).statusCode?e.onCancel&&e.onCancel(i):e.onError?e.onError(i):console.error(i),[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){return r(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return this.isGooglePayLoaded()?[3,2]:[4,l("https://pay.google.com/gp/p/js/pay.js")];case 1:e.sent(),e.label=2;case 2: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 i(i({},t.paymentRequest),{merchantInfo:this.createMerchantInfo(t)})},t.prototype.createMerchantInfo=function(t){var e=i({},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 r(this,void 0,void 0,(function(){var t,e,n,o,i,r,s,l;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),i=!1,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config))];case 2:return r=a.sent(),i=r.result&&!this.config.existingPaymentMethodRequired||r.result&&r.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(i){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==r?void 0:r.result)&&this.paymentMethodPresent===(null==r?void 0:r.paymentMethodPresent)||(this.isReadyToPay=!!(null==r?void 0:r.result),this.paymentMethodPresent=null==r?void 0:r.paymentMethodPresent,this.config.onReadyToPayChange&&(l={isButtonVisible:i,isReadyToPay:this.isReadyToPay},this.paymentMethodPresent&&(l.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(l))),[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(),i="default-google-style-"+this.options.cssSelector.replace(/[^\w-]+/g,"")+"-"+(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,i))){var r=document.createElement("style");r.id=i,r.type="text/css",r.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(r):o.appendChild(r)}}},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="google-pay-button-container";return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.manager=new u({cssSelector:"."+d,softwareInfoId:c,softwareInfoVersion:"3.0.0"}),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 r(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.mount(t)]:[3,2];case 1:e.sent(),this.manager.configure(this.props),e.label=2;case 2: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:[d,this.props.className].filter((function(t){return t})).join(" "),style:this.props.style})},e}(n.default.Component)})); |
@@ -413,3 +413,3 @@ import React from 'react'; | ||
var name = "@google-pay/button-react"; | ||
var version = "2.6.0"; | ||
var version = "3.0.0"; | ||
@@ -416,0 +416,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){return t(this,void 0,void 0,(function*(){this.isGooglePayLoaded()||(yield o("https://pay.google.com/gp/p/js/pay.js")),this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t=void 0;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:"2.6.0"}),this.elementRef=e.createRef()}componentDidMount(){return t(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.mount(e),this.manager.configure(this.props))}))}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){return t(this,void 0,void 0,(function*(){this.isGooglePayLoaded()||(yield o("https://pay.google.com/gp/p/js/pay.js")),this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t=void 0;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.0"}),this.elementRef=e.createRef()}componentDidMount(){return t(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.mount(e),this.manager.configure(this.props))}))}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}; |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.GooglePayButton = factory(global.React)); | ||
}(this, (function (React) { 'use strict'; | ||
})(this, (function (React) { 'use strict'; | ||
@@ -422,3 +422,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var name = "@google-pay/button-react"; | ||
var version = "2.6.0"; | ||
var version = "3.0.0"; | ||
@@ -444,3 +444,3 @@ /** | ||
*/ | ||
class GooglePayButton extends React__default['default'].Component { | ||
class GooglePayButton extends React__default["default"].Component { | ||
constructor() { | ||
@@ -453,3 +453,3 @@ super(...arguments); | ||
}); | ||
this.elementRef = React__default['default'].createRef(); | ||
this.elementRef = React__default["default"].createRef(); | ||
} | ||
@@ -472,3 +472,3 @@ componentDidMount() { | ||
render() { | ||
return (React__default['default'].createElement("div", { ref: this.elementRef, className: [CLASS, this.props.className].filter(c => c).join(' '), style: this.props.style })); | ||
return (React__default["default"].createElement("div", { ref: this.elementRef, className: [CLASS, this.props.className].filter(c => c).join(' '), style: this.props.style })); | ||
} | ||
@@ -495,2 +495,2 @@ } | ||
}))); | ||
})); |
@@ -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){return o(this,void 0,void 0,(function*(){this.isGooglePayLoaded()||(yield a("https://pay.google.com/gp/p/js/pay.js")),this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t=void 0;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:"2.6.0"}),this.elementRef=n.default.createRef()}componentDidMount(){return o(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.mount(e),this.manager.configure(this.props))}))}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){return o(this,void 0,void 0,(function*(){this.isGooglePayLoaded()||(yield a("https://pay.google.com/gp/p/js/pay.js")),this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t=void 0;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.0"}),this.elementRef=n.default.createRef()}componentDidMount(){return o(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.mount(e),this.manager.configure(this.props))}))}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": "2.6.0", | ||
"version": "3.0.0", | ||
"description": "React component for Google Pay button", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.es5.min.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92707