{"version":3,"sources":["frontend/sv-wc-payment-gateway-apple-pay.coffee"],"names":["jQuery","$","window","SV_WC_Apple_Pay_Handler_v5_12_7","args","init_product_page","bind","init_cart_page","init_checkout_page","on_validate_merchant","validate_merchant","on_payment_method_selected","on_shipping_contact_selected","on_shipping_method_selected","on_payment_authorized","process_authorization","on_cancel_payment","reset_payment_request","get_payment_request","gateway_id","gateway_slug","merchant_id","ajax_url","validate_nonce","recalculate_totals_nonce","process_nonce","payment_request","generic_error","wrapper","container","button","ApplePaySession","canMakePaymentsWithActiveCard","then","canMakePayments","children","length","hide","is_available","ui_element","show","document","body","on","e","error","preventDefault","block_ui","session","get_new_session","onvalidatemerchant","event","onpaymentmethodselected","onshippingcontactselected","onshippingmethodselected","onpaymentauthorized","oncancel","begin","error1","fail_payment","parents","get_sdk_version","validationURL","merchant_session","JSON","parse","completeMerchantValidation","response","abort","message","url","Promise","resolve","reject","data","post","success","completePaymentMethodSelection","total","line_items","console","lineItems","shippingContact","completeShippingContactSelection","STATUS_SUCCESS","shipping_methods","STATUS_FAILURE","shippingMethod","identifier","completeShippingMethodSelection","payment","set_payment_status","complete_purchase","action","nonce","stringify","unblock_ui","location","redirect","render_errors","status","completePayment","base_data","extend","errors","remove","prepend","join","removeClass","unblock","animate","scrollTop","offset","top","block","overlayCSS","background","opacity","trigger","call"],"mappings":";AAAA,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,EAAA,WAAA,EAAA,aAAA,EAAA,EAAA,cAAA,EA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OANPA,EAAE,4CAA4CwG,SAEzClE,KAAAA,WAAWmE,QAAQ,qCAAuCF,EAAOG,KAAK,aAAe,cAErFpE,KAAAA,WAAWqE,YAAY,cAAcC,UAEnC5G,EAAE,cAAc6G,QAAQ,CAC7BC,UAAW,KAAKxE,WAAWyE,SAASC,IAAM,KACzC,OAnYP,CAAA,IAAA,WAyYE,MAAA,WACS,OAAA,KAAK1E,WAAW2E,MAAM,CAC3B7C,QAAS,KACT8C,WAAY,CACVC,WAAY,OACZC,QAAS,QA9YjB,CAAA,IAAA,aAsZE,MAAA,WACS,OAAA,KAAK9E,WAAWsE,cAvZ3B,GA4ZO5G,EAAEwC,SAASC,MAAM4E,QAAQ,8CAGjCC,KAAK","file":"sv-wc-payment-gateway-apple-pay.js","sourceRoot":"../js","sourcesContent":["(function() {\n  /*\n   WooCommerce Apple Pay Handler\n   Version 4.7.0\n\n   Copyright (c) 2016, SkyVerge, Inc.\n   Licensed under the GNU General Public License v3.0\n   http://www.gnu.org/licenses/gpl-3.0.html\n  */\n  jQuery(function($) {\n    \"use strict\";\n    // The WooCommerce Apple Pay handler base class.\n\n    // @since 4.7.0\n    window.SV_WC_Apple_Pay_Handler_v5_12_7 = class SV_WC_Apple_Pay_Handler_v5_12_7 {\n      // Constructs the handler.\n\n      // @since 4.7.0\n      constructor(args) {\n        // Initializes the product page.\n\n        // @since 5.6.0\n        this.init_product_page = this.init_product_page.bind(this);\n        // Initializes the cart page.\n\n        // @since 5.6.0\n        this.init_cart_page = this.init_cart_page.bind(this);\n        // Initializes the checkout page.\n\n        // @since 5.6.0\n        this.init_checkout_page = this.init_checkout_page.bind(this);\n        // The callback for after the merchant data is validated.\n\n        // @since 4.7.0\n        this.on_validate_merchant = this.on_validate_merchant.bind(this);\n        // Validates the merchant data.\n\n        // @since 4.7.0\n        // @return object\n        this.validate_merchant = this.validate_merchant.bind(this);\n        // Fires after a payment method has been selected.\n\n        // @since 4.7.0\n        this.on_payment_method_selected = this.on_payment_method_selected.bind(this);\n        // Fires after a shipping contact has been selected.\n\n        // @since 4.7.0\n        this.on_shipping_contact_selected = this.on_shipping_contact_selected.bind(this);\n        // Fires after a shipping method has been selected.\n\n        // @since 4.7.0\n        this.on_shipping_method_selected = this.on_shipping_method_selected.bind(this);\n        // The callback for after the payment data is authorized.\n\n        // @since 4.7.0\n        this.on_payment_authorized = this.on_payment_authorized.bind(this);\n        // Processes the transaction data.\n\n        // @since 4.7.0\n        this.process_authorization = this.process_authorization.bind(this);\n        // The callback for when the payment card is cancelled/dismissed.\n\n        // @since 4.7.0\n        this.on_cancel_payment = this.on_cancel_payment.bind(this);\n        // Resets the payment request via AJAX.\n\n        // Extending handlers can call this on change events to refresh the data.\n\n        // @since 4.7.0\n        this.reset_payment_request = this.reset_payment_request.bind(this);\n        // Gets the payment request via AJAX.\n\n        // @since 4.7.0\n        this.get_payment_request = this.get_payment_request.bind(this);\n        this.gateway_id = args.gateway_id;\n        this.gateway_slug = args.gateway_slug;\n        this.merchant_id = args.merchant_id;\n        this.ajax_url = args.ajax_url;\n        this.validate_nonce = args.validate_nonce;\n        this.recalculate_totals_nonce = args.recalculate_totals_nonce;\n        this.process_nonce = args.process_nonce;\n        this.payment_request = args.payment_request;\n        this.generic_error = args.generic_error;\n        this.wrapper = '.sv-wc-external-checkout';\n        this.container = '.buttons-container';\n        this.button = '.sv-wc-apple-pay-button';\n      }\n\n      // Determines if Apple Pay is available.\n\n      // @since 4.7.0\n      // @return bool\n      is_available() {\n        if (!window.ApplePaySession) {\n          return false;\n        }\n        return ApplePaySession.canMakePaymentsWithActiveCard(this.merchant_id).then((canMakePayments) => {\n          return canMakePayments;\n        });\n      }\n\n      // Initializes the handler.\n\n      // @since 4.7.0\n      init() {\n        // hide the wrapper if Apple Pay is the only button\n        if ($(this.container).children().length === 1) {\n          $(this.wrapper).hide();\n        }\n        if (!this.is_available()) {\n          return;\n        }\n        // initialize for the various pages\n        if ($('form.cart').length) {\n          this.init_product_page();\n        } else if ($('form.woocommerce-cart-form').length) {\n          this.init_cart_page();\n        } else if ($('form.woocommerce-checkout').length) {\n          this.init_checkout_page();\n        }\n        // bail if no UI was initialized\n        if (!this.ui_element) {\n          return;\n        }\n        if (this.payment_request) {\n          $(this.button).show();\n          $(this.wrapper).show();\n        }\n        return $(document.body).on('click', '.sv-wc-apple-pay-button', (e) => {\n          var error;\n          e.preventDefault();\n          this.block_ui();\n          try {\n            this.session = this.get_new_session(this.payment_request);\n            // set the payment card events\n            this.session.onvalidatemerchant = (event) => {\n              return this.on_validate_merchant(event);\n            };\n            this.session.onpaymentmethodselected = (event) => {\n              return this.on_payment_method_selected(event);\n            };\n            this.session.onshippingcontactselected = (event) => {\n              return this.on_shipping_contact_selected(event);\n            };\n            this.session.onshippingmethodselected = (event) => {\n              return this.on_shipping_method_selected(event);\n            };\n            this.session.onpaymentauthorized = (event) => {\n              return this.on_payment_authorized(event);\n            };\n            this.session.oncancel = (event) => {\n              return this.on_cancel_payment(event);\n            };\n            return this.session.begin();\n          } catch (error1) {\n            error = error1;\n            return this.fail_payment(error);\n          }\n        });\n      }\n\n      init_product_page() {\n        return this.ui_element = $('form.cart');\n      }\n\n      init_cart_page() {\n        this.ui_element = $('form.woocommerce-cart-form').parents('div.woocommerce');\n        // re-init if the cart totals are updated\n        return $(document.body).on('updated_cart_totals', () => {\n          return this.reset_payment_request();\n        });\n      }\n\n      init_checkout_page() {\n        this.ui_element = $('form.woocommerce-checkout');\n        return $(document.body).on('updated_checkout', () => {\n          // re-init if the checkout is updated\n          return this.reset_payment_request();\n        });\n      }\n\n      // Gets a new Apple Pay session.\n\n      // @since 5.6.0\n\n      // @param [Object] payment_request payment request object\n      // @return ApplePaySession\n      get_new_session(payment_request) {\n        return new ApplePaySession(this.get_sdk_version(), payment_request);\n      }\n\n      // Gets the Apple SDK version to use.\n\n      // @since 5.6.0\n      // @return int\n      get_sdk_version() {\n        return 2;\n      }\n\n      on_validate_merchant(event) {\n        return this.validate_merchant(event.validationURL).then((merchant_session) => {\n          merchant_session = JSON.parse(merchant_session);\n          return this.session.completeMerchantValidation(merchant_session);\n        }, (response) => {\n          this.session.abort();\n          return this.fail_payment('Merchant could no be validated. ' + response.message);\n        });\n      }\n\n      validate_merchant(url) {\n        return new Promise((resolve, reject) => {\n          var data;\n          data = {\n            'action': `wc_${this.gateway_id}_apple_pay_validate_merchant`,\n            'nonce': this.validate_nonce,\n            'merchant_id': this.merchant_id,\n            'url': url\n          };\n          // retrieve a payment request object\n          return $.post(this.ajax_url, data, (response) => {\n            if (response.success) {\n              return resolve(response.data);\n            } else {\n              return reject(response.data);\n            }\n          });\n        });\n      }\n\n      on_payment_method_selected(event) {\n        return new Promise((resolve, reject) => {\n          var data;\n          data = {\n            'action': `wc_${this.gateway_id}_apple_pay_recalculate_totals`,\n            'nonce': this.recalculate_totals_nonce\n          };\n          // retrieve a payment request object\n          return $.post(this.ajax_url, data, (response) => {\n            if (response.success) {\n              data = response.data;\n              return resolve(this.session.completePaymentMethodSelection(data.total, data.line_items));\n            } else {\n              console.error('[Apple Pay] Error selecting a shipping contact. ' + response.data.message);\n              return reject(this.session.completePaymentMethodSelection(this.payment_request.total, this.payment_request.lineItems));\n            }\n          });\n        });\n      }\n\n      on_shipping_contact_selected(event) {\n        return new Promise((resolve, reject) => {\n          var data;\n          data = {\n            'action': `wc_${this.gateway_id}_apple_pay_recalculate_totals`,\n            'nonce': this.recalculate_totals_nonce,\n            'contact': event.shippingContact\n          };\n          // retrieve a payment request object\n          return $.post(this.ajax_url, data, (response) => {\n            if (response.success) {\n              data = response.data;\n              return resolve(this.session.completeShippingContactSelection(ApplePaySession.STATUS_SUCCESS, data.shipping_methods, data.total, data.line_items));\n            } else {\n              console.error('[Apple Pay] Error selecting a shipping contact. ' + response.data.message);\n              return reject(this.session.completeShippingContactSelection(ApplePaySession.STATUS_FAILURE, [], this.payment_request.total, this.payment_request.lineItems));\n            }\n          });\n        });\n      }\n\n      on_shipping_method_selected(event) {\n        return new Promise((resolve, reject) => {\n          var data;\n          data = {\n            'action': `wc_${this.gateway_id}_apple_pay_recalculate_totals`,\n            'nonce': this.recalculate_totals_nonce,\n            'method': event.shippingMethod.identifier\n          };\n          // retrieve a payment request object\n          return $.post(this.ajax_url, data, (response) => {\n            if (response.success) {\n              data = response.data;\n              return resolve(this.session.completeShippingMethodSelection(ApplePaySession.STATUS_SUCCESS, data.total, data.line_items));\n            } else {\n              console.error('[Apple Pay] Error selecting a shipping method. ' + response.data.message);\n              return reject(this.session.completeShippingMethodSelection(ApplePaySession.STATUS_FAILURE, this.payment_request.total, this.payment_request.lineItems));\n            }\n          });\n        });\n      }\n\n      on_payment_authorized(event) {\n        return this.process_authorization(event.payment).then((response) => {\n          this.set_payment_status(true);\n          return this.complete_purchase(response);\n        }, (response) => {\n          this.set_payment_status(false);\n          return this.fail_payment('Payment could no be processed. ' + response.message);\n        });\n      }\n\n      process_authorization(payment) {\n        return new Promise((resolve, reject) => {\n          var data;\n          data = {\n            action: `wc_${this.gateway_id}_apple_pay_process_payment`,\n            nonce: this.process_nonce,\n            payment: JSON.stringify(payment)\n          };\n          return $.post(this.ajax_url, data, (response) => {\n            if (response.success) {\n              return resolve(response.data);\n            } else {\n              return reject(response.data);\n            }\n          });\n        });\n      }\n\n      on_cancel_payment(event) {\n        return this.unblock_ui();\n      }\n\n      // Completes the purchase based on the gateway result.\n\n      // @since 4.7.0\n      complete_purchase(response) {\n        return window.location = response.redirect;\n      }\n\n      // Fails the purchase based on the gateway result.\n\n      // @since 4.7.0\n      fail_payment(error) {\n        console.error('[Apple Pay] ' + error);\n        this.unblock_ui();\n        return this.render_errors([this.generic_error]);\n      }\n\n      // Sets the Apple Pay payment status depending on the gateway result.\n\n      // @since 4.7.0\n      set_payment_status(success) {\n        var status;\n        if (success) {\n          status = ApplePaySession.STATUS_SUCCESS;\n        } else {\n          status = ApplePaySession.STATUS_FAILURE;\n        }\n        return this.session.completePayment(status);\n      }\n\n      reset_payment_request(data = {}) {\n        this.block_ui();\n        return this.get_payment_request(data).then((response) => {\n          $(this.button).show();\n          $(this.wrapper).show();\n          this.payment_request = JSON.parse(response);\n          return this.unblock_ui();\n        }, (response) => {\n          console.error('[Apple Pay] Could not build payment request. ' + response.message);\n          $(this.button).hide();\n          // hide the wrapper if Apple Pay is the only button\n          if ($(this.container).children().length === 1) {\n            $(this.wrapper).hide();\n          }\n          return this.unblock_ui();\n        });\n      }\n\n      get_payment_request(data) {\n        return new Promise((resolve, reject) => {\n          var base_data;\n          base_data = {\n            'action': `wc_${this.gateway_id}_apple_pay_get_payment_request`\n          };\n          $.extend(data, base_data);\n          // retrieve a payment request object\n          return $.post(this.ajax_url, data, (response) => {\n            if (response.success) {\n              return resolve(response.data);\n            } else {\n              return reject(response.data);\n            }\n          });\n        });\n      }\n\n      // Renders any new errors and bring them into the viewport.\n\n      // @since 4.7.0\n      render_errors(errors) {\n        // hide and remove any previous errors\n        $('.woocommerce-error, .woocommerce-message').remove();\n        // add errors\n        this.ui_element.prepend('<ul class=\"woocommerce-error\"><li>' + errors.join('</li><li>') + '</li></ul>');\n        // unblock UI\n        this.ui_element.removeClass('processing').unblock();\n        // scroll to top\n        return $('html, body').animate({\n          scrollTop: this.ui_element.offset().top - 100\n        }, 1000);\n      }\n\n      // Blocks the payment form UI.\n\n      // @since 4.7.0\n      block_ui() {\n        return this.ui_element.block({\n          message: null,\n          overlayCSS: {\n            background: '#fff',\n            opacity: 0.6\n          }\n        });\n      }\n\n      // Unblocks the payment form UI.\n\n      // @since 4.7.0\n      unblock_ui() {\n        return this.ui_element.unblock();\n      }\n\n    };\n    // dispatch loaded event\n    return $(document.body).trigger('sv_wc_apple_pay_handler_v5_12_7_loaded');\n  });\n\n}).call(this);\n"]}