-
Notifications
You must be signed in to change notification settings - Fork 0
/
braintree.js
13 lines (13 loc) · 20.2 KB
/
braintree.js
1
2
3
4
5
6
7
8
9
10
11
12
13
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.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"EX2r":[function(require,module,exports) {
"use strict";function e(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function r(e,r){for(var i=0;i<r.length;i++){var t=r[i];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function i(e,i,t){return i&&r(e.prototype,i),t&&r(e,t),e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.MethodElement=void 0;var t=jQuery,a=function(){function r(i,a){e(this,r),this.$element=i,this.settings=t.extend(a,{wrapperClasses:["form-control"]}),this.form_id=this.$element.closest("form").attr("id"),this.errorHandler=this.clientsideValidationEnabled?this.clientsideValidationErrorHandler:this.fallbackErrorHandler}return i(r,[{key:"startLoading",value:function(){this.$element.addClass("loading"),t('<div class="loading-wrapper"><div class="throbber"></div></div>').appendTo(this.$element.children(".fieldset-wrapper"))}},{key:"stopLoading",value:function(){this.$element.find(".loading-wrapper").remove(),this.$element.removeClass("loading")}},{key:"setNonce",value:function(e){this.$element.find('[name$="[braintree-payment-nonce]"]').val(e)}},{key:"clientsideValidationErrorHandler",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=Drupal.myClientsideValidation.validators[this.form_id];if(r&&r.attr("name")){var a={};a[r.attr("name")]=e,i.currentElements.push(r),i.showErrors(a)}else{var n=Drupal.settings.clientsideValidation.forms[this.form_id].general,l=t("<".concat(n.errorElement,' class="').concat(n.errorClass,'">')).text(e),o=t("#clientsidevalidation-"+this.form_id+"-errors");if(o.length){var s=o.find("ul");l.wrap("<".concat(n.wrapper,">")).parent().addClass("braintree-error").appendTo(s),s.show(),o.show()}else l.addClass("braintree-error").insertBefore(this.$element.closest(".form-item"))}}},{key:"fallbackErrorHandler",value:function(e){t('<div class="messages error">').text(e).addClass("braintree-error").insertBefore(this.$element.closest("form"))}},{key:"resetValidation",value:function(){if(t(".mo-dialog-wrapper").addClass("visible"),t(".braintree-error").remove(),this.clientsideValidationEnabled()){var e=Drupal.myClientsideValidation.validators[this.form_id];e.prepareForm(),e.hideErrors()}}},{key:"clientsideValidationEnabled",value:function(){return void 0!==Drupal.clientsideValidation&&void 0!==Drupal.myClientsideValidation.validators[this.form_id]&&void 0!==Drupal.settings.clientsideValidation.forms[this.form_id]}}]),r}();exports.MethodElement=a;
},{}],"zeDO":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CreditCardElement=void 0;var e=require("./method-element");function t(e){return(t="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})(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function i(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&a(e,t)}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){var t=u();return function(){var r,n=d(e);if(t){var i=d(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return s(this,r)}}function s(e,r){return!r||"object"!==t(r)&&"function"!=typeof r?c(e):r}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function d(e){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var f=jQuery,p=function(t){o(a,e.MethodElement);var n=l(a);function a(e,t){var i;return r(this,a),(i=n.call(this,e,t)).waitForLibrariesThenInit(),i}return i(a,[{key:"waitForLibrariesThenInit",value:function(){var e=this;"undefined"!=typeof braintree&&void 0!==braintree.client&&void 0!==braintree.hostedFields&&"undefined"!==braintree.threeDSecure?this.initFields():window.setTimeout(function(){e.waitForLibrariesThenInit()},100)}},{key:"getStyles",value:function(){var e,t={},r=f('<div class="form-item"><input type="text" class="default" /><input type="text" class="error" /><select><option>One</option></select></div>').hide().appendTo(this.$element);return e=window.getComputedStyle(r.find("input.default").get(0)),t.input={color:e.getPropertyValue("color"),font:e.getPropertyValue("font"),"line-height":e.getPropertyValue("line-height")},e=window.getComputedStyle(r.find("input.error").get(0)),t["input.invalid"]={color:e.getPropertyValue("color")},e=window.getComputedStyle(r.find("select").get(0)),t.select={font:e.getPropertyValue("font")},r.remove(),t}},{key:"initFields",value:function(){var e=this;this.startLoading(),braintree.client.create({authorization:this.settings.payment_token}).then(function(t){e.client=t,e.$wrappers=e.$element.find(".braintree-hosted-fields-wrapper");var r={};return e.$wrappers.each(function(){var e=f(this),t=e.data("braintreeHostedFieldsField"),n={container:this},i=e.children("input, select");"SELECT"===i.get(0).tagName?(n.select=!0,e.addClass("select-input")):(n.placeholder=this.getAttribute("placeholder"),e.addClass("text-input")),r[t]=n,e.css({height:i.outerHeight(),"box-sizing":"border-box"})}),braintree.hostedFields.create({client:t,styles:e.getStyles(),fields:f.extend(!0,{},e.settings.fields,r)})}).then(function(t){return e.hostedFields=t,e.$wrappers.find("iframe").removeAttr("type"),e.$wrappers.addClass("braintree-hosted-fields-processed"),e.$wrappers.addClass(e.settings.wrapperClasses.join(" ")),braintree.threeDSecure.create({version:2,client:e.client})}).then(function(t){e.client3ds=t,e.stopLoading()})}},{key:"validate",value:function(e){var t=this;this.resetValidation(),this.$wrappers.removeClass("invalid"),this.hostedFields.tokenize().then(function(e){return t.client3ds.verifyCard(f.extend({},t.extraData(),{nonce:e.nonce,bin:e.details.bin,onLookupComplete:function(e,t){t()}}))}).then(function(r){var n=r.threeDSecureInfo;n.liabilityShifted||!n.liabilityShiftPossible&&!t.settings.forceLiabilityShift?(t.setNonce(r.nonce),e.ready()):(t.errorHandler(Drupal.t("Card verification failed. Please choose another form of payment.")),e.error())}).catch(function(r){if("HOSTED_FIELDS_FIELDS_INVALID"===r.code)for(var n in r.details.invalidFields){var i=r.details.invalidFields[n];i.classList.add("invalid");var o=f("label[for='".concat(f("input, select",f(i)).attr("id"),"']"));1===r.details.invalidFieldKeys.length?t.errorHandler(Drupal.t("Invalid @field_name",{"@field_name":o.text()}),f(i)):t.errorHandler(Drupal.t("Invalid @field_name",{"@field_name":o.text()}))}else{var a=r.message;a.length>0?t.errorHandler(a):t.errorHandler(r)}e.error()})}},{key:"extraData",value:function(){var e={};return this.$element.find("[data-braintree-name]").each(function(){var t=f(this).attr("data-braintree-name").split("."),r=f(this).val();a.deepSet(e,t,r)}),e}}],[{key:"deepSet",value:function(e,t,r){var n=t.shift();t.length>0?(void 0===e[n]&&(e[n]={}),a.deepSet(e[n],t,r)):e[n]=r}}]),a}();exports.CreditCardElement=p;
},{"./method-element":"EX2r"}],"IYHS":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ButtonElement=void 0;var e=require("./method-element");function t(e){return(t="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})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function r(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function a(e){var t=l();return function(){var n,o=f(e);if(t){var r=f(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return u(this,n)}}function u(e,n){return!n||"object"!==t(n)&&"function"!=typeof n?s(e):n}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var p=function(t){i(c,e.MethodElement);var o=a(c);function c(e,t){var r;return n(this,c),(r=o.call(this,e,t)).hidePaymethodSelectRadio(),r}return r(c,[{key:"hidePaymethodSelectRadio",value:function(){var e=this.$element.data("pmid"),t=this.$element.closest("form").find('[name*="[paymethod_select]"][value='.concat(e,"]"));if(t.length){var n=t.siblings('label[for="'.concat(t.attr("id"),'"]'));this.$paymethodRadio=t.add(n).hide()}}},{key:"selectRadio",value:function(){this.$paymethodRadio&&this.$paymethodRadio.filter("input").prop("checked",!0).trigger("change")}},{key:"renderButton",value:function(e){if(this.$paymethodRadio){var t=this.$paymethodRadio.filter("label");e.css("height",t.css("height")),e.css("font-size",t.css("font-size")),e.css("line-height",t.css("line-height")),e.css("margin-bottom",t.css("margin-bottom")),this.$paymethodRadio.parent().closest(".paymethod-select-radios").append(e)}else this.$element.append(e)}},{key:"submitForm",value:function(){this.$element.closest("form").find('[type="submit"]:not([formnovalidate])').first().click()}},{key:"validate",value:function(e){this.resetValidation(),this.$element.find('[name$="[braintree-payment-nonce]"]').val().length>0?e.ready():e.error()}}]),c}();exports.ButtonElement=p;
},{"./method-element":"EX2r"}],"cfJ7":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GooglePayElement=void 0;var t=require("./button-element");function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function r(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&a(t,e)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t){var e=l();return function(){var n,o=f(t);if(e){var r=f(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return s(this,n)}}function s(t,n){return!n||"object"!==e(n)&&"function"!=typeof n?c(t):n}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var y=jQuery,p=function(e){i(a,t.ButtonElement);var o=u(a);function a(t,e){var r;return n(this,a),(r=o.call(this,t,e)).waitForLibrariesThenInit(),r}return r(a,[{key:"waitForLibrariesThenInit",value:function(){var t=this;"undefined"!=typeof google&&void 0!==google.payments&&void 0!==google.payments.api&&"undefined"!=typeof braintree&&void 0!==braintree.client&&void 0!==braintree.googlePayment?this.initPayButton():window.setTimeout(function(){t.waitForLibrariesThenInit()},100)}},{key:"initPayButton",value:function(){var t=this;this.paymentsClient=new google.payments.api.PaymentsClient({environment:this.settings.sandbox?"TEST":"PRODUCTION"}),braintree.client.create({authorization:this.settings.payment_token}).then(function(e){return braintree.googlePayment.create({client:e,googlePayVersion:2,googleMerchantId:t.settings.googlePayMerchantId})}).then(function(e){return t.googlePaymentInstance=e,t.paymentsClient.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:e.createPaymentDataRequest().allowedPaymentMethods,existingPaymentMethodRequired:!0})}).then(function(e){if(e.result){var n=t,o=t.paymentsClient.createButton({buttonSizeMode:"fill",buttonType:t.settings.googlePayButtonType,buttonColor:t.settings.googlePayButtonColor,buttonLocale:document.documentElement.lang.substring(0,2),onClick:function(){n.showPaymentForm()}});t.renderButton(y(o))}})}},{key:"showPaymentForm",value:function(){var t=this;this.selectRadio();var e=this.googlePaymentInstance.createPaymentDataRequest({transactionInfo:this.settings.transactionInfo});e.allowedPaymentMethods[0];this.paymentsClient.loadPaymentData(e).then(function(e){return t.googlePaymentInstance.parseResponse(e)}).then(function(e){t.setNonce(e.nonce),t.submitForm()}).catch(function(e){t.resetValidation(),t.errorHandler(e.statusMessage||e.statusCode)})}}]),a}();exports.GooglePayElement=p;
},{"./button-element":"IYHS"}],"Utad":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ApplePayElement=void 0;var e=require("./button-element");function t(e){return(t="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})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function r(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){var t=l();return function(){var n,o=p(e);if(t){var r=p(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return u(this,n)}}function u(e,n){return!n||"object"!==t(n)&&"function"!=typeof n?s(e):n}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var y=jQuery,f=function(t){a(i,e.ButtonElement);var o=c(i);function i(e,t){var r;return n(this,i),(r=o.call(this,e,t)).applePay={},r.checkCompatibility()&&r.waitForLibrariesThenInit(),r}return r(i,[{key:"checkCompatibility",value:function(){return!("undefined"==typeof ApplePaySession||!ApplePaySession.supportsVersion(3)||!ApplePaySession.canMakePayments())||(this.$element.append("<p>".concat(Drupal.t("This browser does not support Apple Pay."),"</p>")),!1)}},{key:"waitForLibrariesThenInit",value:function(){var e=this;"undefined"!=typeof braintree&&void 0!==braintree.client&&void 0!==braintree.applePay?this.initPayButton():window.setTimeout(function(){e.waitForLibrariesThenInit()},100)}},{key:"initPayButton",value:function(){var e=this;braintree.client.create({authorization:this.settings.payment_token}).then(function(e){return braintree.applePay.create({client:e})}).then(function(t){e.applePay.instance=t;var n=e.generateButton();e.renderButton(n),n.on("click",function(){e.selectRadio();var n=t.createPaymentRequest(e.settings.requestData),o=e.applePay.session=new ApplePaySession(3,n);o.onvalidatemerchant=e.validateMerchantHandler.bind(e),o.onpaymentauthorized=e.paymentAuthorizedHandler.bind(e),o.begin()})}).catch(function(t){console.error(t),e.errorHandler(t.message||t)})}},{key:"generateButton",value:function(){return y('\n <button\n type="button"\n class="button braintree apple-pay"\n aria-label="Apple Pay"\n lang='.concat(document.documentElement.lang.substring(0,2),"\n ><span>Apple Pay</span>\n </button>"))}},{key:"validateMerchantHandler",value:function(e){var t=this;this.applePay.instance.performValidation({validationURL:e.validationURL,displayName:this.settings.displayName}).then(function(e){t.applePay.session.completeMerchantValidation(e)}).catch(function(e){console.error(e),t.errorHandler(e.message||e),t.applePay.session.abort()})}},{key:"paymentAuthorizedHandler",value:function(e){var t=this;this.applePay.instance.tokenize({token:e.payment.token}).then(function(e){t.setNonce(e.nonce),t.applePay.session.completePayment(ApplePaySession.STATUS_SUCCESS),t.submitForm()}).catch(function(e){console.error(e),t.errorHandler(e.message||e),t.applePay.session.completePayment(ApplePaySession.STATUS_FAILURE)})}}]),i}();exports.ApplePayElement=f;
},{"./button-element":"IYHS"}],"epB2":[function(require,module,exports) {
"use strict";var e=require("./credit-card-element"),a=require("./google-pay-element"),t=require("./apple-pay-element"),r=jQuery;Drupal.behaviors.braintree_payment={},Drupal.behaviors.braintree_payment.element_map={braintree_payment_credit_card:e.CreditCardElement,braintree_payment_google_pay:a.GooglePayElement,braintree_payment_apple_pay:t.ApplePayElement},Drupal.behaviors.braintree_payment.attach=function(e,a){var t=this;Drupal.payment_handler||(Drupal.payment_handler={}),r('input[name$="braintree-payment-nonce]"]',e).each(function(){if(document.body.contains(this)){var e=r(this).closest(".payment-method-form"),n=e.attr("data-pmid"),p=a.braintree_payment["pmid_"+n];if(p.method in t.element_map){var i=new t.element_map[p.method](e,p);Drupal.payment_handler[n]=function(e,a,t){i.validate(t)}}}})};
},{"./credit-card-element":"zeDO","./google-pay-element":"cfJ7","./apple-pay-element":"Utad"}]},{},["epB2"], null)