diff --git a/woocommerce/i18n/languages/woocommerce-plugin-framework-et.po b/woocommerce/i18n/languages/woocommerce-plugin-framework-et.po index 59aae20c7..ee7cd53cc 100644 --- a/woocommerce/i18n/languages/woocommerce-plugin-framework-et.po +++ b/woocommerce/i18n/languages/woocommerce-plugin-framework-et.po @@ -387,7 +387,7 @@ msgid "" "processing real payments." msgstr "" -#: payment-gateway/External_Checkout/Google_Pay/Frontend.php:130 +#: payment-gateway/External_Checkout/Google_Pay/Frontend.php:131 #: payment-gateway/External_Checkout/apple-pay/class-sv-wc-payment-gateway-apple-pay-frontend.php:141 #: payment-gateway/api/class-sv-wc-payment-gateway-api-response-message-helper.php:99 msgid "An error occurred, please try again or try an alternate form of payment" diff --git a/woocommerce/i18n/languages/woocommerce-plugin-framework.pot b/woocommerce/i18n/languages/woocommerce-plugin-framework.pot index 4727f9c8b..c368b54fd 100644 --- a/woocommerce/i18n/languages/woocommerce-plugin-framework.pot +++ b/woocommerce/i18n/languages/woocommerce-plugin-framework.pot @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: WooCommerce Plugin Framework 5.11.7\n" "Report-Msgid-Bugs-To: https://support.woocommerce.com/hc/\n" -"POT-Creation-Date: 2023-07-28 09:06:33+00:00\n" +"POT-Creation-Date: 2023-07-28 09:14:36+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -374,7 +374,7 @@ msgid "" "processing real payments." msgstr "" -#: payment-gateway/External_Checkout/Google_Pay/Frontend.php:130 +#: payment-gateway/External_Checkout/Google_Pay/Frontend.php:131 #: payment-gateway/External_Checkout/apple-pay/class-sv-wc-payment-gateway-apple-pay-frontend.php:141 #: payment-gateway/api/class-sv-wc-payment-gateway-api-response-message-helper.php:99 msgid "An error occurred, please try again or try an alternate form of payment" diff --git a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php index 3ef8ee052..7540c37fe 100644 --- a/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php +++ b/woocommerce/payment-gateway/External_Checkout/Google_Pay/Frontend.php @@ -120,6 +120,7 @@ protected function get_js_handler_args() { 'merchant_name' => get_bloginfo( 'name' ), 'gateway_id' => $this->get_gateway()->get_id(), 'gateway_id_dasherized' => $this->get_gateway()->get_id_dasherized(), + 'environment' => $this->get_gateway()->get_environment() == 'production' ? 'PRODUCTION' : 'TEST', 'ajax_url' => admin_url( 'admin-ajax.php' ), 'recalculate_totals_nonce' => wp_create_nonce( 'wc_' . $this->get_gateway()->get_id() . '_google_pay_recalculate_totals' ), 'process_nonce' => wp_create_nonce( 'wc_' . $this->get_plugin()->get_gateway()->get_id() . '_google_pay_process_payment' ), diff --git a/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js b/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js index 4c01fe412..e334f4c41 100644 --- a/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js +++ b/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js @@ -1,4 +1,4 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c
  • '+t.join("
  • ")+"
  • "),this.uiElement.removeClass("processing").unblock(),e("html, body").animate({scrollTop:this.uiElement.offset().top-100},1e3)}},{key:"blockUI",value:function(){this.uiElement.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}},{key:"unblockUI",value:function(){this.uiElement.unblock()}}]),n}(),e(document.body).trigger("sv_wc_google_pay_handler_v5_11_8_loaded")}); +function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n
  • '+t.join("
  • ")+"
  • "),this.uiElement.removeClass("processing").unblock(),e("html, body").animate({scrollTop:this.uiElement.offset().top-100},1e3)}},{key:"blockUI",value:function(){this.uiElement.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}},{key:"unblockUI",value:function(){this.uiElement.unblock()}}]),n}(),e(document.body).trigger("sv_wc_google_pay_handler_v5_11_8_loaded")}); },{}]},{},["O8A1"], null) //# sourceMappingURL=../frontend/sv-wc-payment-gateway-google-pay.js.map \ No newline at end of file diff --git a/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js.map b/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js.map index dd535496d..f599d369e 100644 --- a/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js.map +++ b/woocommerce/payment-gateway/assets/dist/frontend/sv-wc-payment-gateway-google-pay.js.map @@ -1 +1 @@ -{"version":3,"sources":["frontend/sv-wc-payment-gateway-google-pay.js"],"names":["jQuery","$","window","SV_WC_Google_Pay_Handler_v5_11_8","params","_classCallCheck","plugin_id","merchant_id","merchant_name","gateway_id","ajax_url","gateway_id_dasherized","recalculate_totals_nonce","process_nonce","button_style","card_types","available_countries","currency_code","needs_shipping","generic_error","gatewayID","merchantID","merchantName","ajaxURL","recalculateTotalsNonce","processNonce","buttonStyle","availableCountries","currencyCode","needsShipping","genericError","product_id","productID","allowedCardNetworks","baseRequest","apiVersion","apiVersionMinor","tokenizationSpecification","type","parameters","baseCardPaymentMethod","allowedAuthMethods","billingAddressRequired","billingAddressParameters","format","phoneNumberRequired","cardPaymentMethod","Object","assign","paymentsClient","_createClass","key","value","allowedPaymentMethods","resolve","_this","getGoogleTransactionInfo","transactionInfo","paymentDataRequest","merchantInfo","merchantId","emailRequired","callbackIntents","shippingAddressRequired","shippingAddressParameters","getGoogleShippingAddressParameters","shippingOptionRequired","_this2","args","paymentDataCallbacks","onPaymentAuthorized","paymentData","onPaymentDataChanged","google","payments","api","PaymentsClient","_this3","blockUI","Promise","reject","processPayment","err","transactionState","error","intent","message","reason","unblockUI","intermediatePaymentData","_this4","shippingAddress","shippingOptionData","chosenShippingMethod","callbackTrigger","id","getUpdatedTotals","paymentDataRequestUpdate","newShippingOptionParameters","shippingOptions","length","getGoogleUnserviceableAddressError","failPayment","_this5","data","action","concat","post","response","success","JSON","parse","shippingMethod","_this6","allowedCountryCodes","_this7","button","getGooglePaymentsClient","createButton","onClick","event","onGooglePaymentButtonClicked","buttonColor","buttonSizeMode","document","getElementById","appendChild","_this8","getGooglePaymentDataRequest","totalPriceStatus","prefetchPaymentData","_this9","nonce","stringify","location","redirect","_this10","preventDefault","loadPaymentData","initProductPage","initCartPage","initCheckoutPage","initGooglePay","_this11","isReadyToPay","getGoogleIsReadyToPayRequest","then","result","addGooglePayButton","prefetchGooglePaymentData","catch","uiElement","_this12","parents","body","on","console","renderErrors","errors","remove","prepend","join","removeClass","unblock","animate","scrollTop","offset","top","block","overlayCSS","background","opacity","trigger"],"mappings":";AAimBG,SAAA,EAAA,GAAA,OAAA,EAAA,mBAAA,QAAA,iBAAA,OAAA,SAAA,SAAA,GAAA,cAAA,GAAA,SAAA,GAAA,OAAA,GAAA,mBAAA,QAAA,EAAA,cAAA,QAAA,IAAA,OAAA,UAAA,gBAAA,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AC,MAGA,WACC,KAAKmG,UAAYtJ,EAAG,eAGrB,CAAAkD,IAAA,eAAAC,MAGA,WAAe,IAAAoG,EAAA,KACd,KAAKD,UAAYtJ,EAAG,8BAA+BwJ,QAAS,mBAG5DxJ,EAAG2H,SAAS8B,MAAOC,GAAI,sBAAuB,WAC7CH,EAAKV,oBAIP,CAAA3F,IAAA,mBAAAC,MAGA,WACC,KAAKmG,UAAYtJ,EAAG,+BAGrB,CAAAkD,IAAA,cAAAC,MAGA,SAAagC,GAEZwE,QAAQxE,MAAO,gBAAkBA,GAEjC,KAAKI,YAEL,KAAKqE,aAAc,CAAE,KAAK/H,iBAG3B,CAAAqB,IAAA,eAAAC,MAGA,SAAc0G,GAGb7J,EAAG,4CAA6C8J,SAGhD,KAAKR,UAAUS,QAAS,qCAAuCF,EAAOG,KAAM,aAAgB,cAG5F,KAAKV,UAAUW,YAAa,cAAeC,UAG3ClK,EAAG,cAAemK,QAAS,CAAEC,UAAW,KAAKd,UAAUe,SAASC,IAAM,KAAO,OAG9E,CAAApH,IAAA,UAAAC,MAGA,WACC,KAAKmG,UAAUiB,MAAO,CAAElF,QAAS,KAAMmF,WAAY,CAAEC,WAAY,OAAQC,QAAS,QAGnF,CAAAxH,IAAA,YAAAC,MAGA,WACC,KAAKmG,UAAUY,cACfhK,EAjlBqC,GAolBvCF,EAAG2H,SAAS8B,MAAOkB,QAAS","file":"sv-wc-payment-gateway-google-pay.js","sourceRoot":"../js","sourcesContent":["jQuery( function( $ ) {\n\n\t\"use strict\"\n\n\t/**\n\t * Google Pay handler.\n\t *\n\t * @since 5.10.0\n\t *\n\t * @type {SV_WC_Google_Pay_Handler_v5_11_8} object\n\t */\n\twindow.SV_WC_Google_Pay_Handler_v5_11_8 = class SV_WC_Google_Pay_Handler_v5_11_8 {\n\n\t\t/**\n\t\t * Handler constructor.\n\t\t *\n\t\t * @since 5.10.0\n\t\t *\n\t\t * @param {Object} params The plugin ID\n\t\t * @param {string} params.plugin_id The plugin ID\n\t\t * @param {string} params.merchant_id The merchant ID\n\t\t * @param {string} params.merchant_name The site name\n\t\t * @param {string} params.gateway_id The gateway ID\n\t\t * @param {string} params.gateway_id_dasherized The gateway ID dasherized\n\t\t * @param {string} params.ajax_url The AJAX URL\n\t\t * @param {string} params.recalculate_totals_nonce Nonce for the recalculate_totals AJAX action\n\t\t * @param {string} params.process_nonce Nonce for the process AJAX action\n\t\t * @param {string} params.button_style The button style\n\t\t * @param {string[]} params.card_types The supported card types\n\t\t * @param {string[]} params.available_countries Array of two-letter country codes the gateway is available for\n\t\t * @param {string[]} params.currency_code WC configured currency\n\t\t * @param {boolean} params.needs_shipping Whether or not the cart or product needs shipping\n\t\t * @param {string} params.generic_error The generic error message\n\t\t * @param {string} params.product_id The product ID if we are on a Product page\n\t\t */\n\t\tconstructor( params ) {\n\n\t\t\tlet {\n\t\t\t\tplugin_id,\n\t\t\t\tmerchant_id,\n\t\t\t\tmerchant_name,\n\t\t\t\tgateway_id,\n\t\t\t\tgateway_id_dasherized,\n\t\t\t\tajax_url,\n\t\t\t\trecalculate_totals_nonce,\n\t\t\t\tprocess_nonce,\n\t\t\t\tbutton_style,\n\t\t\t\tcard_types,\n\t\t\t\tavailable_countries,\n\t\t\t\tcurrency_code,\n\t\t\t\tneeds_shipping,\n\t\t\t\tgeneric_error\n\t\t\t} = params;\n\n\t\t\tthis.gatewayID = gateway_id;\n\t\t\tthis.merchantID = merchant_id;\n\t\t\tthis.merchantName = merchant_name;\n\t\t\tthis.ajaxURL = ajax_url;\n\t\t\tthis.recalculateTotalsNonce = recalculate_totals_nonce;\n\t\t\tthis.processNonce = process_nonce;\n\t\t\tthis.buttonStyle = button_style;\n\t\t\tthis.availableCountries = available_countries;\n\t\t\tthis.currencyCode = currency_code;\n\t\t\tthis.needsShipping = needs_shipping;\n\t\t\tthis.genericError = generic_error;\n\n\t\t\tif ( params.product_id ) {\n\t\t\t\tthis.productID = params.product_id;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Card networks supported by your site and your gateway\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t */\n\t\t\tconst allowedCardNetworks = card_types;\n\n\t\t\t/**\n\t\t\t * Define the version of the Google Pay API referenced when creating your configuration\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest|apiVersion in PaymentDataRequest}\n\t\t\t */\n\t\t\tthis.baseRequest = {\n\t\t\t\tapiVersion: 2,\n\t\t\t\tapiVersionMinor: 0\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Card authentication methods supported by your site and your gateway\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t *\n\t\t\t * @todo confirm your processor supports Android device tokens for your supported card networks\n\t\t\t */\n\t\t\tconst allowedCardAuthMethods = [ 'PAN_ONLY', 'CRYPTOGRAM_3DS' ];\n\n\t\t\t/**\n\t\t\t * Identify your gateway and your site's gateway merchant identifier\n\t\t\t *\n\t\t\t * The Google Pay API response will return an encrypted payment method capable\n\t\t\t * of being charged by a supported gateway after payer authorization\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#gateway|PaymentMethodTokenizationSpecification}\n\t\t\t */\n\t\t\tconst tokenizationSpecification = {\n\t\t\t\ttype: 'PAYMENT_GATEWAY',\n\t\t\t\tparameters: {\n\t\t\t\t\t'gateway': plugin_id,\n\t\t\t\t\t'gatewayMerchantId': this.merchantID\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Describe your site's support for the CARD payment method and its required fields\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t */\n\t\t\tthis.baseCardPaymentMethod = {\n\t\t\t\ttype: 'CARD',\n\t\t\t\tparameters: {\n\t\t\t\t\tallowedAuthMethods: allowedCardAuthMethods,\n\t\t\t\t\tallowedCardNetworks: allowedCardNetworks,\n\t\t\t\t\tbillingAddressRequired: true,\n\t\t\t\t\tbillingAddressParameters: {\n\t\t\t\t\t\tformat: 'FULL',\n\t\t\t\t\t\tphoneNumberRequired: true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Describe your site's support for the CARD payment method including optional fields\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t */\n\t\t\tthis.cardPaymentMethod = Object.assign(\n\t\t\t\t{},\n\t\t\t\tthis.baseCardPaymentMethod,\n\t\t\t\t{\n\t\t\t\t\ttokenizationSpecification: tokenizationSpecification\n\t\t\t\t}\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * An initialized google.payments.api.PaymentsClient object or null if not yet set\n\t\t\t *\n\t\t\t * @see {@link getGooglePaymentsClient}\n\t\t\t */\n\t\t\tthis.paymentsClient = null;\n\t\t}\n\n\t\t/**\n\t\t * Configure your site's support for payment methods supported by the Google Pay\n\t\t * API.\n\t\t *\n\t\t * Each member of allowedPaymentMethods should contain only the required fields,\n\t\t * allowing reuse of this base request when determining a viewer's ability\n\t\t * to pay and later requesting a supported payment method\n\t\t *\n\t\t * @returns {object} Google Pay API version, payment methods supported by the site\n\t\t */\n\t\tgetGoogleIsReadyToPayRequest() {\n\n\t\t\treturn Object.assign(\n\t\t\t\t{},\n\t\t\t\tthis.baseRequest,\n\t\t\t\t{\n\t\t\t\t\tallowedPaymentMethods: [ this.baseCardPaymentMethod ]\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Configure support for the Google Pay API\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest|PaymentDataRequest}\n\t\t *\n\t\t * @param {function} resolve callback\n\t\t * @returns {object} PaymentDataRequest fields\n\t\t */\n\t\tgetGooglePaymentDataRequest( resolve ) {\n\n\t\t\treturn this.getGoogleTransactionInfo( ( transactionInfo ) => {\n\n\t\t\t\tconst paymentDataRequest = Object.assign( {}, this.baseRequest );\n\t\t\t\tpaymentDataRequest.allowedPaymentMethods = [ this.cardPaymentMethod ];\n\t\t\t\tpaymentDataRequest.transactionInfo = transactionInfo;\n\t\t\t\tpaymentDataRequest.merchantInfo = {\n\t\t\t\t\tmerchantId: this.merchantID,\n\t\t\t\t\tmerchantName: this.merchantName\n\t\t\t\t};\n\n\t\t\t\tpaymentDataRequest.emailRequired = true;\n\t\t\t\tpaymentDataRequest.callbackIntents = [ 'PAYMENT_AUTHORIZATION' ];\n\n\t\t\t\tif ( this.needsShipping ) {\n\t\t\t\t\tpaymentDataRequest.callbackIntents = [ 'SHIPPING_ADDRESS', 'SHIPPING_OPTION', 'PAYMENT_AUTHORIZATION' ];\n\t\t\t\t\tpaymentDataRequest.shippingAddressRequired = true;\n\t\t\t\t\tpaymentDataRequest.shippingAddressParameters = this.getGoogleShippingAddressParameters();\n\t\t\t\t\tpaymentDataRequest.shippingOptionRequired = true;\n\t\t\t\t}\n\n\t\t\t\tresolve( paymentDataRequest );\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Return an active PaymentsClient or initialize\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/client#PaymentsClient|PaymentsClient constructor}\n\t\t * @returns {google.payments.api.PaymentsClient} Google Pay API client\n\t\t */\n\t\tgetGooglePaymentsClient() {\n\t\t\tif ( this.paymentsClient === null ) {\n\t\t\t\tlet args = {\n\t\t\t\t\tmerchantInfo: {\n\t\t\t\t\t\tmerchantName: this.merchantName,\n\t\t\t\t\t\tmerchantId: this.merchantID\n\t\t\t\t\t},\n\t\t\t\t\tpaymentDataCallbacks: {\n\t\t\t\t\t\tonPaymentAuthorized: ( paymentData ) => this.onPaymentAuthorized( paymentData ),\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tif ( this.needsShipping ) {\n\t\t\t\t\targs.paymentDataCallbacks.onPaymentDataChanged = ( paymentData ) => this.onPaymentDataChanged( paymentData );\n\t\t\t\t}\n\n\t\t\t\tthis.paymentsClient = new google.payments.api.PaymentsClient( args );\n\t\t\t}\n\t\t\treturn this.paymentsClient;\n\t\t}\n\n\t\t/**\n\t\t * Handles payment authorization callback intent.\n\t\t *\n\t\t * @param {object} paymentData response from Google Pay API after a payer approves payment.\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentData|PaymentData object reference}\n\t\t *\n\t\t * @returns Promise<{object}> Promise object to complete or fail the transaction.\n\t\t */\n\t\tonPaymentAuthorized( paymentData ) {\n\n\t\t\tthis.blockUI();\n\n\t\t\treturn new Promise( (resolve, reject) => {\n\n\t\t\t\t// handle the response\n\t\t\t\ttry {\n\t\t\t\t\tthis.processPayment( paymentData, resolve );\n\t\t\t\t}\tcatch( err ) {\n\t\t\t\t\treject( {\n\t\t\t\t\t\ttransactionState: 'ERROR',\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tintent: 'PAYMENT_AUTHORIZATION',\n\t\t\t\t\t\t\tmessage: 'Payment could not be processed',\n\t\t\t\t\t\t\treason: 'PAYMENT_DATA_INVALID'\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tthis.unblockUI();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Handles dynamic buy flow shipping address and shipping options callback intents.\n\t\t *\n\t\t * @param {object} intermediatePaymentData response from Google Pay API a shipping address or shipping option is selected in the payment sheet.\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#IntermediatePaymentData|IntermediatePaymentData object reference}\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentDataRequestUpdate|PaymentDataRequestUpdate}\n\t\t * @returns Promise<{object}> Promise of PaymentDataRequestUpdate object to update the payment sheet.\n\t\t */\n\t\tonPaymentDataChanged( intermediatePaymentData ) {\n\n\t\t\tthis.blockUI();\n\n\t\t\treturn new Promise(( resolve, reject ) => {\n\n\t\t\t\ttry {\n\t\t\t\t\tlet shippingAddress = intermediatePaymentData.shippingAddress;\n\t\t\t\t\tlet shippingOptionData = intermediatePaymentData.shippingOptionData;\n\t\t\t\t\tlet chosenShippingMethod = '';\n\n\t\t\t\t\tif ( intermediatePaymentData.callbackTrigger == 'SHIPPING_OPTION' ) {\n\t\t\t\t\t\tchosenShippingMethod = shippingOptionData.id;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.getUpdatedTotals( shippingAddress, chosenShippingMethod, ( paymentDataRequestUpdate ) => {\n\n\t\t\t\t\t\tif ( paymentDataRequestUpdate.newShippingOptionParameters.shippingOptions.length == 0 ) {\n\t\t\t\t\t\t\tpaymentDataRequestUpdate = {\n\t\t\t\t\t\t\t\terror: this.getGoogleUnserviceableAddressError()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve( paymentDataRequestUpdate );\n\t\t\t\t\t} );\n\n\t\t\t\t}\tcatch( err ) {\n\t\t\t\t\tthis.failPayment( 'Could not load updated totals or process payment data request update. ' + err );\n\t\t\t\t}\n\n\t\t\t\tthis.unblockUI();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Provide Google Pay API with a payment amount, currency, and amount status\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#TransactionInfo|TransactionInfo}\n\t\t *\n\t\t * @param {function} resolve callback\n\t\t * @returns {object} transaction info, suitable for use as transactionInfo property of PaymentDataRequest\n\t\t */\n\t\tgetGoogleTransactionInfo( resolve ) {\n\n\t\t\t// get transaction info from cart\n\t\t\tconst data = {\n\t\t\t\taction: `wc_${this.gatewayID}_google_pay_get_transaction_info`,\n\t\t\t}\n\n\t\t\tif ( this.productID ) {\n\t\t\t\tdata.productID = this.productID;\n\t\t\t}\n\n\t\t\t$.post( this.ajaxURL, data, ( response ) => {\n\n\t\t\t\tif ( response.success ) {\n\t\t\t\t\tresolve( JSON.parse( response.data ) )\n\t\t\t\t} else {\n\t\t\t\t\tthis.failPayment( 'Could not build transaction info. ' + response.data.message );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Get updated totals and shipping options via AJAX for use in the PaymentDataRequest\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentDataRequestUpdate|PaymentDataRequestUpdate}\n\t\t *\n\t\t * @param {object} shippingAddress shipping address\n\t\t * @param {object} shippingMethod chosen shipping method\n\t\t * @param {function} resolve callback\n\t\t */\n\t\tgetUpdatedTotals( shippingAddress, shippingMethod, resolve ) {\n\n\t\t\tconst data = {\n\t\t\t\taction: `wc_${this.gatewayID}_google_pay_recalculate_totals`,\n\t\t\t\t'nonce': this.recalculateTotalsNonce,\n\t\t\t\tshippingAddress,\n\t\t\t\tshippingMethod\n\t\t\t}\n\n\t\t\tif ( this.productID ) {\n\t\t\t\tdata.productID = this.productID;\n\t\t\t}\n\n\t\t\t$.post( this.ajaxURL, data, ( response ) => {\n\n\t\t\t\tif ( response.success ) {\n\t\t\t\t\tresolve( JSON.parse( response.data ) )\n\t\t\t\t} else {\n\t\t\t\t\tthis.failPayment( 'Could not recalculate totals. ' + response.data.message );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Provide Google Pay API with shipping address parameters when using dynamic buy flow.\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ShippingAddressParameters|ShippingAddressParameters}\n\t\t * @returns {object} shipping address details, suitable for use as shippingAddressParameters property of PaymentDataRequest\n\t\t */\n\t\tgetGoogleShippingAddressParameters() {\n\n\t\t\treturn {\n\t\t\t\tallowedCountryCodes: this.availableCountries\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Provide Google Pay API with a payment data error.\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentDataError|PaymentDataError}\n\t\t * @returns {object} payment data error, suitable for use as error property of PaymentDataRequestUpdate\n\t\t */\n\t\tgetGoogleUnserviceableAddressError() {\n\t\t\treturn {\n\t\t\t\treason: 'SHIPPING_ADDRESS_UNSERVICEABLE',\n\t\t\t\tmessage: 'Cannot ship to the selected address',\n\t\t\t\tintent: 'SHIPPING_ADDRESS'\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Add a Google Pay purchase button alongside an existing checkout button\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions|Button options}\n\t\t * @see {@link https://developers.google.com/pay/api/web/guides/brand-guidelines|Google Pay brand guidelines}\n\t\t */\n\t\taddGooglePayButton() {\n\n\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\tconst button = paymentsClient.createButton( {\n\t\t\t\tonClick: ( event ) => this.onGooglePaymentButtonClicked( event ),\n\t\t\t\tbuttonColor: this.buttonStyle,\n\t\t\t\tbuttonSizeMode: 'fill'\n\t\t\t} );\n\t\t\tdocument.getElementById( 'sv-wc-google-pay-button-container' ).appendChild( button );\n\t\t}\n\n\t\t/**\n\t\t * Prefetch payment data to improve performance\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/client#prefetchPaymentData|prefetchPaymentData()}\n\t\t */\n\t\tprefetchGooglePaymentData() {\n\n\t\t\tthis.getGooglePaymentDataRequest( ( paymentDataRequest ) => {\n\n\t\t\t\t// transactionInfo must be set but does not affect cache\n\t\t\t\tpaymentDataRequest.transactionInfo = {\n\t\t\t\t\ttotalPriceStatus: 'NOT_CURRENTLY_KNOWN',\n\t\t\t\t\tcurrencyCode: this.currencyCode\n\t\t\t\t};\n\t\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\t\tpaymentsClient.prefetchPaymentData( paymentDataRequest );\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Process payment data returned by the Google Pay API\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentData|PaymentData object reference}\n\t\t *\n\t\t * @param {object} paymentData response from Google Pay API after user approves payment\n\t\t * @param {function} resolve callback\n\t\t */\n\t\tprocessPayment( paymentData, resolve ) {\n\n\t\t\t// pass payment token to your gateway to process payment\n\t\t\tconst data = {\n\t\t\t\taction: `wc_${this.gatewayID}_google_pay_process_payment`,\n\t\t\t\tnonce: this.processNonce,\n\t\t\t\tpaymentData: JSON.stringify( paymentData ),\n\t\t\t}\n\n\t\t\tif ( this.productID && ! this.needsShipping ) {\n\t\t\t\tdata.productID = this.productID;\n\t\t\t}\n\n\t\t\treturn $.post( this.ajaxURL, data, ( response ) => {\n\t\t\t\tif ( response.success ) {\n\t\t\t\t\tresolve( {\n\t\t\t\t\t\ttransactionState: 'SUCCESS'\n\t\t\t\t\t} );\n\t\t\t\t\twindow.location = response.data.redirect;\n\t\t\t\t} else {\n\t\t\t\t\tresolve( {\n\t\t\t\t\t\ttransactionState: 'ERROR',\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tintent: 'SHIPPING_ADDRESS',\n\t\t\t\t\t\t\tmessage: 'Invalid data',\n\t\t\t\t\t\t\treason: 'PAYMENT_DATA_INVALID'\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t\tthis.failPayment( 'Payment could not be processed. ' + response.data.message );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Show Google Pay payment sheet when Google Pay payment button is clicked\n\t\t */\n\t\tonGooglePaymentButtonClicked( event ) {\n\n\t\t\tevent.preventDefault();\n\n\t\t\tthis.blockUI();\n\n\t\t\tthis.getGooglePaymentDataRequest( ( paymentDataRequest ) => {\n\n\t\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\t\ttry {\n\t\t\t\t\tpaymentsClient.loadPaymentData( paymentDataRequest );\n\t\t\t\t} catch ( err ) {\n\t\t\t\t\tthis.failPayment( 'Could not load payment data. ' + err );\n\t\t\t\t}\n\n\t\t\t\tthis.unblockUI();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Initialize Google PaymentsClient after Google-hosted JavaScript has loaded\n\t\t *\n\t\t * Display a Google Pay payment button after confirmation of the viewer's\n\t\t * ability to pay.\n\t\t */\n\t\tinit() {\n\n\t\t\t// initialize for the various pages\n\t\t\tif ( $( 'form.cart' ).length ) {\n\t\t\t\tthis.initProductPage();\n\t\t\t} else if ( $( 'form.woocommerce-cart-form' ).length ) {\n\t\t\t\tthis.initCartPage();\n\t\t\t} else if ( $( 'form.woocommerce-checkout' ).length) {\n\t\t\t\tthis.initCheckoutPage()\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.initGooglePay();\n\t\t}\n\n\t\t/**\n\t\t * Initializes Google Pay.\n\t\t */\n\t\tinitGooglePay() {\n\n\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\tpaymentsClient.isReadyToPay( this.getGoogleIsReadyToPayRequest() )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( response.result ) {\n\t\t\t\t\t\tthis.addGooglePayButton();\n\t\t\t\t\t\t// prefetch payment data to improve performance\n\t\t\t\t\t\tthis.prefetchGooglePaymentData();\n\t\t\t\t\t}\n\t\t\t\t} )\n\t\t\t\t.catch( ( err ) => {\n\t\t\t\t\tthis.failPayment( 'Google Pay is not ready. ' + err );\n\t\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Initializes the product page.\n\t\t */\n\t\tinitProductPage() {\n\t\t\tthis.uiElement = $( 'form.cart' );\n\t\t}\n\n\t\t/**\n\t\t * Initializes the cart page.\n\t\t */\n\t\tinitCartPage() {\n\t\t\tthis.uiElement = $( 'form.woocommerce-cart-form' ).parents( 'div.woocommerce' );\n\n\t\t\t// re-init if the cart totals are updated\n\t\t\t$( document.body ).on( 'updated_cart_totals', () => {\n\t\t\t\tthis.initGooglePay();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Initializes the checkout page.\n\t\t */\n\t\tinitCheckoutPage() {\n\t\t\tthis.uiElement = $( 'form.woocommerce-checkout' );\n\t\t}\n\n\t\t/**\n\t\t * Fails the purchase based on the gateway result.\n\t\t */\n\t\tfailPayment( error ) {\n\n\t\t\tconsole.error( '[Google Pay] ' + error );\n\n\t\t\tthis.unblockUI();\n\n\t\t\tthis.renderErrors( [ this.genericError ] );\n\t\t}\n\n\t\t/**\n\t\t * Renders any new errors and bring them into the viewport.\n \t\t */\n\t\trenderErrors( errors ) {\n\n\t\t\t// hide and remove any previous errors\n\t\t\t$( '.woocommerce-error, .woocommerce-message' ).remove();\n\n\t\t\t// add errors\n\t\t\tthis.uiElement.prepend( '' );\n\n\t\t\t// unblock UI\n\t\t\tthis.uiElement.removeClass( 'processing' ).unblock();\n\n\t\t\t// scroll to top\n\t\t\t$( 'html, body' ).animate( { scrollTop: this.uiElement.offset().top - 100 }, 1000 );\n\t\t}\n\n\t\t/**\n\t\t * Blocks the payment form UI.\n\t\t */\n\t\tblockUI() {\n\t\t\tthis.uiElement.block( { message: null, overlayCSS: { background: '#fff', opacity: 0.6 } } );\n\t\t}\n\n\t\t/**\n\t\t * Unblocks the payment form UI.\n\t\t */\n\t\tunblockUI() {\n\t\t\tthis.uiElement.unblock();\n\t\t}\n\t}\n\n\t$( document.body ).trigger( 'sv_wc_google_pay_handler_v5_11_8_loaded' );\n\n} );\n"]} \ No newline at end of file +{"version":3,"sources":["frontend/sv-wc-payment-gateway-google-pay.js"],"names":["jQuery","$","window","SV_WC_Google_Pay_Handler_v5_11_8","params","_classCallCheck","plugin_id","merchant_id","merchant_name","gateway_id","environment","gateway_id_dasherized","ajax_url","recalculate_totals_nonce","process_nonce","button_style","card_types","available_countries","currency_code","needs_shipping","generic_error","gatewayID","merchantID","merchantName","ajaxURL","recalculateTotalsNonce","processNonce","buttonStyle","availableCountries","currencyCode","needsShipping","genericError","product_id","productID","allowedCardNetworks","baseRequest","apiVersion","apiVersionMinor","tokenizationSpecification","type","parameters","baseCardPaymentMethod","allowedAuthMethods","billingAddressRequired","billingAddressParameters","format","phoneNumberRequired","cardPaymentMethod","Object","assign","paymentsClient","_createClass","key","value","allowedPaymentMethods","resolve","_this","getGoogleTransactionInfo","transactionInfo","paymentDataRequest","merchantInfo","merchantId","emailRequired","callbackIntents","shippingAddressRequired","shippingAddressParameters","getGoogleShippingAddressParameters","shippingOptionRequired","_this2","args","paymentDataCallbacks","onPaymentAuthorized","paymentData","onPaymentDataChanged","google","payments","api","PaymentsClient","_this3","blockUI","Promise","reject","processPayment","err","transactionState","error","intent","message","reason","unblockUI","intermediatePaymentData","_this4","shippingAddress","shippingOptionData","chosenShippingMethod","callbackTrigger","id","getUpdatedTotals","paymentDataRequestUpdate","newShippingOptionParameters","shippingOptions","length","getGoogleUnserviceableAddressError","failPayment","_this5","data","action","concat","post","response","success","JSON","parse","shippingMethod","_this6","allowedCountryCodes","_this7","button","getGooglePaymentsClient","createButton","onClick","event","onGooglePaymentButtonClicked","buttonColor","buttonSizeMode","document","getElementById","appendChild","_this8","getGooglePaymentDataRequest","totalPriceStatus","prefetchPaymentData","_this9","nonce","stringify","location","redirect","_this10","preventDefault","loadPaymentData","initProductPage","initCartPage","initCheckoutPage","initGooglePay","_this11","isReadyToPay","getGoogleIsReadyToPayRequest","then","result","addGooglePayButton","prefetchGooglePaymentData","catch","uiElement","_this12","parents","body","on","console","renderErrors","errors","remove","prepend","join","removeClass","unblock","animate","scrollTop","offset","top","block","overlayCSS","background","opacity","trigger"],"mappings":";AAqmBG,SAAA,EAAA,GAAA,OAAA,EAAA,mBAAA,QAAA,iBAAA,OAAA,SAAA,SAAA,GAAA,cAAA,GAAA,SAAA,GAAA,OAAA,GAAA,mBAAA,QAAA,EAAA,cAAA,QAAA,IAAA,OAAA,UAAA,gBAAA,IAAA,GAAA,SAAA,EAAA,EAAA,GAAA,KAAA,aAAA,GAAA,MAAA,IAAA,UAAA,qCAAA,SAAA,EAAA,EAAA,GAAA,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,OAAA,IAAA,CAAA,IAAA,EAAA,EAAA,GAAA,EAA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vJ,EAAG,8BAA+ByJ,QAAS,mBAG5DzJ,EAAG4H,SAAS8B,MAAOC,GAAI,sBAAuB,WAC7CH,EAAKV,oBAIP,CAAA3F,IAAA,mBAAAC,MAGA,WACC,KAAKmG,UAAYvJ,EAAG,+BAGrB,CAAAmD,IAAA,cAAAC,MAGA,SAAagC,GAEZwE,QAAQxE,MAAO,gBAAkBA,GAEjC,KAAKI,YAEL,KAAKqE,aAAc,CAAE,KAAK/H,iBAG3B,CAAAqB,IAAA,eAAAC,MAGA,SAAc0G,GAGb9J,EAAG,4CAA6C+J,SAGhD,KAAKR,UAAUS,QAAS,qCAAuCF,EAAOG,KAAM,aAAgB,cAG5F,KAAKV,UAAUW,YAAa,cAAeC,UAG3CnK,EAAG,cAAeoK,QAAS,CAAEC,UAAW,KAAKd,UAAUe,SAASC,IAAM,KAAO,OAG9E,CAAApH,IAAA,UAAAC,MAGA,WACC,KAAKmG,UAAUiB,MAAO,CAAElF,QAAS,KAAMmF,WAAY,CAAEC,WAAY,OAAQC,QAAS,QAGnF,CAAAxH,IAAA,YAAAC,MAGA,WACC,KAAKmG,UAAUY,cACfjK,EArlBqC,GAwlBvCF,EAAG4H,SAAS8B,MAAOkB,QAAS","file":"sv-wc-payment-gateway-google-pay.js","sourceRoot":"../js","sourcesContent":["jQuery( function( $ ) {\n\n\t\"use strict\"\n\n\t/**\n\t * Google Pay handler.\n\t *\n\t * @since 5.10.0\n\t *\n\t * @type {SV_WC_Google_Pay_Handler_v5_11_8} object\n\t */\n\twindow.SV_WC_Google_Pay_Handler_v5_11_8 = class SV_WC_Google_Pay_Handler_v5_11_8 {\n\n\t\t/**\n\t\t * Handler constructor.\n\t\t *\n\t\t * @since 5.10.0\n\t\t *\n\t\t * @param {Object} params The plugin ID\n\t\t * @param {string} params.plugin_id The plugin ID\n\t\t * @param {string} params.merchant_id The merchant ID\n\t\t * @param {string} params.merchant_name The site name\n\t\t * @param {string} params.gateway_id The gateway ID\n\t\t * @param {string} params.gateway_id_dasherized The gateway ID dasherized\n\t\t * @param {string} params.environment The gateway environment (PRODUCTION or TEST)\n\t\t * @param {string} params.ajax_url The AJAX URL\n\t\t * @param {string} params.recalculate_totals_nonce Nonce for the recalculate_totals AJAX action\n\t\t * @param {string} params.process_nonce Nonce for the process AJAX action\n\t\t * @param {string} params.button_style The button style\n\t\t * @param {string[]} params.card_types The supported card types\n\t\t * @param {string[]} params.available_countries Array of two-letter country codes the gateway is available for\n\t\t * @param {string[]} params.currency_code WC configured currency\n\t\t * @param {boolean} params.needs_shipping Whether or not the cart or product needs shipping\n\t\t * @param {string} params.generic_error The generic error message\n\t\t * @param {string} params.product_id The product ID if we are on a Product page\n\t\t */\n\t\tconstructor( params ) {\n\n\t\t\tlet {\n\t\t\t\tplugin_id,\n\t\t\t\tmerchant_id,\n\t\t\t\tmerchant_name,\n\t\t\t\tgateway_id,\n\t\t\t\tgateway_id_dasherized,\n\t\t\t\tenvironment,\n\t\t\t\tajax_url,\n\t\t\t\trecalculate_totals_nonce,\n\t\t\t\tprocess_nonce,\n\t\t\t\tbutton_style,\n\t\t\t\tcard_types,\n\t\t\t\tavailable_countries,\n\t\t\t\tcurrency_code,\n\t\t\t\tneeds_shipping,\n\t\t\t\tgeneric_error\n\t\t\t} = params;\n\n\t\t\tthis.gatewayID = gateway_id;\n\t\t\tthis.merchantID = merchant_id;\n\t\t\tthis.merchantName = merchant_name;\n\t\t\tthis.environment = environment;\n\t\t\tthis.ajaxURL = ajax_url;\n\t\t\tthis.recalculateTotalsNonce = recalculate_totals_nonce;\n\t\t\tthis.processNonce = process_nonce;\n\t\t\tthis.buttonStyle = button_style;\n\t\t\tthis.availableCountries = available_countries;\n\t\t\tthis.currencyCode = currency_code;\n\t\t\tthis.needsShipping = needs_shipping;\n\t\t\tthis.genericError = generic_error;\n\n\t\t\tif ( params.product_id ) {\n\t\t\t\tthis.productID = params.product_id;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Card networks supported by your site and your gateway\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t */\n\t\t\tconst allowedCardNetworks = card_types;\n\n\t\t\t/**\n\t\t\t * Define the version of the Google Pay API referenced when creating your configuration\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest|apiVersion in PaymentDataRequest}\n\t\t\t */\n\t\t\tthis.baseRequest = {\n\t\t\t\tapiVersion: 2,\n\t\t\t\tapiVersionMinor: 0\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Card authentication methods supported by your site and your gateway\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t *\n\t\t\t * @todo confirm your processor supports Android device tokens for your supported card networks\n\t\t\t */\n\t\t\tconst allowedCardAuthMethods = [ 'PAN_ONLY', 'CRYPTOGRAM_3DS' ];\n\n\t\t\t/**\n\t\t\t * Identify your gateway and your site's gateway merchant identifier\n\t\t\t *\n\t\t\t * The Google Pay API response will return an encrypted payment method capable\n\t\t\t * of being charged by a supported gateway after payer authorization\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#gateway|PaymentMethodTokenizationSpecification}\n\t\t\t */\n\t\t\tconst tokenizationSpecification = {\n\t\t\t\ttype: 'PAYMENT_GATEWAY',\n\t\t\t\tparameters: {\n\t\t\t\t\t'gateway': plugin_id,\n\t\t\t\t\t'gatewayMerchantId': this.merchantID\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Describe your site's support for the CARD payment method and its required fields\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t */\n\t\t\tthis.baseCardPaymentMethod = {\n\t\t\t\ttype: 'CARD',\n\t\t\t\tparameters: {\n\t\t\t\t\tallowedAuthMethods: allowedCardAuthMethods,\n\t\t\t\t\tallowedCardNetworks: allowedCardNetworks,\n\t\t\t\t\tbillingAddressRequired: true,\n\t\t\t\t\tbillingAddressParameters: {\n\t\t\t\t\t\tformat: 'FULL',\n\t\t\t\t\t\tphoneNumberRequired: true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t/**\n\t\t\t * Describe your site's support for the CARD payment method including optional fields\n\t\t\t *\n\t\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}\n\t\t\t */\n\t\t\tthis.cardPaymentMethod = Object.assign(\n\t\t\t\t{},\n\t\t\t\tthis.baseCardPaymentMethod,\n\t\t\t\t{\n\t\t\t\t\ttokenizationSpecification: tokenizationSpecification\n\t\t\t\t}\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * An initialized google.payments.api.PaymentsClient object or null if not yet set\n\t\t\t *\n\t\t\t * @see {@link getGooglePaymentsClient}\n\t\t\t */\n\t\t\tthis.paymentsClient = null;\n\t\t}\n\n\t\t/**\n\t\t * Configure your site's support for payment methods supported by the Google Pay\n\t\t * API.\n\t\t *\n\t\t * Each member of allowedPaymentMethods should contain only the required fields,\n\t\t * allowing reuse of this base request when determining a viewer's ability\n\t\t * to pay and later requesting a supported payment method\n\t\t *\n\t\t * @returns {object} Google Pay API version, payment methods supported by the site\n\t\t */\n\t\tgetGoogleIsReadyToPayRequest() {\n\n\t\t\treturn Object.assign(\n\t\t\t\t{},\n\t\t\t\tthis.baseRequest,\n\t\t\t\t{\n\t\t\t\t\tallowedPaymentMethods: [ this.baseCardPaymentMethod ]\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Configure support for the Google Pay API\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest|PaymentDataRequest}\n\t\t *\n\t\t * @param {function} resolve callback\n\t\t * @returns {object} PaymentDataRequest fields\n\t\t */\n\t\tgetGooglePaymentDataRequest( resolve ) {\n\n\t\t\treturn this.getGoogleTransactionInfo( ( transactionInfo ) => {\n\n\t\t\t\tconst paymentDataRequest = Object.assign( {}, this.baseRequest );\n\t\t\t\tpaymentDataRequest.allowedPaymentMethods = [ this.cardPaymentMethod ];\n\t\t\t\tpaymentDataRequest.transactionInfo = transactionInfo;\n\t\t\t\tpaymentDataRequest.merchantInfo = {\n\t\t\t\t\tmerchantId: this.merchantID,\n\t\t\t\t\tmerchantName: this.merchantName\n\t\t\t\t};\n\n\t\t\t\tpaymentDataRequest.emailRequired = true;\n\t\t\t\tpaymentDataRequest.callbackIntents = [ 'PAYMENT_AUTHORIZATION' ];\n\n\t\t\t\tif ( this.needsShipping ) {\n\t\t\t\t\tpaymentDataRequest.callbackIntents = [ 'SHIPPING_ADDRESS', 'SHIPPING_OPTION', 'PAYMENT_AUTHORIZATION' ];\n\t\t\t\t\tpaymentDataRequest.shippingAddressRequired = true;\n\t\t\t\t\tpaymentDataRequest.shippingAddressParameters = this.getGoogleShippingAddressParameters();\n\t\t\t\t\tpaymentDataRequest.shippingOptionRequired = true;\n\t\t\t\t}\n\n\t\t\t\tresolve( paymentDataRequest );\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Return an active PaymentsClient or initialize\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/client#PaymentsClient|PaymentsClient constructor}\n\t\t * @returns {google.payments.api.PaymentsClient} Google Pay API client\n\t\t */\n\t\tgetGooglePaymentsClient() {\n\t\t\tif ( this.paymentsClient === null ) {\n\t\t\t\tlet args = {\n\t\t\t\t\tenvironment: this.environment,\n\t\t\t\t\tmerchantInfo: {\n\t\t\t\t\t\tmerchantName: this.merchantName,\n\t\t\t\t\t\tmerchantId: this.merchantID\n\t\t\t\t\t},\n\t\t\t\t\tpaymentDataCallbacks: {\n\t\t\t\t\t\tonPaymentAuthorized: ( paymentData ) => this.onPaymentAuthorized( paymentData ),\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tif ( this.needsShipping ) {\n\t\t\t\t\targs.paymentDataCallbacks.onPaymentDataChanged = ( paymentData ) => this.onPaymentDataChanged( paymentData );\n\t\t\t\t}\n\n\t\t\t\tthis.paymentsClient = new google.payments.api.PaymentsClient( args );\n\t\t\t}\n\t\t\treturn this.paymentsClient;\n\t\t}\n\n\t\t/**\n\t\t * Handles payment authorization callback intent.\n\t\t *\n\t\t * @param {object} paymentData response from Google Pay API after a payer approves payment.\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentData|PaymentData object reference}\n\t\t *\n\t\t * @returns Promise<{object}> Promise object to complete or fail the transaction.\n\t\t */\n\t\tonPaymentAuthorized( paymentData ) {\n\n\t\t\tthis.blockUI();\n\n\t\t\treturn new Promise( (resolve, reject) => {\n\n\t\t\t\t// handle the response\n\t\t\t\ttry {\n\t\t\t\t\tthis.processPayment( paymentData, resolve );\n\t\t\t\t}\tcatch( err ) {\n\t\t\t\t\treject( {\n\t\t\t\t\t\ttransactionState: 'ERROR',\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tintent: 'PAYMENT_AUTHORIZATION',\n\t\t\t\t\t\t\tmessage: 'Payment could not be processed',\n\t\t\t\t\t\t\treason: 'PAYMENT_DATA_INVALID'\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tthis.unblockUI();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Handles dynamic buy flow shipping address and shipping options callback intents.\n\t\t *\n\t\t * @param {object} intermediatePaymentData response from Google Pay API a shipping address or shipping option is selected in the payment sheet.\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#IntermediatePaymentData|IntermediatePaymentData object reference}\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentDataRequestUpdate|PaymentDataRequestUpdate}\n\t\t * @returns Promise<{object}> Promise of PaymentDataRequestUpdate object to update the payment sheet.\n\t\t */\n\t\tonPaymentDataChanged( intermediatePaymentData ) {\n\n\t\t\tthis.blockUI();\n\n\t\t\treturn new Promise(( resolve, reject ) => {\n\n\t\t\t\ttry {\n\t\t\t\t\tlet shippingAddress = intermediatePaymentData.shippingAddress;\n\t\t\t\t\tlet shippingOptionData = intermediatePaymentData.shippingOptionData;\n\t\t\t\t\tlet chosenShippingMethod = '';\n\n\t\t\t\t\tif ( intermediatePaymentData.callbackTrigger == 'SHIPPING_OPTION' ) {\n\t\t\t\t\t\tchosenShippingMethod = shippingOptionData.id;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.getUpdatedTotals( shippingAddress, chosenShippingMethod, ( paymentDataRequestUpdate ) => {\n\n\t\t\t\t\t\tif ( paymentDataRequestUpdate.newShippingOptionParameters.shippingOptions.length == 0 ) {\n\t\t\t\t\t\t\tpaymentDataRequestUpdate = {\n\t\t\t\t\t\t\t\terror: this.getGoogleUnserviceableAddressError()\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve( paymentDataRequestUpdate );\n\t\t\t\t\t} );\n\n\t\t\t\t}\tcatch( err ) {\n\t\t\t\t\tthis.failPayment( 'Could not load updated totals or process payment data request update. ' + err );\n\t\t\t\t}\n\n\t\t\t\tthis.unblockUI();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Provide Google Pay API with a payment amount, currency, and amount status\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#TransactionInfo|TransactionInfo}\n\t\t *\n\t\t * @param {function} resolve callback\n\t\t * @returns {object} transaction info, suitable for use as transactionInfo property of PaymentDataRequest\n\t\t */\n\t\tgetGoogleTransactionInfo( resolve ) {\n\n\t\t\t// get transaction info from cart\n\t\t\tconst data = {\n\t\t\t\taction: `wc_${this.gatewayID}_google_pay_get_transaction_info`,\n\t\t\t}\n\n\t\t\tif ( this.productID ) {\n\t\t\t\tdata.productID = this.productID;\n\t\t\t}\n\n\t\t\t$.post( this.ajaxURL, data, ( response ) => {\n\n\t\t\t\tif ( response.success ) {\n\t\t\t\t\tresolve( JSON.parse( response.data ) )\n\t\t\t\t} else {\n\t\t\t\t\tthis.failPayment( 'Could not build transaction info. ' + response.data.message );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Get updated totals and shipping options via AJAX for use in the PaymentDataRequest\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentDataRequestUpdate|PaymentDataRequestUpdate}\n\t\t *\n\t\t * @param {object} shippingAddress shipping address\n\t\t * @param {object} shippingMethod chosen shipping method\n\t\t * @param {function} resolve callback\n\t\t */\n\t\tgetUpdatedTotals( shippingAddress, shippingMethod, resolve ) {\n\n\t\t\tconst data = {\n\t\t\t\taction: `wc_${this.gatewayID}_google_pay_recalculate_totals`,\n\t\t\t\t'nonce': this.recalculateTotalsNonce,\n\t\t\t\tshippingAddress,\n\t\t\t\tshippingMethod\n\t\t\t}\n\n\t\t\tif ( this.productID ) {\n\t\t\t\tdata.productID = this.productID;\n\t\t\t}\n\n\t\t\t$.post( this.ajaxURL, data, ( response ) => {\n\n\t\t\t\tif ( response.success ) {\n\t\t\t\t\tresolve( JSON.parse( response.data ) )\n\t\t\t\t} else {\n\t\t\t\t\tthis.failPayment( 'Could not recalculate totals. ' + response.data.message );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Provide Google Pay API with shipping address parameters when using dynamic buy flow.\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ShippingAddressParameters|ShippingAddressParameters}\n\t\t * @returns {object} shipping address details, suitable for use as shippingAddressParameters property of PaymentDataRequest\n\t\t */\n\t\tgetGoogleShippingAddressParameters() {\n\n\t\t\treturn {\n\t\t\t\tallowedCountryCodes: this.availableCountries\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Provide Google Pay API with a payment data error.\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentDataError|PaymentDataError}\n\t\t * @returns {object} payment data error, suitable for use as error property of PaymentDataRequestUpdate\n\t\t */\n\t\tgetGoogleUnserviceableAddressError() {\n\t\t\treturn {\n\t\t\t\treason: 'SHIPPING_ADDRESS_UNSERVICEABLE',\n\t\t\t\tmessage: 'Cannot ship to the selected address',\n\t\t\t\tintent: 'SHIPPING_ADDRESS'\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Add a Google Pay purchase button alongside an existing checkout button\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions|Button options}\n\t\t * @see {@link https://developers.google.com/pay/api/web/guides/brand-guidelines|Google Pay brand guidelines}\n\t\t */\n\t\taddGooglePayButton() {\n\n\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\tconst button = paymentsClient.createButton( {\n\t\t\t\tonClick: ( event ) => this.onGooglePaymentButtonClicked( event ),\n\t\t\t\tbuttonColor: this.buttonStyle,\n\t\t\t\tbuttonSizeMode: 'fill'\n\t\t\t} );\n\t\t\tdocument.getElementById( 'sv-wc-google-pay-button-container' ).appendChild( button );\n\t\t}\n\n\t\t/**\n\t\t * Prefetch payment data to improve performance\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/client#prefetchPaymentData|prefetchPaymentData()}\n\t\t */\n\t\tprefetchGooglePaymentData() {\n\n\t\t\tthis.getGooglePaymentDataRequest( ( paymentDataRequest ) => {\n\n\t\t\t\t// transactionInfo must be set but does not affect cache\n\t\t\t\tpaymentDataRequest.transactionInfo = {\n\t\t\t\t\ttotalPriceStatus: 'NOT_CURRENTLY_KNOWN',\n\t\t\t\t\tcurrencyCode: this.currencyCode\n\t\t\t\t};\n\t\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\t\tpaymentsClient.prefetchPaymentData( paymentDataRequest );\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Process payment data returned by the Google Pay API\n\t\t *\n\t\t * @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentData|PaymentData object reference}\n\t\t *\n\t\t * @param {object} paymentData response from Google Pay API after user approves payment\n\t\t * @param {function} resolve callback\n\t\t */\n\t\tprocessPayment( paymentData, resolve ) {\n\n\t\t\t// pass payment token to your gateway to process payment\n\t\t\tconst data = {\n\t\t\t\taction: `wc_${this.gatewayID}_google_pay_process_payment`,\n\t\t\t\tnonce: this.processNonce,\n\t\t\t\tpaymentData: JSON.stringify( paymentData ),\n\t\t\t}\n\n\t\t\tif ( this.productID && ! this.needsShipping ) {\n\t\t\t\tdata.productID = this.productID;\n\t\t\t}\n\n\t\t\treturn $.post( this.ajaxURL, data, ( response ) => {\n\t\t\t\tif ( response.success ) {\n\t\t\t\t\tresolve( {\n\t\t\t\t\t\ttransactionState: 'SUCCESS'\n\t\t\t\t\t} );\n\t\t\t\t\twindow.location = response.data.redirect;\n\t\t\t\t} else {\n\t\t\t\t\tresolve( {\n\t\t\t\t\t\ttransactionState: 'ERROR',\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tintent: 'SHIPPING_ADDRESS',\n\t\t\t\t\t\t\tmessage: 'Invalid data',\n\t\t\t\t\t\t\treason: 'PAYMENT_DATA_INVALID'\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t\tthis.failPayment( 'Payment could not be processed. ' + response.data.message );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Show Google Pay payment sheet when Google Pay payment button is clicked\n\t\t */\n\t\tonGooglePaymentButtonClicked( event ) {\n\n\t\t\tevent.preventDefault();\n\n\t\t\tthis.blockUI();\n\n\t\t\tthis.getGooglePaymentDataRequest( ( paymentDataRequest ) => {\n\n\t\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\t\ttry {\n\t\t\t\t\tpaymentsClient.loadPaymentData( paymentDataRequest );\n\t\t\t\t} catch ( err ) {\n\t\t\t\t\tthis.failPayment( 'Could not load payment data. ' + err );\n\t\t\t\t}\n\n\t\t\t\tthis.unblockUI();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Initialize Google PaymentsClient after Google-hosted JavaScript has loaded\n\t\t *\n\t\t * Display a Google Pay payment button after confirmation of the viewer's\n\t\t * ability to pay.\n\t\t */\n\t\tinit() {\n\n\t\t\t// initialize for the various pages\n\t\t\tif ( $( 'form.cart' ).length ) {\n\t\t\t\tthis.initProductPage();\n\t\t\t} else if ( $( 'form.woocommerce-cart-form' ).length ) {\n\t\t\t\tthis.initCartPage();\n\t\t\t} else if ( $( 'form.woocommerce-checkout' ).length) {\n\t\t\t\tthis.initCheckoutPage()\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.initGooglePay();\n\t\t}\n\n\t\t/**\n\t\t * Initializes Google Pay.\n\t\t */\n\t\tinitGooglePay() {\n\n\t\t\tconst paymentsClient = this.getGooglePaymentsClient();\n\t\t\tpaymentsClient.isReadyToPay( this.getGoogleIsReadyToPayRequest() )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( response.result ) {\n\t\t\t\t\t\tthis.addGooglePayButton();\n\t\t\t\t\t\t// prefetch payment data to improve performance\n\t\t\t\t\t\tthis.prefetchGooglePaymentData();\n\t\t\t\t\t}\n\t\t\t\t} )\n\t\t\t\t.catch( ( err ) => {\n\t\t\t\t\tthis.failPayment( 'Google Pay is not ready. ' + err );\n\t\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Initializes the product page.\n\t\t */\n\t\tinitProductPage() {\n\t\t\tthis.uiElement = $( 'form.cart' );\n\t\t}\n\n\t\t/**\n\t\t * Initializes the cart page.\n\t\t */\n\t\tinitCartPage() {\n\t\t\tthis.uiElement = $( 'form.woocommerce-cart-form' ).parents( 'div.woocommerce' );\n\n\t\t\t// re-init if the cart totals are updated\n\t\t\t$( document.body ).on( 'updated_cart_totals', () => {\n\t\t\t\tthis.initGooglePay();\n\t\t\t} );\n\t\t}\n\n\t\t/**\n\t\t * Initializes the checkout page.\n\t\t */\n\t\tinitCheckoutPage() {\n\t\t\tthis.uiElement = $( 'form.woocommerce-checkout' );\n\t\t}\n\n\t\t/**\n\t\t * Fails the purchase based on the gateway result.\n\t\t */\n\t\tfailPayment( error ) {\n\n\t\t\tconsole.error( '[Google Pay] ' + error );\n\n\t\t\tthis.unblockUI();\n\n\t\t\tthis.renderErrors( [ this.genericError ] );\n\t\t}\n\n\t\t/**\n\t\t * Renders any new errors and bring them into the viewport.\n \t\t */\n\t\trenderErrors( errors ) {\n\n\t\t\t// hide and remove any previous errors\n\t\t\t$( '.woocommerce-error, .woocommerce-message' ).remove();\n\n\t\t\t// add errors\n\t\t\tthis.uiElement.prepend( '' );\n\n\t\t\t// unblock UI\n\t\t\tthis.uiElement.removeClass( 'processing' ).unblock();\n\n\t\t\t// scroll to top\n\t\t\t$( 'html, body' ).animate( { scrollTop: this.uiElement.offset().top - 100 }, 1000 );\n\t\t}\n\n\t\t/**\n\t\t * Blocks the payment form UI.\n\t\t */\n\t\tblockUI() {\n\t\t\tthis.uiElement.block( { message: null, overlayCSS: { background: '#fff', opacity: 0.6 } } );\n\t\t}\n\n\t\t/**\n\t\t * Unblocks the payment form UI.\n\t\t */\n\t\tunblockUI() {\n\t\t\tthis.uiElement.unblock();\n\t\t}\n\t}\n\n\t$( document.body ).trigger( 'sv_wc_google_pay_handler_v5_11_8_loaded' );\n\n} );\n"]} \ No newline at end of file diff --git a/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js b/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js index 12fd0d12c..3f27fb4c2 100644 --- a/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js +++ b/woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-google-pay.js @@ -22,6 +22,7 @@ jQuery( function( $ ) { * @param {string} params.merchant_name The site name * @param {string} params.gateway_id The gateway ID * @param {string} params.gateway_id_dasherized The gateway ID dasherized + * @param {string} params.environment The gateway environment (PRODUCTION or TEST) * @param {string} params.ajax_url The AJAX URL * @param {string} params.recalculate_totals_nonce Nonce for the recalculate_totals AJAX action * @param {string} params.process_nonce Nonce for the process AJAX action @@ -41,6 +42,7 @@ jQuery( function( $ ) { merchant_name, gateway_id, gateway_id_dasherized, + environment, ajax_url, recalculate_totals_nonce, process_nonce, @@ -55,6 +57,7 @@ jQuery( function( $ ) { this.gatewayID = gateway_id; this.merchantID = merchant_id; this.merchantName = merchant_name; + this.environment = environment; this.ajaxURL = ajax_url; this.recalculateTotalsNonce = recalculate_totals_nonce; this.processNonce = process_nonce; @@ -213,6 +216,7 @@ jQuery( function( $ ) { getGooglePaymentsClient() { if ( this.paymentsClient === null ) { let args = { + environment: this.environment, merchantInfo: { merchantName: this.merchantName, merchantId: this.merchantID