{"version":3,"names":["LatepointPaymentsBraintreeAddon","_classCallCheck","this","hostedFieldsInstance","threeDSecure","ready","_createClass","key","value","_this","jQuery","document","on","e","data","latepoint_helper","demo_mode","is_final_submit","currentTarget","find","val","current_step","latepoint_add_action","callbacks_list","createToken","payment_method","initPaypalButton","initCreditCardForm","$booking_form_element","payload","deferred","Deferred","form_data","FormData","action","route_name","params","latepoint_formdata_to_url_encoded_string","layout","return_format","ajax","type","dataType","url","ajaxurl","success","status","resolve","amount","message","reject","error","request","_error","_this2","tokenize","then","getPaymentData","paymentData","verifyCard","onLookupComplete","next","nonce","bin","details","email","liabilityShifted","liabilityShiftPossible","catch","err","code","invalidFields","each","field","addClass","payment_amount","getPaymentAmount","braintree","client","create","authorization","braintree_client_token","clientInstance","paypalCheckout","paypalCheckoutInstance","loadPayPalSDK","currency","paypal_payment_currency","intent","paypal","Buttons","createOrder","createPayment","flow","onApprove","actions","removeClass","$latepoint_form","tokenizePayment","submit","render","_this3","html","Promise","all","hostedFields","styles","input","body_font_family","color","fields","postalCode","container","placeholder","cardholderName","number","cvv","expirationDate","version","instances","latepoint_show_next_btn","latepointPaymentsBraintreeAddon"],"sources":["../../lib/assets/javascripts/latepoint-payments-braintree.js"],"sourcesContent":["class LatepointPaymentsBraintreeAddon {\n\tconstructor(){\n\t\tthis.hostedFieldsInstance = null;\n\t\tthis.threeDSecure = null;\n\t\tthis.ready();\n\t}\n\n\tready(){\n\t\tjQuery(document).ready(() => {\n\t\t\tjQuery('body').on('latepoint:submitBookingForm', '.latepoint-booking-form-element', (e, data) => {\n\t if(!latepoint_helper.demo_mode && data.is_final_submit){\n\t \tlet payment_method = jQuery(e.currentTarget).find('input[name=\"booking[payment_method]\"]').val();\n\t \tswitch(payment_method){\n\t \t\tcase 'card':\n\t \t\tbreak;\n\t \t}\n\t }\n\t\t\t});\n\n\t\t\tjQuery('body').on('latepoint:nextStepClicked', '.latepoint-booking-form-element', (e, data) => {\n\t if(!latepoint_helper.demo_mode && (data.current_step == 'payment')){\n\t \tlet payment_method = jQuery(e.currentTarget).find('input[name=\"booking[payment_method]\"]').val();\n\t \tswitch(payment_method){\n\t \t\tcase 'card':\n\t\t\t \tlatepoint_add_action(data.callbacks_list, () => {\n\t\t\t\t\t\t\t\treturn this.createToken(jQuery(e.currentTarget), 'card');\n\t\t\t \t});\n\t \t\tbreak;\n\t \t}\n\t }\n\t\t\t});\n\n\t\t\tjQuery('body').on('latepoint:initPaymentMethod', '.latepoint-booking-form-element', (e, data) => {\n\t\t\t\tif(data.payment_method == 'paypal'){\n\t\t\t\t\tlatepoint_add_action(data.callbacks_list, () => {\n\t\t\t\t\t\treturn this.initPaypalButton(jQuery(e.currentTarget));\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif(data.payment_method == 'card'){\n\t\t\t\t\tlatepoint_add_action(data.callbacks_list, () => {\n\t\t\t\t\t\treturn this.initCreditCardForm(jQuery(e.currentTarget));\n\t \t});\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tjQuery('body').on('latepoint:initStep:payment', '.latepoint-booking-form-element', (e, data) => {\n\t\t\t\t\n\t\t\t});\n\t\t});\n\t}\n\n\n getPaymentData($booking_form_element, payment_method, payload){\n let deferred = jQuery.Deferred();\n\t\tlet form_data = new FormData($booking_form_element.find('.latepoint-form')[0]);\n var data = { \n \taction: 'latepoint_route_call', \n \troute_name: $booking_form_element.find('.lp-payment-method-content[data-payment-method=\"'+payment_method+'\"]').data('init-route'), \n \tparams: latepoint_formdata_to_url_encoded_string(form_data),\n \tlayout: 'none', \n \treturn_format: 'json' \n }\n jQuery.ajax({\n type : \"post\",\n dataType : \"json\",\n url : latepoint_helper.ajaxurl,\n data : data,\n success: (data) => {\n if(data.status === \"success\"){\n \tdeferred.resolve({amount: data.message, payload: payload});\n }else{\n \tdeferred.reject({message: data.message});\n }\n },\n error: function(request, status, error){\n \tdeferred.reject({message: error});\n }\n });\n\n return deferred;\n }\n\n\tcreateToken($booking_form_element, payment_method){\n let deferred = jQuery.Deferred();\n this.hostedFieldsInstance.tokenize().then(payload => {\n\t return this.getPaymentData($booking_form_element, payment_method, payload);\n }).then((paymentData) => {\n\t\t\treturn this.threeDSecure.verifyCard({\n\t\t\t onLookupComplete: (data, next) => {\n\t\t\t next();\n\t\t\t },\n\t\t\t amount: paymentData.amount,\n\t\t\t nonce: paymentData.payload.nonce,\n\t\t\t bin: paymentData.payload.details.bin,\n\t\t\t email: $booking_form_element.find('input[name=\"customer[email]\"]').val()\n\t\t\t})\n\t }).then(payload => {\n\t \tif(payload.liabilityShifted || (!payload.liabilityShifted && !payload.liabilityShiftPossible)){\n\t\t \t$booking_form_element.find('input[name=\"booking[payment_token]\"]').val(payload.nonce);\n\t\t \tdeferred.resolve();\n\t \t}else{\n\t\t \tdeferred.reject({message: '3D Secure Card Validation Failed'});\n\t \t}\n\t }).catch(err => {\n \tif(err.code == 'HOSTED_FIELDS_FIELDS_INVALID' && err.details.invalidFields){\n \t\tjQuery.each(err.details.invalidFields, function(key, field){\n \t\t\t$booking_form_element.find(field).addClass('braintree-hosted-fields-invalid');\n \t\t});\n \t}\n \tdeferred.reject({message: err.message});\n\t });\n\t return deferred;\n\t}\n\n\n\n\tgetPaymentAmount($booking_form_element){\n\t\tlet payment_portion = $booking_form_element.find('input[name=\"booking[payment_portion]\"]').val();\n\t\tlet payment_amount = (payment_portion == 'deposit') ? $booking_form_element.find('.lp-paypal-btn-trigger').data('deposit-amount') : $booking_form_element.find('.lp-paypal-btn-trigger').data('full-amount');\n\t\treturn payment_amount;\n\t}\n\n\n\tinitPaypalButton($booking_form_element){\n let deferred = jQuery.Deferred();\n \tlet payment_amount = this.getPaymentAmount($booking_form_element);\n\n\t\tbraintree.client.create({ authorization: latepoint_helper.braintree_client_token})\n\t\t\t.then(function (clientInstance) {\n\t\t\t // Create a PayPal Checkout component.\n\t\t\t return braintree.paypalCheckout.create({\n\t\t\t client: clientInstance\n\t\t\t });\n\t\t\t})\n\t\t\t.then(function (paypalCheckoutInstance) {\n\t\t\t return paypalCheckoutInstance.loadPayPalSDK({\n\t\t\t currency: latepoint_helper.paypal_payment_currency,\n\t\t\t intent: 'authorize'\n\t\t\t });\n\t\t\t})\n\t\t\t.then(function (paypalCheckoutInstance) {\n\t\t\t return paypal.Buttons({\n\t\t\t\t createOrder: function() {\n\t\t\t\t return paypalCheckoutInstance.createPayment({\n\t flow: 'checkout', // Required\n\t amount: payment_amount, // Required\n\t currency: latepoint_helper.paypal_payment_currency,\n\t intent: 'authorize' // Required\n\t // Your PayPal options here. For available options, see\n\t // http://braintree.github.io/braintree-web/current/PayPalCheckout.html#createPayment\n\t\t\t\t });\n\t\t\t\t },\n\t\t\t\t onApprove: function(data, actions) {\n\t\t\t\t\t\t$booking_form_element.removeClass('step-content-loaded').addClass('step-content-loading');\n\t\t\t\t\t\tlet $latepoint_form = $booking_form_element.find('.latepoint-form');\n\t\t\t\t // Authorize the transaction\n\t\t\t\t return paypalCheckoutInstance.tokenizePayment(data).then(function(payload) {\n\t\t\t\t // Get the authorization id\n\t\t\t\t $booking_form_element.find('input[name=\"booking[payment_token]\"]').val(payload.nonce);\n\t\t\t\t $latepoint_form.submit();\n\t\t\t\t });\n\t\t\t\t }\n\t\t\t\t}).render($booking_form_element.find('.lp-paypal-btn-trigger')[0]);\n\t\t\t})\n\t\t\t.then(function () {\n\t\t\t deferred.resolve();\n\t\t\t});\n\t\t\treturn deferred;\n\t}\n\n\tinitCreditCardForm($booking_form_element){\n let deferred = jQuery.Deferred();\n\t\t// reset fields just in case they were initialised before\n\t\t$booking_form_element.find('#payment_zip,#payment_name_on_card,#payment_card_number,#payment_card_cvc,#payment_card_expiration').html('');\n\t\tbraintree.client.create({ authorization: latepoint_helper.braintree_client_token })\n\t\t\t.then((clientInstance) => {\n\t\t\t\t\treturn Promise.all([\n\t\t\t\t braintree.hostedFields.create({\n\t\t\t\t client: clientInstance,\n\t\t\t\t styles: {\n\t\t\t\t 'input': {\n\t\t\t\t 'font-size': '14px',\n\t\t\t\t 'font-family': latepoint_helper.body_font_family,\n\t\t\t\t 'font-weight': '500',\n\t\t\t\t 'color': '#fff',\n\t\t\t\t },\n\t\t\t\t ':focus': {\n\t\t\t\t 'color': '#fff'\n\t\t\t\t },\n\t\t\t\t '::placeholder': {\n\t\t\t\t 'color': '#7d89b1'\n\t\t\t\t },\n\t\t\t\t '.valid': {\n\t\t\t\t 'color': '#fff'\n\t\t\t\t },\n\t\t\t\t '.invalid': {\n\t\t\t\t 'color': '#ff5a16'\n\t\t\t\t }\n\t\t\t\t },\n\t\t\t\t fields: {\n\t\t\t\t \tpostalCode: {\n\t\t\t\t \t\tcontainer: $booking_form_element.find('#payment_zip')[0],\n\t\t\t\t placeholder: $booking_form_element.find('#payment_zip').data('placeholder')\n\t\t\t\t \t},\n\t\t\t\t \tcardholderName: {\n\t\t\t\t \t\tcontainer: $booking_form_element.find('#payment_name_on_card')[0],\n\t\t\t\t placeholder: $booking_form_element.find('#payment_name_on_card').data('placeholder')\n\t\t\t\t \t},\n\t\t\t\t number: {\n\t\t\t\t container: $booking_form_element.find('#payment_card_number')[0],\n\t\t\t\t placeholder: $booking_form_element.find('#payment_card_number').data('placeholder')\n\t\t\t\t },\n\t\t\t\t cvv: {\n\t\t\t\t container: $booking_form_element.find('#payment_card_cvc')[0],\n\t\t\t\t placeholder: $booking_form_element.find('#payment_card_cvc').data('placeholder')\n\t\t\t\t },\n\t\t\t\t expirationDate: {\n\t\t\t\t container: $booking_form_element.find('#payment_card_expiration')[0],\n\t\t\t\t placeholder: $booking_form_element.find('#payment_card_expiration').data('placeholder')\n\t\t\t\t },\n\t\t\t\t }\n\t\t\t\t }),\n\t\t\t\t braintree.threeDSecure.create({\n\t\t\t\t client: clientInstance,\n\t\t\t version: 2\n\t\t\t })\n\t\t\t ]);\n\t\t\t\t})\n\t\t\t.then(instances => {\n\t \tthis.hostedFieldsInstance = instances[0];\n\t \tthis.threeDSecure = instances[1];\n \tlatepoint_show_next_btn($booking_form_element);\n \tdeferred.resolve();\n\t \t})\n\t .catch(err => {\n\t \tdeferred.reject({message: err});\n\t });\n return deferred;\n\t}\n}\n\nlet latepointPaymentsBraintreeAddon = new LatepointPaymentsBraintreeAddon();"],"mappings":"+kCAAMA,gCAA+B,WACpC,SAAAA,IAAaC,gBAAAC,KAAAF,GACZE,KAAKC,qBAAuB,KAC5BD,KAAKE,aAAe,KACpBF,KAAKG,OACN,CAyOC,OAzOAC,aAAAN,EAAA,EAAAO,IAAA,QAAAC,MAED,WAAO,IAAAC,EAAAP,KACNQ,OAAOC,UAAUN,OAAM,WACtBK,OAAO,QAAQE,GAAG,8BAA+B,mCAAmC,SAACC,EAAGC,IAChFC,iBAAiBC,WAAaF,EAAKG,iBACjBP,OAAOG,EAAEK,eAAeC,KAAK,yCAAyCC,KAMhG,IAEAV,OAAO,QAAQE,GAAG,4BAA6B,mCAAmC,SAACC,EAAGC,GAClF,IAAIC,iBAAiBC,WAAmC,WAArBF,EAAKO,cAGjC,SAFeX,OAAOG,EAAEK,eAAeC,KAAK,yCAAyCC,MAGzFE,qBAAqBR,EAAKS,gBAAgB,WAC5C,OAAOd,EAAKe,YAAYd,OAAOG,EAAEK,eAAgB,OAC/C,GAIP,IAEAR,OAAO,QAAQE,GAAG,8BAA+B,mCAAmC,SAACC,EAAGC,GAC7D,UAAvBA,EAAKW,gBACPH,qBAAqBR,EAAKS,gBAAgB,WACzC,OAAOd,EAAKiB,iBAAiBhB,OAAOG,EAAEK,eACvC,IAEyB,QAAvBJ,EAAKW,gBACPH,qBAAqBR,EAAKS,gBAAgB,WACzC,OAAOd,EAAKkB,mBAAmBjB,OAAOG,EAAEK,eACtC,GAEL,IAEAR,OAAO,QAAQE,GAAG,6BAA8B,mCAAmC,SAACC,EAAGC,GAEvF,GACD,GACD,GAAC,CAAAP,IAAA,iBAAAC,MAGA,SAAeoB,EAAuBH,EAAgBI,GACpD,IAAIC,EAAWpB,OAAOqB,WACpBC,EAAY,IAAIC,SAASL,EAAsBT,KAAK,mBAAmB,IACrEL,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