@bigcommerce/checkout-sdk 1.614.0 → 1.614.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checkout-button.js +1 -1
- package/dist/checkout-button.umd.js +1 -1
- package/dist/checkout-sdk.js +1 -1
- package/dist/checkout-sdk.umd.js +1 -1
- package/dist/hosted-form.js +1 -1
- package/dist/hosted-form.js.map +1 -1
- package/dist/hosted-form.umd.js +1 -1
- package/dist/hosted-form.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/hosted-form.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{initializeHostedInput:()=>ue,notifyInitializeError:()=>ce});const n=require("tslib"),r=function(e){function t(t){var n,r,i=this.constructor,a=e.call(this,t||"An unexpected error has occurred.")||this;return a.name="StandardError",a.type="standard",n=a,r=i.prototype,Object.setPrototypeOf?Object.setPrototypeOf(n,r):n.__proto__=r,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(a,i):a.stack=new Error(a.message).stack,a}return(0,n.__extends)(t,e),t}(Error),i=function(e){function t(t){var n=e.call(this,t||"Invalid arguments have been provided.")||this;return n.name="InvalidArgumentError",n.type="invalid_argument",n}return(0,n.__extends)(t,e),t}(r);function a(e){if(!/^(https?:)?\/\//.test(e))throw new i("The provided URL must be absolute.");var t=document.createElement("a");t.href=e;var n=t.port&&-1!==e.indexOf(t.hostname+":"+t.port)?t.port:"";return{hash:t.hash,hostname:t.hostname,href:t.href,origin:t.protocol+"//"+t.hostname+(n?":"+n:""),pathname:t.pathname,port:n,protocol:t.protocol,search:t.search}}function o(e){return a(0===e.hostname.indexOf("www")?e.href:e.href.replace(e.hostname,"www."+e.hostname))}const s=function(e,t,r){return t&&r?u(0,t,r):function(e){var t=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,n.__extends)(t,e),t}(e);return Object.getOwnPropertyNames(e.prototype).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e.prototype,n);r&&"constructor"!==n&&Object.defineProperty(t.prototype,n,u(e.prototype,n,r))})),t}(e)};function u(e,t,r){if("function"!=typeof r.value)return r;var i=r.value;return{get:function(){var e=i.bind(this);return Object.defineProperty(this,t,(0,n.__assign)((0,n.__assign)({},r),{value:e})),e},set:function(e){i=e}}}function d(e,t){return e.type===t}const c=function(){function e(e){this._sourceOrigins=[a(e).origin,o(a(e)).origin],this._isListening=!1,this._listeners={}}return e.prototype.listen=function(){this._isListening||(this._isListening=!0,window.addEventListener("message",this._handleMessage))},e.prototype.stopListen=function(){this._isListening&&(this._isListening=!1,window.removeEventListener("message",this._handleMessage))},e.prototype.addListener=function(e,t){var n=this._listeners[e];n||(this._listeners[e]=n=[]),-1===n.indexOf(t)&&n.push(t)},e.prototype.removeListener=function(e,t){var n=this._listeners[e];if(n){var r=n.indexOf(t);r>=0&&n.splice(r,1)}},e.prototype.trigger=function(e,t){var n=this._listeners[e.type];n&&n.forEach((function(n){return t?n(e,t):n(e)}))},e.prototype._handleMessage=function(e){if(-1!==this._sourceOrigins.indexOf(e.origin)&&d(e.data,e.data.type)){var t=e.data,r=t.context,i=(0,n.__rest)(t,["context"]);this.trigger(i,r)}},(0,n.__decorate)([s],e.prototype,"_handleMessage",null),e}(),p=function(){function e(){}return e.prototype.setNonce=function(e){this._nonce=e},e.prototype.getNonce=function(){return this._nonce},e}();var l;function m(){return l=l||new p}const h=require("@bigcommerce/bigpay-client"),g=require("@bigcommerce/request-sender"),_=require("rxjs"),f=require("rxjs/operators"),y=function(){function e(e,t,n){this._targetWindow=t,this._context=n,this._targetOrigin="*"===e?"*":a(e).origin}return e.prototype.post=function(e,t){var r=this,i=this._targetWindow;if(window!==i){if(!i)throw new Error("Unable to post message because target window is not set.");var a=t&&(0,_.fromEvent)(window,"message").pipe((0,f.filter)((function(e){return e.origin===r._targetOrigin&&d(e.data,e.data.type)&&-1!==[t.successType,t.errorType].indexOf(e.data.type)})),(0,f.map)((function(e){if(t.errorType===e.data.type)throw e.data;return e.data})),(0,f.take)(1)).toPromise();return i.postMessage((0,n.__assign)((0,n.__assign)({},e),{context:this._context}),this._targetOrigin),a}},e.prototype.setTarget=function(e){this._targetWindow=e},e.prototype.setContext=function(e){this._context=e},e}(),v=function(){function e(e){this._client=e}return e.prototype.submitPayment=function(e){var t=this;return new Promise((function(n,r){t._client.submitPayment(e,(function(e,i){e?r(t._transformResponse(e)):n(t._transformResponse(i))}))}))},e.prototype.initializeOffsitePayment=function(e,t){var n=this;return new Promise((function(){n._client.initializeOffsitePayment(e,null,t)}))},e.prototype._transformResponse=function(e){return{headers:e.headers,body:e.data,status:e.status,statusText:e.statusText}},e}(),C=require("lodash");function b(e,t){var n;return function(e){return void 0!==e.id}(e)?n=e.id:t&&t.length&&(n=t[0].id),{id:n,firstName:e.firstName,lastName:e.lastName,company:e.company,addressLine1:e.address1,addressLine2:e.address2,city:e.city,province:e.stateOrProvince,provinceCode:e.stateOrProvinceCode,postCode:e.postalCode,country:e.country,countryCode:e.countryCode,phone:e.phone,customFields:e.customFields}}const E=function(){function e(e){this._decimalPlaces=e}return e.prototype.toInteger=function(e){return Math.round(e*Math.pow(10,this._decimalPlaces))},e}();var I,A=["per_item_discount","percentage_discount","per_total_discount","shipping_discount","free_shipping"];function P(e){return{code:e.code,discount:e.displayName,discountType:A.indexOf(e.couponType)}}function T(e){return{code:e.code,discountedAmount:e.used,remainingBalance:e.remaining,giftCertificate:{balance:e.balance,code:e.code,purchaseDate:e.purchaseDate}}}function w(e,t,r){return void 0===r&&(r="id"),Object.keys(e).reduce((function(i,a){return(0,n.__spreadArrays)(i,e[a].map((function(e){return"giftCertificates"===a?function(e,t){var n=new E(t);return{id:e.id,imageUrl:"",name:e.name,amount:e.amount,amountAfterDiscount:e.amount,discount:0,integerAmount:n.toInteger(e.amount),integerAmountAfterDiscount:n.toInteger(e.amount),integerUnitPrice:n.toInteger(e.amount),integerUnitPriceAfterDiscount:n.toInteger(e.amount),integerDiscount:0,quantity:1,sender:e.sender,recipient:e.recipient,type:"ItemGiftCertificateEntity",attributes:[],variantId:null}}(e,t):function(e,t,n,r){void 0===r&&(r="id");var i=new E(n);return{id:e[r],imageUrl:e.imageUrl,amount:e.extendedListPrice,amountAfterDiscount:e.extendedSalePrice,discount:e.discountAmount,integerAmount:i.toInteger(e.extendedListPrice),integerAmountAfterDiscount:i.toInteger(e.extendedSalePrice),integerDiscount:i.toInteger(e.discountAmount),integerUnitPrice:i.toInteger(e.listPrice),integerUnitPriceAfterDiscount:i.toInteger(e.salePrice),downloadsPageUrl:e.downloadPageUrl,name:e.name,quantity:e.quantity,brand:e.brand,sku:e.sku,categoryNames:e.categoryNames,variantId:e.variantId,productId:e.productId,attributes:(e.options||[]).map((function(e){return{name:e.name,value:e.value}})),addedByPromotion:e.addedByPromotion,type:t}}(e,function(e){switch(e){case"physicalItems":return"ItemPhysicalEntity";case"digitalItems":return"ItemDigitalEntity";case"giftCertificates":return"ItemGiftCertificateEntity";default:return""}}(a),t,r)})))}),[])}function S(e){var t,n,r=e.cart.currency.decimalPlaces,i=new E(r);return{id:e.cart.id,items:w(e.cart.lineItems,r),currency:e.cart.currency.code,coupon:{discountedAmount:(0,C.reduce)(e.cart.coupons,(function(e,t){return e+t.discountedAmount}),0),coupons:e.cart.coupons.map(P)},discount:{amount:e.cart.discountAmount,integerAmount:i.toInteger(e.cart.discountAmount)},discountNotifications:(t=e.promotions,n=[],(t||[]).forEach((function(e){(e.banners||[]).forEach((function(e){n.push({placeholders:[],discountType:null,message:"",messageHtml:e.text})}))})),n),giftCertificate:{totalDiscountedAmount:(0,C.reduce)(e.giftCertificates,(function(e,t){return e+t.used}),0),appliedGiftCertificates:(0,C.keyBy)(e.giftCertificates.map(T),"code")},shipping:{amount:e.shippingCostTotal,integerAmount:i.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:i.toInteger(e.shippingCostBeforeDiscount),required:(0,C.some)(e.cart.lineItems.physicalItems,(function(e){return e.isShippingRequired}))},subtotal:{amount:e.subtotal,integerAmount:i.toInteger(e.subtotal)},storeCredit:{amount:e.customer?e.customer.storeCredit:0},taxSubtotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:i.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.grandTotal,integerAmount:i.toInteger(e.grandTotal)}}}!function(e){e.APPLEPAY="applepay",e.AMAZON_PAY_V2="amazonpay",e.BRAINTREE_PAYPAL="braintreepaypal",e.BRAINTREE_VENMO="braintreevenmo",e.BRAINTREE_PAYPAL_CREDIT="braintreepaypalcredit",e.GOOGLEPAY_ADYENV2="googlepayadyenv2",e.GOOGLEPAY_ADYENV3="googlepayadyenv3",e.GOOGLEPAY_AUTHORIZENET="googlepayauthorizenet",e.GOOGLEPAY_BNZ="googlepaybnz",e.GOOGLEPAY_BRAINTREE="googlepaybraintree",e.GOOGLEPAY_CHECKOUTCOM="googlepaycheckoutcom",e.GOOGLEPAY_CYBERSOURCEV2="googlepaycybersourcev2",e.GOOGLEPAY_ORBITAL="googlepayorbital",e.GOOGLEPAY_STRIPE="googlepaystripe",e.GOOGLEPAY_STRIPEUPE="googlepaystripeupe",e.GOOGLEPAY_WORLDPAYACCESS="googlepayworldpayaccess",e.MASTERPASS="masterpass",e.PAYPALEXPRESS="paypalexpress"}(I||(I={}));const O=I;var N;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentProviderCustomer=13]="MissingPaymentProviderCustomer",e[e.MissingPaymentRedirectUrl=14]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=15]="MissingPaymentStatus",e[e.MissingPaymentToken=16]="MissingPaymentToken",e[e.MissingShippingAddress=17]="MissingShippingAddress"}(N||(N={}));const M=function(e){function t(t){var n=e.call(this,function(e){switch(e){case N.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case N.MissingCart:return"Unable to proceed because cart data is unavailable.";case N.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case N.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case N.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case N.MissingCheckoutConfig:case N.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case N.MissingOrder:return"Unable to proceed because order data is unavailable.";case N.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case N.MissingPayment:return"Unable to proceed because payment data is unavailable.";case N.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case N.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case N.MissingPaymentProviderCustomer:return"Unable to proceed because payment provider customer is unavailable.";case N.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(t))||this;return n.subtype=t,n.name="MissingDataError",n.type="missing_data",n}return(0,n.__extends)(t,e),t}(r);function D(e,t){var n=e.firstName||t.firstName||"",r=e.lastName||t.lastName||"";return{addresses:(e.addresses||[]).map((function(e){return b(e)})),customerId:e.id,isGuest:e.isGuest,storeCredit:e.storeCredit,email:e.email||t.email||"",firstName:n,lastName:r,name:e.fullName||[n,r].join(" "),customerGroupName:e.customerGroup&&e.customerGroup.name}}const x=function(){function e(){}return e.prototype.format=function(e){var t=e.split(new RegExp("\\s*/\\s*")),n=t[0],r=void 0===n?"":n,i=t[1],a=void 0===i?"":i,o=r.slice(0,2),s=4===a.length?a.slice(-2):a?a.slice(0,2):r.slice(2);return e.length<2?r:e.length>3&&!s?o:o+" / "+s},e.prototype.toObject=function(e){var t=e.split(new RegExp("\\s*/\\s*")),n=t[0],r=void 0===n?"":n,i=t[1],a=void 0===i?"":i;return/^\d+$/.test(r)&&/^\d+$/.test(a)?{month:1===r.length?"0"+r:r.slice(0,2),year:2===a.length?"20"+a:a.slice(0,4)}:{month:"",year:""}},e}(),V=require("card-validator"),L=function(){function e(){}return e.prototype.format=function(e){var t=(0,V.number)(e).card;if(!t)return e;var n=(0,C.max)((0,V.creditCardType)(e).map((function(e){return(0,C.max)(e.lengths)}))),r=this.unformat(e).slice(0,n);return t.gaps.filter((function(e){return r.length>e})).reduce((function(e,t,n){return[e.slice(0,t+n),e.slice(t+n)].join(" ")}),r)},e.prototype.unformat=function(e){return(0,V.number)(e).card?e.replace(new RegExp(" ","g"),""):e},e}();function U(e,t){void 0===t&&(t={});var n,r,i=e.currency.decimalPlaces,a=new E(i);return{id:e.orderId,items:w(e.lineItems,e.currency.decimalPlaces,"productId"),orderId:e.orderId,currency:e.currency.code,customerCanBeCreated:e.customerCanBeCreated,payment:R(e.payments,t.payment),subtotal:{amount:e.baseAmount,integerAmount:a.toInteger(e.baseAmount)},coupon:{discountedAmount:(0,C.reduce)(e.coupons,(function(e,t){return e+t.discountedAmount}),0),coupons:e.coupons.map(P)},discount:{amount:e.discountAmount,integerAmount:a.toInteger(e.discountAmount)},token:t.orderToken,callbackUrl:t.callbackUrl,discountNotifications:[],giftCertificate:(n=e.payments,r=(0,C.filter)(n,{providerId:"giftcertificate"}),{totalDiscountedAmount:(0,C.reduce)(r,(function(e,t){return t.amount+e}),0),appliedGiftCertificates:(0,C.keyBy)(r.map((function(e){return{code:e.detail.code,discountedAmount:e.amount,remainingBalance:e.detail.remaining,giftCertificate:{balance:e.amount+e.detail.remaining,code:e.detail.code,purchaseDate:""}}})),"code")}),socialData:F(e),status:e.status,hasDigitalItems:e.hasDigitalItems,isDownloadable:e.isDownloadable,isComplete:e.isComplete,shipping:{amount:e.shippingCostTotal,integerAmount:a.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:a.toInteger(e.shippingCostBeforeDiscount)},storeCredit:{amount:k(e.payments)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:a.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:a.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.orderAmount,integerAmount:e.orderAmountAsInteger}}}function k(e){var t=(0,C.find)(e,{providerId:"storecredit"});return t?t.amount:0}function R(e,t){void 0===t&&(t={});var n,r=(0,C.find)(e,q);return r?{id:r.providerId,status:(n=r.detail.step,"PAYMENT_STATUS_"+n),helpText:r.detail.instructions,returnUrl:t.returnUrl}:{}}function q(e){return"giftcertificate"!==e.providerId&&"storecredit"!==e.providerId}function F(e){var t={};return(0,n.__spreadArrays)(e.lineItems.physicalItems,e.lineItems.digitalItems).forEach((function(e){var n;t[e.id]=(n=e,["fb","tw","gp"].reduce((function(e,t){var r=n.socialMedia&&(0,C.find)(n.socialMedia,(function(e){return e.code===t}));return r?(e[t]={name:n.name,description:n.name,image:n.imageUrl,url:r.link,shareText:r.text,sharingLink:r.link,channelName:r.channel,channelCode:r.code},e):e}),{}))})),t}function H(e,t){return{description:e.description,module:e.type,price:e.cost,id:e.id,selected:t,isRecommended:e.isRecommended,imageUrl:e.imageUrl,transitTime:e.transitTime}}const B=function(){function e(){this._cardExpiryFormatter=new x,this._cardNumberFormatter=new L}return e.prototype.transform=function(e,t){var r,i=t.billingAddress.getBillingAddress(),a=t.checkout.getCheckout(),o=t.customer.getCustomer(),s=t.order.getOrder(),u=t.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),d=this._mapShippingAddress(t,u),c=t.consignments.getConsignments(),p=t.consignments.getShippingOption(),l=t.config.getStoreConfig(),m=t.config.getContextConfig(),h=t.instruments.getInstrumentsMeta(),g=t.paymentMethods.getPaymentMethodsMeta(),_=t.order.getOrderMeta(),f=o&&i&&D(o,i),y=h&&e.paymentData&&(r=e.paymentData,Boolean(r.instrumentId)||function(e){var t=e.formattedPayload;return!!t&&("string"==typeof t.bigpay_token||Boolean(t.bigpay_token&&t.bigpay_token.token))}(e.paymentData))?t.payment.getPaymentToken()+", "+h.vaultAccessToken:t.payment.getPaymentToken();if(!y)throw new M(N.MissingPaymentToken);return{additionalAction:e.additionalAction,authToken:y,customer:f,billingAddress:i&&b(i),shippingAddress:d&&b(d,c),shippingOption:p&&H(p,!0),cart:a&&S(a),order:s&&U(s,_),orderMeta:_,payment:e.paymentData,paymentMethod:u&&this._transformPaymentMethod(u),quoteMeta:{request:(0,n.__assign)((0,n.__assign)({},g),{geoCountryCode:m&&m.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:(0,C.pick)(l&&l.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}},e.prototype.transformWithHostedFormData=function(e,t,r){var i=t.additionalAction,a=t.authToken,o=t.checkout,s=t.config,u=t.order,d=t.orderMeta,c=t.payment,p=void 0===c?{}:c,l=t.paymentMethod,m=t.paymentMethodMeta,h=o&&o.consignments[0],g=h&&h.shippingAddress,_=h&&h.selectedShippingOption;return{additionalAction:i,authToken:a,paymentMethod:l&&this._transformPaymentMethod(l),customer:u&&u.billingAddress&&o&&D(o.customer,u.billingAddress),billingAddress:u&&u.billingAddress&&b(u.billingAddress),shippingAddress:g&&o&&b(g,o.consignments),shippingOption:_&&H(_,!0),cart:o&&S(o),order:u&&U(u,d),orderMeta:d,payment:this._transformHostedInputValues(e,p,r),quoteMeta:{request:(0,n.__assign)((0,n.__assign)({},m),{geoCountryCode:s&&s.context.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:s&&(0,C.pick)(s.storeConfig.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}},e.prototype._transformPaymentMethod=function(e){return"multi-option"!==e.method||e.gateway?e.initializationData&&e.initializationData.gateway?(0,n.__assign)((0,n.__assign)({},e),{id:e.initializationData.gateway}):e.id===O.BRAINTREE_VENMO?(0,n.__assign)((0,n.__assign)({},e),{id:O.BRAINTREE_PAYPAL}):e:(0,n.__assign)((0,n.__assign)({},e),{gateway:e.id})},e.prototype._transformHostedInputValues=function(e,t,r){return"instrumentId"in t?(0,n.__assign)((0,n.__assign)({},t),{ccCvv:e.cardCodeVerification,ccNumber:e.cardNumberVerification&&this._cardNumberFormatter.unformat(e.cardNumberVerification),hostedFormNonce:r}):(0,n.__assign)((0,n.__assign)({},t),{ccCvv:e.cardCode,ccExpiry:this._cardExpiryFormatter.toObject(e.cardExpiry||""),ccName:e.cardName||"",ccNumber:this._cardNumberFormatter.unformat(e.cardNumber||""),hostedFormNonce:r})},e.prototype._mapShippingAddress=function(e,t){var n,r,i,a;if(t){var o=null===(r=null===(n=t.initializationData)||void 0===n?void 0:n.bopis)||void 0===r?void 0:r.enabled,s=null===(a=null===(i=t.initializationData)||void 0===i?void 0:i.bopis)||void 0===a?void 0:a.requiredAddress,u=e.consignments.getConsignments(),d=null==u?void 0:u.every((function(e){return e.selectedPickupOption}));if(o&&d&&"none"===s)return}return e.shippingAddress.getShippingAddress()},e}(),G=function(){function e(e){this._requestSender=e}return e.prototype.submitPaymentInstrument=function(e,t){return(0,n.__awaiter)(this,void 0,void 0,(function(){var r,i,a,o,s,u,d,c,p,l,m;return(0,n.__generator)(this,(function(h){switch(h.label){case 0:return r=e.providerId,i=e.currencyCode,a=e.paymentsUrl,o=e.shopperId,s=e.storeHash,u=e.vaultToken,d=t.billingAddress,c=t.instrument,p=t.defaultInstrument,l=a+"/stores/"+s+"/customers/"+o+"/stored_instruments",m={headers:{Authorization:u,Accept:"application/vnd.bc.v1+json","Content-Type":"application/vnd.bc.v1+json"},body:JSON.stringify({instrument:{type:c.type,cardholder_name:c.cardholderName,number:c.number,expiry_month:c.expiryMonth,expiry_year:c.expiryYear,verification_value:c.verificationValue},billing_address:(0,n.__assign)((0,n.__assign)((0,n.__assign)((0,n.__assign)((0,n.__assign)((0,n.__assign)({email:d.email,address1:d.address1},d.address2&&{address2:d.address2}),{city:d.city,postal_code:d.postalCode,country_code:d.countryCode}),d.company&&{company:d.company}),{first_name:d.firstName,last_name:d.lastName}),d.phone&&{phone:d.phone}),d.stateOrProvinceCode&&{state_or_province_code:d.stateOrProvinceCode}),provider_id:r,default_instrument:p,currency_code:i})},[4,this._requestSender.post(l,m)];case 1:return h.sent(),[2]}}))}))},e}();var j;!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(j||(j={}));const Y=j;function z(e){switch(e){case Y.CardCode:return"cc-csc";case Y.CardExpiry:return"cc-exp";case Y.CardName:return"cc-name";case Y.CardNumber:return"cc-number";default:return""}}const W=function(){function e(e,t,n){var r=this;this._form=e,this._fieldTypes=t,this._inputAggregator=n,this._handleChange=function(e){var t=e.target;if(!t)throw new Error("Unable to get a reference to the target of the change event.");var n=r._inputAggregator.getInputs().find((function(e){return r._getAutocompleteElementId(e.getType())===t.id}));n&&n.setValue(t.value)},this._inputs=this._fieldTypes.map((function(e){return r._createInput(e)}))}return e.prototype.attach=function(){var e=this;this._inputs.forEach((function(t){return e._form.appendChild(t)}))},e.prototype.detach=function(){this._inputs.forEach((function(e){e.parentElement&&e.parentElement.removeChild(e)}))},e.prototype._createInput=function(e){var t=document.createElement("input");return t.autocomplete=z(e),t.id=this._getAutocompleteElementId(e),t.tabIndex=-1,t.style.position="absolute",t.style.opacity="0",t.style.zIndex="-1",t.addEventListener("change",this._handleChange),t},e.prototype._getAutocompleteElementId=function(e){return"autocomplete-"+(0,C.kebabCase)(e)},e}();var Q,Z;!function(e){e.AttachRequested="HOSTED_FIELD:ATTACH_REQUESTED",e.SubmitRequested="HOSTED_FIELD:SUBMITTED_REQUESTED",e.ValidateRequested="HOSTED_FIELD:VALIDATE_REQUESTED",e.StoredCardRequested="HOSTED_FIELD:STORED_CARD_REQUESTED"}(Q||(Q={})),function(e){e.AttachSucceeded="HOSTED_INPUT:ATTACH_SUCCEEDED",e.AttachFailed="HOSTED_INPUT:ATTACH_FAILED",e.BinChanged="HOSTED_INPUT:BIN_CHANGED",e.Blurred="HOSTED_INPUT:BLURRED",e.Changed="HOSTED_INPUT:CHANGED",e.CardTypeChanged="HOSTED_INPUT:CARD_TYPE_CHANGED",e.Entered="HOSTED_INPUT:ENTERED",e.Focused="HOSTED_INPUT:FOCUSED",e.SubmitSucceeded="HOSTED_INPUT:SUBMIT_SUCCEEDED",e.SubmitFailed="HOSTED_INPUT:SUBMIT_FAILED",e.Validated="HOSTED_INPUT:VALIDATED",e.StoredCardSucceeded="HOSTED_INPUT:STORED_CARD_SUCCEEDED",e.StoredCardFailed="HOSTED_INPUT:STORED_CARD_FAILED"}(Z||(Z={}));const $=function(){function e(e,t,n,r,i,a,o,s,u,d,c,p,l){var m=this;this._type=e,this._form=t,this._placeholder=n,this._accessibilityLabel=r,this._autocomplete=i,this._styles=a,this._fontUrls=o,this._eventListener=s,this._eventPoster=u,this._inputAggregator=d,this._inputValidator=c,this._paymentHandler=p,this._storedCardHandler=l,this._isTouched=!1,this._handleInput=function(e){var t=e.target;m._processChange(t.value)},this._handleBlur=function(){m._applyStyles(m._styles.default),m._validateForm(),m._eventPoster.post({type:Z.Blurred,payload:{fieldType:m._type}})},this._handleFocus=function(){m._applyStyles(m._styles.focus),m._eventPoster.post({type:Z.Focused,payload:{fieldType:m._type}})},this._handleValidate=function(){m._validateForm()},this._handleSubmit=function(e){e.preventDefault(),m._eventPoster.post({type:Z.Entered,payload:{fieldType:m._type}})},this._forceFocusToInput=function(){document.activeElement===document.body&&(navigator.userAgent.toLowerCase().indexOf("safari")>-1?""===m._input.value&&(m._input.setAttribute("value"," "),m._input.setSelectionRange(0,1),m._input.setAttribute("value","")):m._input.focus())},this._input=document.createElement("input"),this._input.addEventListener("input",this._handleInput),this._input.addEventListener("blur",this._handleBlur),this._input.addEventListener("focus",this._handleFocus),this._eventListener.addListener(Q.ValidateRequested,this._handleValidate),this._eventListener.addListener(Q.SubmitRequested,this._paymentHandler.handle),this._eventListener.addListener(Q.StoredCardRequested,this._storedCardHandler.handle),this._configureInput()}return e.prototype.getType=function(){return this._type},e.prototype.getValue=function(){return this._input.value},e.prototype.setValue=function(e){this._processChange(e)},e.prototype.isTouched=function(){return this._isTouched},e.prototype.attach=function(){this._form.appendChild(this._input),this._form.addEventListener("submit",this._handleSubmit),this._loadFonts(),this._eventPoster.setTarget(window.parent),this._eventListener.listen(),window.addEventListener("focus",this._forceFocusToInput),window.hostedInput=this,this._eventPoster.post({type:Z.AttachSucceeded})},e.prototype.detach=function(){this._input.parentElement&&this._input.parentElement.removeChild(this._input),this._form.removeEventListener("submit",this._handleSubmit),this._unloadFonts(),window.removeEventListener("focus",this._forceFocusToInput),this._eventListener.stopListen()},e.prototype._formatValue=function(e){this._input.value=e},e.prototype._notifyChange=function(e){this._eventPoster.post({type:Z.Changed,payload:{fieldType:this._type}})},e.prototype._configureInput=function(){switch(this._input.style.backgroundColor="transparent",this._input.style.border="0",this._input.style.display="block",this._input.style.height="100%",this._input.style.margin="0",this._input.style.outline="none",this._input.style.padding="0",this._input.style.width="100%",this._input.id=(0,C.kebabCase)(this._type),this._input.placeholder=this._placeholder,this._input.autocomplete=this._autocomplete,this._input.setAttribute("aria-label",this._accessibilityLabel),this._applyStyles(this._styles.default),this._input.id){case"card-code":case"card-expiry":case"card-number":this._input.type="text",this._input.inputMode="numeric",this._input.pattern="[0-9]*";break;case"card-name":this._input.type="text",this._input.inputMode="text"}},e.prototype._applyStyles=function(e){var t=this;void 0===e&&(e={});var n={color:e.color,fontFamily:e.fontFamily,fontSize:e.fontSize,fontWeight:e.fontWeight};Object.keys(n).forEach((function(e){n[e]&&(t._input.style[e]=n[e]||"")}))},e.prototype._loadFonts=function(){this._fontLinks||(this._fontLinks=this._fontUrls.filter((function(e){return"fonts.googleapis.com"===a(e).hostname})).filter((function(e){return!document.querySelector("link[href='"+e+"'][rel='stylesheet']")})).map((function(e){var t=document.createElement("link");return t.rel="stylesheet",t.href=e,document.head.appendChild(t),t})))},e.prototype._unloadFonts=function(){this._fontLinks&&(this._fontLinks.forEach((function(e){e.parentElement&&e.parentElement.removeChild(e)})),this._fontLinks=void 0)},e.prototype._validateForm=function(){return(0,n.__awaiter)(this,void 0,void 0,(function(){var e,t;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return e=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(e)];case 1:return(t=n.sent()).isValid?this._applyStyles(this._styles.default):this._applyStyles(this._styles.error),this._eventPoster.post({type:Z.Validated,payload:t}),[2]}}))}))},e.prototype._processChange=function(e){e!==this._previousValue&&(this._isTouched=!0,this._formatValue(e),this._validateForm(),this._notifyChange(e),this._previousValue=e)},e}(),J=function(e){function t(t,n,r,i,a,o,s,u,d,c,p,l,m){var h=e.call(this,Y.CardExpiry,t,n,r,i,a,o,s,u,d,c,p,l)||this;return h._formatter=m,h}return(0,n.__extends)(t,e),t.prototype._formatValue=function(e){this._input.value=this._formatter.format(e)},t}($),K=function(e){function t(t,n,r,i,a,o,s,u,d,c,p,l,m,h,g){var _=e.call(this,t,n,r,i,a,o,s,u,d,c,p,l,m)||this;return _._autocompleteFieldset=h,_._formatter=g,_}return(0,n.__extends)(t,e),t.prototype.attach=function(){e.prototype.attach.call(this),this._autocompleteFieldset.attach()},t.prototype._notifyChange=function(e){var t=(0,V.number)(e).card,n=this._previousValue&&(0,V.number)(this._previousValue).card;(0,C.get)(n,"type")!==(0,C.get)(t,"type")&&this._eventPoster.post({type:Z.CardTypeChanged,payload:{cardType:t?t.type:void 0}});var r=this._formatter.unformat(e),i=this._previousValue?this._formatter.unformat(this._previousValue):"",a=r.length>=6&&(0,V.number)(r).isPotentiallyValid?r.substr(0,6):"";a!==(i.length>=6?i.substr(0,6):"")&&this._eventPoster.post({type:Z.BinChanged,payload:{bin:a}})},t.prototype._formatValue=function(e){var t=this._input.selectionEnd,n=this._formatter.format(e);t===e.length&&e.length<n.length?this._input.setSelectionRange(n.length,n.length):this._input.setSelectionRange(t||0,t||0),this._input.value=n},t}($),X=function(){function e(e){this._parentWindow=e}return e.prototype.getInputs=function(e){return Array.prototype.slice.call(this._parentWindow.frames).reduce((function(t,r){try{var i=r.hostedInput;return!i||e&&!e(i)?t:(0,n.__spreadArrays)(t,[i])}catch(e){if(e instanceof DOMException)return t;if(e instanceof Error&&"Permission denied"===e.message)return t;throw e}}),[])},e.prototype.getInputValues=function(e){return this.getInputs(e).reduce((function(e,t){var r;return(0,n.__assign)((0,n.__assign)({},e),((r={})[t.getType()]=t.getValue(),r))}),{})},e}(),ee=function(e){function t(t){var r=e.call(this,(0,n.__spreadArrays)(["Unable to proceed due to invalid user input values"],(0,C.flatMap)((0,C.values)(t),(function(e){return(0,C.map)(e,(function(e){return e.message}))}))).join(". "))||this;return r.errors=t,r.name="InvalidHostedFormValueError",r.type="invalid_hosted_form_value",r}return(0,n.__extends)(t,e),t}(r),te=function(){function e(e,t,r,i,a,o){var s=this;this._inputAggregator=e,this._inputValidator=t,this._inputStorage=r,this._eventPoster=i,this._paymentRequestSender=a,this._paymentRequestTransformer=o,this.handle=function(e){var t=e.payload.data;return(0,n.__awaiter)(s,void 0,void 0,(function(){var e,r,i,a,o;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return e=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(e)];case 1:if(r=n.sent(),this._eventPoster.post({type:Z.Validated,payload:r}),!r.isValid)return i=new ee(r.errors),[2,this._eventPoster.post({type:Z.SubmitFailed,payload:{error:{code:(0,C.snakeCase)(i.name),message:i.message}}})];n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transformWithHostedFormData(e,t,this._inputStorage.getNonce()||""))];case 3:return a=n.sent(),this._eventPoster.post({type:Z.SubmitSucceeded,payload:{response:a}}),[3,5];case 4:return o=n.sent(),this._eventPoster.post({type:Z.SubmitFailed,payload:this._isPaymentErrorResponse(o)?{error:o.body.errors[0],response:o}:{error:{code:(0,C.snakeCase)(o.name),message:o.message}}}),[3,5];case 5:return[2]}}))}))}}return e.prototype._isPaymentErrorResponse=function(e){var t=(e||{}).body,n=(void 0===t?{}:t).errors,r=void 0===n?[]:n;return"string"==typeof(r[0]&&r[0].code)&&"string"==typeof(r[0]&&r[0].message)},e}(),ne=function(e,t,r,i){var a=this;this._inputAggregator=e,this._inputValidator=t,this._eventPoster=r,this._storedCardRequestSender=i,this.handle=function(e){return(0,n.__awaiter)(a,void 0,void 0,(function(){var t,r,i,a,o,s,u,d,c,p,l;return(0,n.__generator)(this,(function(m){switch(m.label){case 0:return t=e.payload,r=t.data,i=t.fields,a=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(a)];case 1:if(o=m.sent(),this._eventPoster.post({type:Z.Validated,payload:o}),!o.isValid)return[2,this._eventPoster.post({type:Z.StoredCardFailed})];s=i.defaultInstrument,u=(0,n.__rest)(i,["defaultInstrument"]),d=a.cardExpiry?a.cardExpiry.split("/"):[],c=d[0],p=d[1],m.label=2;case 2:return m.trys.push([2,4,,5]),[4,this._storedCardRequestSender.submitPaymentInstrument(r,{billingAddress:u,instrument:{type:"card",cardholderName:a.cardName||"",number:a.cardNumber?a.cardNumber.replace(/ /g,""):"",expiryMonth:Number(c.trim()),expiryYear:Number("20"+p.trim()),verificationValue:null!==(l=a.cardCode)&&void 0!==l?l:""},defaultInstrument:s})];case 3:return m.sent(),this._eventPoster.post({type:Z.StoredCardSucceeded}),[3,5];case 4:return m.sent(),this._eventPoster.post({type:Z.StoredCardFailed}),[3,5];case 5:return[2]}}))}))}},re=require("yup"),ie=function(){function e(e){this._cardInstrument=e,this._completeSchema={cardCode:this._getCardCodeSchema(),cardCodeVerification:this._getCardCodeVerificationSchema(),cardExpiry:this._getCardExpirySchema(),cardName:this._getCardNameSchema(),cardNumber:this._getCardNumberSchema(),cardNumberVerification:this._getCardNumberVerificationSchema()},this._configureCardValidator()}return e.prototype.validate=function(e){return(0,n.__awaiter)(this,void 0,void 0,(function(){var t,r,i,a;return(0,n.__generator)(this,(function(o){switch(o.label){case 0:for(i in t={},r={errors:{},isValid:!0},e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=this._completeSchema[i],r.errors[i]=[]);o.label=1;case 1:return o.trys.push([1,3,,4]),[4,(0,re.object)(t).validate(e,{abortEarly:!1})];case 2:return o.sent(),[2,r];case 3:if("ValidationError"!==(a=o.sent()).name)throw a;return[2,{errors:Object.keys(r.errors).reduce((function(e,t){var r;return(0,n.__assign)((0,n.__assign)({},e),((r={})[t]=a.inner.filter((function(e){return e.path===t})).map((function(e){return{fieldType:e.path,message:e.errors.join(" "),type:e.type}})),r))}),{}),isValid:!1}];case 4:return[2]}}))}))},e.prototype._configureCardValidator=function(){var e=V.creditCardType.getTypeInfo("discover"),t=V.creditCardType.getTypeInfo("visa");V.creditCardType.updateCard("visa",{lengths:(0,n.__spreadArrays)([13],t.lengths||[])}),V.creditCardType.updateCard("discover",{patterns:(0,n.__spreadArrays)(e.patterns||[],[[810,817]])}),V.creditCardType.addCard({niceType:"Mada",type:"mada",patterns:[400861,401757,407197,407395,409201,410685,412565,417633,419593,422817,422818,422819,428331,428671,428672,428673,431361,432328,434107,439954,440533,440647,440795,445564,446393,446404,446672,455036,455708,457865,458456,462220,468540,468541,468542,468543,483010,483011,483012,484783,486094,486095,486096,489317,489318,489319,493428,504300,506968,508160,513213,520058,521076,524130,524514,529415,529741,530060,530906,531095,531196,532013,535825,535989,536023,537767,539931,543085,543357,549760,554180,557606,558848,585265,588845,588846,588847,588848,588849,588850,588851,588982,588983,589005,589206,604906,605141,636120,968201,968202,968203,968204,968205,968206,968207,968208,968209,968210,968211],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}})},e.prototype._getCardCodeSchema=function(){return(0,re.string)().required("CVV is required").test({message:"CVV must be valid",name:"invalid_card_code",test:function(e){var t=(0,V.number)(this.parent.cardNumber||"").card;return(0,V.cvv)(e,t&&t.code?t.code.size:void 0).isValid}})},e.prototype._getCardCodeVerificationSchema=function(){var e=this;return(0,re.string)().required("CVV is required").test({message:"CVV must be valid",name:"invalid_card_code",test:function(t){void 0===t&&(t="");var n=e._cardInstrument&&e._mapFromInstrumentCardType(e._cardInstrument.brand),r=n&&V.creditCardType.getTypeInfo(n);return(0,V.cvv)(t,r&&r.code?r.code.size:void 0).isValid}})},e.prototype._getCardExpirySchema=function(){return(0,re.string)().required("Expiration date is required").test({message:"Expiration date must be a valid future date in MM / YY format",name:"invalid_card_expiry",test:function(e){return(0,V.expirationDate)(e).isValid}})},e.prototype._getCardNameSchema=function(){return(0,re.string)().max(200).required("Full name is required")},e.prototype._getCardNumberSchema=function(){return(0,re.string)().required("Credit card number is required").test({message:"Credit card number must be valid",name:"invalid_card_number",test:function(e){return(0,V.number)(e).isValid}})},e.prototype._getCardNumberVerificationSchema=function(){var e=this;return(0,re.string)().required("Credit card number is required").test({message:"Credit card number must be valid",name:"invalid_card_number",test:function(e){return void 0===e&&(e=""),(0,V.number)(e).isValid}}).test({message:"The card number entered does not match the card stored in your account",name:"mismatched_card_number",test:function(t){return void 0===t&&(t=""),!!e._cardInstrument&&t.slice(-e._cardInstrument.last4.length)===e._cardInstrument.last4}})},e.prototype._mapFromInstrumentCardType=function(e){switch(e){case"amex":case"american_express":return"american-express";case"diners":return"diners-club";default:return e}},e}(),ae=function(){function e(e){this._parentOrigin=e}return e.prototype.create=function(e,t,n,r,i,a,o){void 0===n&&(n={}),void 0===r&&(r=[]),void 0===i&&(i=""),void 0===a&&(a=function(e){switch(e){case Y.CardCode:case Y.CardCodeVerification:return"CVC";case Y.CardExpiry:return"Expiration";case Y.CardName:return"Name on card";case Y.CardNumber:case Y.CardNumberVerification:return"Credit card number"}}(t));var s=z(t);return t===Y.CardNumber?this._createNumberInput(t,e,n,r,i,a,s):t===Y.CardNumberVerification?this._createNumberInput(t,e,n,r,i,a,s,o):t===Y.CardExpiry?this._createExpiryInput(e,n,r,i,a,s):t===Y.CardCodeVerification?this._createInput(t,e,n,r,i,a,s,o):this._createInput(t,e,n,r,i,a,s)},e.prototype.normalizeParentOrigin=function(e){this._parentOrigin!==e&&(this._parentOrigin!==o(a(e)).origin&&e!==o(a(this._parentOrigin)).origin||(this._parentOrigin=e))},e.prototype.getParentOrigin=function(){return this._parentOrigin},e.prototype._createExpiryInput=function(e,t,n,r,i,a){return void 0===i&&(i=""),void 0===a&&(a=""),new J(e,r,i,a,t,n,new c(this._parentOrigin),new y(this._parentOrigin,window.parent),new X(window.parent),new ie,this._createPaymentHandler(),this._createStoredCardHandler(),new x)},e.prototype._createNumberInput=function(e,t,n,r,i,a,o,s){return void 0===a&&(a=""),void 0===o&&(o=""),new K(e,t,i,a,o,n,r,new c(this._parentOrigin),new y(this._parentOrigin,window.parent),new X(window.parent),new ie(s),this._createPaymentHandler(s),this._createStoredCardHandler(s),new W(t,[Y.CardCode,Y.CardExpiry,Y.CardName],new X(window.parent)),new L)},e.prototype._createInput=function(e,t,n,r,i,a,o,s){return void 0===a&&(a=""),void 0===o&&(o=""),new $(e,t,i,a,o,n,r,new c(this._parentOrigin),new y(this._parentOrigin,window.parent),new X(window.parent),new ie(s),this._createPaymentHandler(s),this._createStoredCardHandler(s))},e.prototype._createPaymentHandler=function(e){return new te(new X(window.parent),new ie(e),m(),new y(this._parentOrigin,window.parent),new v((0,h.createClient)()),new B)},e.prototype._createStoredCardHandler=function(e){return new ne(new X(window.parent),new ie(e),new y(this._parentOrigin,window.parent),new G((0,g.createRequestSender)()))},e}(),oe=function(e){function t(t){var n=e.call(this,t||"Unable to proceed due to invalid configuration provided for the hosted payment form.")||this;return n.name="InvalidHostedFormConfigError",n.type="invalid_hosted_form_config",n}return(0,n.__extends)(t,e),t}(r),se=function(){function e(e,t,n){this._factory=e,this._storage=t,this._eventListener=n}return e.prototype.initialize=function(e,t){var n=this;t&&this._storage.setNonce(t);var r=this._createFormContainer(e);return this._resetPageStyles(e),this._eventListener.listen(),(0,_.fromEvent)(this._eventListener,Q.AttachRequested).pipe((0,f.map)((function(e){var t=e.payload,i=t.accessibilityLabel,a=t.cardInstrument,o=t.fontUrls,s=t.placeholder,u=t.styles,d=t.origin,c=t.type;d&&n._factory.normalizeParentOrigin(d);var p=n._factory.create(r,c,u,o,s,i,a);return p.attach(),p})),(0,f.take)(1)).toPromise()},e.prototype._resetPageStyles=function(e){[document.querySelector("html"),document.querySelector("body"),document.getElementById(e)].forEach((function(e){e&&(e.style.height="100%",e.style.width="100%",e.style.overflow="hidden",e.style.padding="0",e.style.margin="0")}))},e.prototype._createFormContainer=function(e){var t=document.getElementById(e);if(!t)throw new oe("Unable to proceed because the provided container ID is not valid.");var n=document.createElement("form"),r=document.createElement("button");return n.noValidate=!0,n.style.height="100%",n.style.width="100%",r.style.display="none",t.appendChild(n),n.appendChild(r),n},e}();function ue(e){var t=e.containerId,n=e.nonce,r=e.parentOrigin;return new se(new ae(r),m(),new c(r)).initialize(t,n)}var de=new y("*",window.parent);function ce(e){de.post({type:Z.AttachFailed,payload:{error:e}})}module.exports=t})();
|
|
1
|
+
(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{initializeHostedInput:()=>ue,notifyInitializeError:()=>ce});const n=require("tslib"),r=function(e){function t(t){var n,r,i=this.constructor,a=e.call(this,t||"An unexpected error has occurred.")||this;return a.name="StandardError",a.type="standard",n=a,r=i.prototype,Object.setPrototypeOf?Object.setPrototypeOf(n,r):n.__proto__=r,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(a,i):a.stack=new Error(a.message).stack,a}return(0,n.__extends)(t,e),t}(Error),i=function(e){function t(t){var n=e.call(this,t||"Invalid arguments have been provided.")||this;return n.name="InvalidArgumentError",n.type="invalid_argument",n}return(0,n.__extends)(t,e),t}(r);function a(e){if(!/^(https?:)?\/\//.test(e))throw new i("The provided URL must be absolute.");var t=document.createElement("a");t.href=e;var n=t.port&&-1!==e.indexOf(t.hostname+":"+t.port)?t.port:"";return{hash:t.hash,hostname:t.hostname,href:t.href,origin:t.protocol+"//"+t.hostname+(n?":"+n:""),pathname:t.pathname,port:n,protocol:t.protocol,search:t.search}}function o(e){return a(0===e.hostname.indexOf("www")?e.href:e.href.replace(e.hostname,"www."+e.hostname))}const s=function(e,t,r){return t&&r?u(0,t,r):function(e){var t=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,n.__extends)(t,e),t}(e);return Object.getOwnPropertyNames(e.prototype).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e.prototype,n);r&&"constructor"!==n&&Object.defineProperty(t.prototype,n,u(e.prototype,n,r))})),t}(e)};function u(e,t,r){if("function"!=typeof r.value)return r;var i=r.value;return{get:function(){var e=i.bind(this);return Object.defineProperty(this,t,(0,n.__assign)((0,n.__assign)({},r),{value:e})),e},set:function(e){i=e}}}function d(e,t){return e.type===t}const c=function(){function e(e){this._sourceOrigins=[a(e).origin,o(a(e)).origin],this._isListening=!1,this._listeners={}}return e.prototype.listen=function(){this._isListening||(this._isListening=!0,window.addEventListener("message",this._handleMessage))},e.prototype.stopListen=function(){this._isListening&&(this._isListening=!1,window.removeEventListener("message",this._handleMessage))},e.prototype.addListener=function(e,t){var n=this._listeners[e];n||(this._listeners[e]=n=[]),-1===n.indexOf(t)&&n.push(t)},e.prototype.removeListener=function(e,t){var n=this._listeners[e];if(n){var r=n.indexOf(t);r>=0&&n.splice(r,1)}},e.prototype.trigger=function(e,t){var n=this._listeners[e.type];n&&n.forEach((function(n){return t?n(e,t):n(e)}))},e.prototype._handleMessage=function(e){if(-1!==this._sourceOrigins.indexOf(e.origin)&&d(e.data,e.data.type)){var t=e.data,r=t.context,i=(0,n.__rest)(t,["context"]);this.trigger(i,r)}},(0,n.__decorate)([s],e.prototype,"_handleMessage",null),e}(),p=function(){function e(){}return e.prototype.setNonce=function(e){this._nonce=e},e.prototype.getNonce=function(){return this._nonce},e}();var l;function m(){return l=l||new p}const h=require("@bigcommerce/bigpay-client"),g=require("@bigcommerce/request-sender"),_=require("rxjs"),f=require("rxjs/operators"),y=function(){function e(e,t,n){this._targetWindow=t,this._context=n,this._targetOrigin="*"===e?"*":a(e).origin}return e.prototype.post=function(e,t){var r=this,i=this._targetWindow;if(window!==i){if(!i)throw new Error("Unable to post message because target window is not set.");var a=t&&(0,_.fromEvent)(window,"message").pipe((0,f.filter)((function(e){return e.origin===r._targetOrigin&&d(e.data,e.data.type)&&-1!==[t.successType,t.errorType].indexOf(e.data.type)})),(0,f.map)((function(e){if(t.errorType===e.data.type)throw e.data;return e.data})),(0,f.take)(1)).toPromise();return i.postMessage((0,n.__assign)((0,n.__assign)({},e),{context:this._context}),this._targetOrigin),a}},e.prototype.setTarget=function(e){this._targetWindow=e},e.prototype.setContext=function(e){this._context=e},e}(),v=function(){function e(e){this._client=e}return e.prototype.submitPayment=function(e){var t=this;return new Promise((function(n,r){t._client.submitPayment(e,(function(e,i){e?r(t._transformResponse(e)):n(t._transformResponse(i))}))}))},e.prototype.initializeOffsitePayment=function(e,t){var n=this;return new Promise((function(){n._client.initializeOffsitePayment(e,null,t)}))},e.prototype._transformResponse=function(e){return{headers:e.headers,body:e.data,status:e.status,statusText:e.statusText}},e}(),C=require("lodash");function b(e,t){var n;return function(e){return void 0!==e.id}(e)?n=e.id:t&&t.length&&(n=t[0].id),{id:n,firstName:e.firstName,lastName:e.lastName,company:e.company,addressLine1:e.address1,addressLine2:e.address2,city:e.city,province:e.stateOrProvince,provinceCode:e.stateOrProvinceCode,postCode:e.postalCode,country:e.country,countryCode:e.countryCode,phone:e.phone,customFields:e.customFields}}const E=function(){function e(e){this._decimalPlaces=e}return e.prototype.toInteger=function(e){return Math.round(e*Math.pow(10,this._decimalPlaces))},e}();var I,A=["per_item_discount","percentage_discount","per_total_discount","shipping_discount","free_shipping"];function T(e){return{code:e.code,discount:e.displayName,discountType:A.indexOf(e.couponType)}}function P(e){return{code:e.code,discountedAmount:e.used,remainingBalance:e.remaining,giftCertificate:{balance:e.balance,code:e.code,purchaseDate:e.purchaseDate}}}function w(e,t,r){return void 0===r&&(r="id"),Object.keys(e).reduce((function(i,a){return(0,n.__spreadArrays)(i,e[a].map((function(e){return"giftCertificates"===a?function(e,t){var n=new E(t);return{id:e.id,imageUrl:"",name:e.name,amount:e.amount,amountAfterDiscount:e.amount,discount:0,integerAmount:n.toInteger(e.amount),integerAmountAfterDiscount:n.toInteger(e.amount),integerUnitPrice:n.toInteger(e.amount),integerUnitPriceAfterDiscount:n.toInteger(e.amount),integerDiscount:0,quantity:1,sender:e.sender,recipient:e.recipient,type:"ItemGiftCertificateEntity",attributes:[],variantId:null}}(e,t):function(e,t,n,r){void 0===r&&(r="id");var i=new E(n);return{id:e[r],imageUrl:e.imageUrl,amount:e.extendedListPrice,amountAfterDiscount:e.extendedSalePrice,discount:e.discountAmount,integerAmount:i.toInteger(e.extendedListPrice),integerAmountAfterDiscount:i.toInteger(e.extendedSalePrice),integerDiscount:i.toInteger(e.discountAmount),integerUnitPrice:i.toInteger(e.listPrice),integerUnitPriceAfterDiscount:i.toInteger(e.salePrice),downloadsPageUrl:e.downloadPageUrl,name:e.name,quantity:e.quantity,brand:e.brand,sku:e.sku,categoryNames:e.categoryNames,variantId:e.variantId,productId:e.productId,attributes:(e.options||[]).map((function(e){return{name:e.name,value:e.value}})),addedByPromotion:e.addedByPromotion,type:t}}(e,function(e){switch(e){case"physicalItems":return"ItemPhysicalEntity";case"digitalItems":return"ItemDigitalEntity";case"giftCertificates":return"ItemGiftCertificateEntity";default:return""}}(a),t,r)})))}),[])}function S(e){var t,n,r=e.cart.currency.decimalPlaces,i=new E(r);return{id:e.cart.id,items:w(e.cart.lineItems,r),currency:e.cart.currency.code,coupon:{discountedAmount:(0,C.reduce)(e.cart.coupons,(function(e,t){return e+t.discountedAmount}),0),coupons:e.cart.coupons.map(T)},discount:{amount:e.cart.discountAmount,integerAmount:i.toInteger(e.cart.discountAmount)},discountNotifications:(t=e.promotions,n=[],(t||[]).forEach((function(e){(e.banners||[]).forEach((function(e){n.push({placeholders:[],discountType:null,message:"",messageHtml:e.text})}))})),n),giftCertificate:{totalDiscountedAmount:(0,C.reduce)(e.giftCertificates,(function(e,t){return e+t.used}),0),appliedGiftCertificates:(0,C.keyBy)(e.giftCertificates.map(P),"code")},shipping:{amount:e.shippingCostTotal,integerAmount:i.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:i.toInteger(e.shippingCostBeforeDiscount),required:(0,C.some)(e.cart.lineItems.physicalItems,(function(e){return e.isShippingRequired}))},subtotal:{amount:e.subtotal,integerAmount:i.toInteger(e.subtotal)},storeCredit:{amount:e.customer?e.customer.storeCredit:0},taxSubtotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:i.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.grandTotal,integerAmount:i.toInteger(e.grandTotal)}}}!function(e){e.APPLEPAY="applepay",e.AMAZON_PAY_V2="amazonpay",e.BRAINTREE_PAYPAL="braintreepaypal",e.BRAINTREE_VENMO="braintreevenmo",e.BRAINTREE_PAYPAL_CREDIT="braintreepaypalcredit",e.GOOGLEPAY_ADYENV2="googlepayadyenv2",e.GOOGLEPAY_ADYENV3="googlepayadyenv3",e.GOOGLEPAY_AUTHORIZENET="googlepayauthorizenet",e.GOOGLEPAY_BNZ="googlepaybnz",e.GOOGLEPAY_BRAINTREE="googlepaybraintree",e.GOOGLEPAY_CHECKOUTCOM="googlepaycheckoutcom",e.GOOGLEPAY_CYBERSOURCEV2="googlepaycybersourcev2",e.GOOGLEPAY_ORBITAL="googlepayorbital",e.GOOGLEPAY_STRIPE="googlepaystripe",e.GOOGLEPAY_STRIPEUPE="googlepaystripeupe",e.GOOGLEPAY_WORLDPAYACCESS="googlepayworldpayaccess",e.MASTERPASS="masterpass",e.PAYPALEXPRESS="paypalexpress"}(I||(I={}));const O=I;var N;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentProviderCustomer=13]="MissingPaymentProviderCustomer",e[e.MissingPaymentRedirectUrl=14]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=15]="MissingPaymentStatus",e[e.MissingPaymentToken=16]="MissingPaymentToken",e[e.MissingShippingAddress=17]="MissingShippingAddress"}(N||(N={}));const M=function(e){function t(t){var n=e.call(this,function(e){switch(e){case N.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case N.MissingCart:return"Unable to proceed because cart data is unavailable.";case N.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case N.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case N.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case N.MissingCheckoutConfig:case N.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case N.MissingOrder:return"Unable to proceed because order data is unavailable.";case N.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case N.MissingPayment:return"Unable to proceed because payment data is unavailable.";case N.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case N.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case N.MissingPaymentProviderCustomer:return"Unable to proceed because payment provider customer is unavailable.";case N.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(t))||this;return n.subtype=t,n.name="MissingDataError",n.type="missing_data",n}return(0,n.__extends)(t,e),t}(r);function D(e,t){var n=e.firstName||t.firstName||"",r=e.lastName||t.lastName||"";return{addresses:(e.addresses||[]).map((function(e){return b(e)})),customerId:e.id,isGuest:e.isGuest,storeCredit:e.storeCredit,email:e.email||t.email||"",firstName:n,lastName:r,name:e.fullName||[n,r].join(" "),customerGroupName:e.customerGroup&&e.customerGroup.name}}const x=function(){function e(){}return e.prototype.format=function(e){var t=e.split(new RegExp("\\s*/\\s*")),n=t[0],r=void 0===n?"":n,i=t[1],a=void 0===i?"":i,o=r.slice(0,2),s=4===a.length?a.slice(-2):a?a.slice(0,2):r.slice(2);return e.length<2?r:e.length>3&&!s?o:o+" / "+s},e.prototype.toObject=function(e){var t=e.split(new RegExp("\\s*/\\s*")),n=t[0],r=void 0===n?"":n,i=t[1],a=void 0===i?"":i;return/^\d+$/.test(r)&&/^\d+$/.test(a)?{month:1===r.length?"0"+r:r.slice(0,2),year:2===a.length?"20"+a:a.slice(0,4)}:{month:"",year:""}},e}(),V=require("card-validator"),L=function(){function e(){}return e.prototype.format=function(e){var t=(0,V.number)(e).card;if(!t)return e;var n=(0,C.max)((0,V.creditCardType)(e).map((function(e){return(0,C.max)(e.lengths)}))),r=this.unformat(e).slice(0,n);return t.gaps.filter((function(e){return r.length>e})).reduce((function(e,t,n){return[e.slice(0,t+n),e.slice(t+n)].join(" ")}),r)},e.prototype.unformat=function(e){return(0,V.number)(e).card?e.replace(new RegExp(" ","g"),""):e},e}();function U(e,t){void 0===t&&(t={});var n,r,i=e.currency.decimalPlaces,a=new E(i);return{id:e.orderId,items:w(e.lineItems,e.currency.decimalPlaces,"productId"),orderId:e.orderId,currency:e.currency.code,customerCanBeCreated:e.customerCanBeCreated,payment:R(e.payments,t.payment),subtotal:{amount:e.baseAmount,integerAmount:a.toInteger(e.baseAmount)},coupon:{discountedAmount:(0,C.reduce)(e.coupons,(function(e,t){return e+t.discountedAmount}),0),coupons:e.coupons.map(T)},discount:{amount:e.discountAmount,integerAmount:a.toInteger(e.discountAmount)},token:t.orderToken,callbackUrl:t.callbackUrl,discountNotifications:[],giftCertificate:(n=e.payments,r=(0,C.filter)(n,{providerId:"giftcertificate"}),{totalDiscountedAmount:(0,C.reduce)(r,(function(e,t){return t.amount+e}),0),appliedGiftCertificates:(0,C.keyBy)(r.map((function(e){return{code:e.detail.code,discountedAmount:e.amount,remainingBalance:e.detail.remaining,giftCertificate:{balance:e.amount+e.detail.remaining,code:e.detail.code,purchaseDate:""}}})),"code")}),socialData:F(e),status:e.status,hasDigitalItems:e.hasDigitalItems,isDownloadable:e.isDownloadable,isComplete:e.isComplete,shipping:{amount:e.shippingCostTotal,integerAmount:a.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:a.toInteger(e.shippingCostBeforeDiscount)},storeCredit:{amount:k(e.payments)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:a.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:a.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.orderAmount,integerAmount:e.orderAmountAsInteger}}}function k(e){var t=(0,C.find)(e,{providerId:"storecredit"});return t?t.amount:0}function R(e,t){void 0===t&&(t={});var n,r=(0,C.find)(e,q);return r?{id:r.providerId,status:(n=r.detail.step,"PAYMENT_STATUS_"+n),helpText:r.detail.instructions,returnUrl:t.returnUrl}:{}}function q(e){return"giftcertificate"!==e.providerId&&"storecredit"!==e.providerId}function F(e){var t={};return(0,n.__spreadArrays)(e.lineItems.physicalItems,e.lineItems.digitalItems).forEach((function(e){var n;t[e.id]=(n=e,["fb","tw","gp"].reduce((function(e,t){var r=n.socialMedia&&(0,C.find)(n.socialMedia,(function(e){return e.code===t}));return r?(e[t]={name:n.name,description:n.name,image:n.imageUrl,url:r.link,shareText:r.text,sharingLink:r.link,channelName:r.channel,channelCode:r.code},e):e}),{}))})),t}function H(e,t){return{description:e.description,module:e.type,price:e.cost,id:e.id,selected:t,isRecommended:e.isRecommended,imageUrl:e.imageUrl,transitTime:e.transitTime}}const B=function(){function e(){this._cardExpiryFormatter=new x,this._cardNumberFormatter=new L}return e.prototype.transform=function(e,t){var r,i=t.billingAddress.getBillingAddress(),a=t.checkout.getCheckout(),o=t.customer.getCustomer(),s=t.order.getOrder(),u=t.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),d=this._mapShippingAddress(t,u),c=t.consignments.getConsignments(),p=t.consignments.getShippingOption(),l=t.config.getStoreConfig(),m=t.config.getContextConfig(),h=t.instruments.getInstrumentsMeta(),g=t.paymentMethods.getPaymentMethodsMeta(),_=t.order.getOrderMeta(),f=o&&i&&D(o,i),y=h&&e.paymentData&&(r=e.paymentData,Boolean(r.instrumentId)||function(e){var t=e.formattedPayload;return!!t&&("string"==typeof t.bigpay_token||Boolean(t.bigpay_token&&t.bigpay_token.token))}(e.paymentData))?t.payment.getPaymentToken()+", "+h.vaultAccessToken:t.payment.getPaymentToken();if(!y)throw new M(N.MissingPaymentToken);return{additionalAction:e.additionalAction,authToken:y,customer:f,billingAddress:i&&b(i),shippingAddress:d&&b(d,c),shippingOption:p&&H(p,!0),cart:a&&S(a),order:s&&U(s,_),orderMeta:_,payment:e.paymentData,paymentMethod:u&&this._transformPaymentMethod(u),quoteMeta:{request:(0,n.__assign)((0,n.__assign)({},g),{geoCountryCode:m&&m.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:(0,C.pick)(l&&l.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}},e.prototype.transformWithHostedFormData=function(e,t,r){var i=t.additionalAction,a=t.authToken,o=t.checkout,s=t.config,u=t.order,d=t.orderMeta,c=t.payment,p=void 0===c?{}:c,l=t.paymentMethod,m=t.paymentMethodMeta,h=o&&o.consignments[0],g=h&&h.shippingAddress,_=h&&h.selectedShippingOption;return{additionalAction:i,authToken:a,paymentMethod:l&&this._transformPaymentMethod(l),customer:u&&u.billingAddress&&o&&D(o.customer,u.billingAddress),billingAddress:u&&u.billingAddress&&b(u.billingAddress),shippingAddress:g&&o&&b(g,o.consignments),shippingOption:_&&H(_,!0),cart:o&&S(o),order:u&&U(u,d),orderMeta:d,payment:this._transformHostedInputValues(e,p,r),quoteMeta:{request:(0,n.__assign)((0,n.__assign)({},m),{geoCountryCode:s&&s.context.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:s&&(0,C.pick)(s.storeConfig.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}},e.prototype._transformPaymentMethod=function(e){return"multi-option"!==e.method||e.gateway?e.initializationData&&e.initializationData.gateway?(0,n.__assign)((0,n.__assign)({},e),{id:e.initializationData.gateway}):e.id===O.BRAINTREE_VENMO?(0,n.__assign)((0,n.__assign)({},e),{id:O.BRAINTREE_PAYPAL}):e:(0,n.__assign)((0,n.__assign)({},e),{gateway:e.id})},e.prototype._transformHostedInputValues=function(e,t,r){return"instrumentId"in t?(0,n.__assign)((0,n.__assign)({},t),{ccCvv:e.cardCodeVerification,ccNumber:e.cardNumberVerification&&this._cardNumberFormatter.unformat(e.cardNumberVerification),hostedFormNonce:r}):(0,n.__assign)((0,n.__assign)({},t),{ccCvv:e.cardCode,ccExpiry:this._cardExpiryFormatter.toObject(e.cardExpiry||""),ccName:e.cardName||"",ccNumber:this._cardNumberFormatter.unformat(e.cardNumber||""),hostedFormNonce:r})},e.prototype._mapShippingAddress=function(e,t){var n,r,i,a;if(t){var o=null===(r=null===(n=t.initializationData)||void 0===n?void 0:n.bopis)||void 0===r?void 0:r.enabled,s=null===(a=null===(i=t.initializationData)||void 0===i?void 0:i.bopis)||void 0===a?void 0:a.requiredAddress,u=e.consignments.getConsignments(),d=null==u?void 0:u.every((function(e){return e.selectedPickupOption}));if(o&&d&&"none"===s)return}return e.shippingAddress.getShippingAddress()},e}(),G=function(){function e(e){this._requestSender=e}return e.prototype.submitPaymentInstrument=function(e,t){return(0,n.__awaiter)(this,void 0,void 0,(function(){var r,i,a,o,s,u,d,c,p,l,m;return(0,n.__generator)(this,(function(h){switch(h.label){case 0:return r=e.providerId,i=e.currencyCode,a=e.paymentsUrl,o=e.shopperId,s=e.storeHash,u=e.vaultToken,d=t.billingAddress,c=t.instrument,p=t.defaultInstrument,l=a+"/stores/"+s+"/customers/"+o+"/stored_instruments",m={headers:{Authorization:u,Accept:"application/vnd.bc.v1+json","Content-Type":"application/vnd.bc.v1+json"},body:JSON.stringify({instrument:{type:c.type,cardholder_name:c.cardholderName,number:c.number,expiry_month:c.expiryMonth,expiry_year:c.expiryYear,verification_value:c.verificationValue},billing_address:(0,n.__assign)((0,n.__assign)((0,n.__assign)((0,n.__assign)((0,n.__assign)((0,n.__assign)({email:d.email,address1:d.address1},d.address2&&{address2:d.address2}),{city:d.city,postal_code:d.postalCode,country_code:d.countryCode}),d.company&&{company:d.company}),{first_name:d.firstName,last_name:d.lastName}),d.phone&&{phone:d.phone}),d.stateOrProvinceCode&&{state_or_province_code:d.stateOrProvinceCode}),provider_id:r,default_instrument:p,currency_code:i})},[4,this._requestSender.post(l,m)];case 1:return h.sent(),[2]}}))}))},e}();var j;!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(j||(j={}));const Y=j;function z(e){switch(e){case Y.CardCode:return"cc-csc";case Y.CardExpiry:return"cc-exp";case Y.CardName:return"cc-name";case Y.CardNumber:return"cc-number";default:return""}}const W=function(){function e(e,t,n){var r=this;this._form=e,this._fieldTypes=t,this._inputAggregator=n,this._handleChange=function(e){var t=e.target;if(!t)throw new Error("Unable to get a reference to the target of the change event.");var n=r._inputAggregator.getInputs().find((function(e){return r._getAutocompleteElementId(e.getType())===t.id}));n&&n.setValue(t.value)},this._inputs=this._fieldTypes.map((function(e){return r._createInput(e)}))}return e.prototype.attach=function(){var e=this;this._inputs.forEach((function(t){return e._form.appendChild(t)}))},e.prototype.detach=function(){this._inputs.forEach((function(e){e.parentElement&&e.parentElement.removeChild(e)}))},e.prototype._createInput=function(e){var t=document.createElement("input");return t.autocomplete=z(e),t.id=this._getAutocompleteElementId(e),t.tabIndex=-1,t.style.position="absolute",t.style.opacity="0",t.style.zIndex="-1",t.addEventListener("change",this._handleChange),t},e.prototype._getAutocompleteElementId=function(e){return"autocomplete-"+(0,C.kebabCase)(e)},e}();var Q,Z;!function(e){e.AttachRequested="HOSTED_FIELD:ATTACH_REQUESTED",e.SubmitRequested="HOSTED_FIELD:SUBMITTED_REQUESTED",e.ValidateRequested="HOSTED_FIELD:VALIDATE_REQUESTED",e.StoredCardRequested="HOSTED_FIELD:STORED_CARD_REQUESTED"}(Q||(Q={})),function(e){e.AttachSucceeded="HOSTED_INPUT:ATTACH_SUCCEEDED",e.AttachFailed="HOSTED_INPUT:ATTACH_FAILED",e.BinChanged="HOSTED_INPUT:BIN_CHANGED",e.Blurred="HOSTED_INPUT:BLURRED",e.Changed="HOSTED_INPUT:CHANGED",e.CardTypeChanged="HOSTED_INPUT:CARD_TYPE_CHANGED",e.Entered="HOSTED_INPUT:ENTERED",e.Focused="HOSTED_INPUT:FOCUSED",e.SubmitSucceeded="HOSTED_INPUT:SUBMIT_SUCCEEDED",e.SubmitFailed="HOSTED_INPUT:SUBMIT_FAILED",e.Validated="HOSTED_INPUT:VALIDATED",e.StoredCardSucceeded="HOSTED_INPUT:STORED_CARD_SUCCEEDED",e.StoredCardFailed="HOSTED_INPUT:STORED_CARD_FAILED"}(Z||(Z={}));const $=function(){function e(e,t,n,r,i,a,o,s,u,d,c,p,l){var m=this;this._type=e,this._form=t,this._placeholder=n,this._accessibilityLabel=r,this._autocomplete=i,this._styles=a,this._fontUrls=o,this._eventListener=s,this._eventPoster=u,this._inputAggregator=d,this._inputValidator=c,this._paymentHandler=p,this._storedCardHandler=l,this._isTouched=!1,this._handleInput=function(e){var t=e.target;m._processChange(t.value)},this._handleBlur=function(){m._applyStyles(m._styles.default),m._validateForm(),m._eventPoster.post({type:Z.Blurred,payload:{fieldType:m._type}})},this._handleFocus=function(){m._applyStyles(m._styles.focus),m._eventPoster.post({type:Z.Focused,payload:{fieldType:m._type}})},this._handleValidate=function(){m._validateForm()},this._handleSubmit=function(e){e.preventDefault(),m._eventPoster.post({type:Z.Entered,payload:{fieldType:m._type}})},this._forceFocusToInput=function(){document.activeElement===document.body&&(navigator.userAgent.toLowerCase().indexOf("safari")>-1?""===m._input.value&&(m._input.setAttribute("value"," "),m._input.setSelectionRange(0,1),m._input.setAttribute("value","")):m._input.focus())},this._input=document.createElement("input"),this._input.addEventListener("input",this._handleInput),this._input.addEventListener("blur",this._handleBlur),this._input.addEventListener("focus",this._handleFocus),this._eventListener.addListener(Q.ValidateRequested,this._handleValidate),this._eventListener.addListener(Q.SubmitRequested,this._paymentHandler.handle),this._eventListener.addListener(Q.StoredCardRequested,this._storedCardHandler.handle),this._configureInput()}return e.prototype.getType=function(){return this._type},e.prototype.getValue=function(){return this._input.value},e.prototype.setValue=function(e){this._processChange(e)},e.prototype.isTouched=function(){return this._isTouched},e.prototype.attach=function(){this._form.appendChild(this._input),this._form.addEventListener("submit",this._handleSubmit),this._loadFonts(),this._eventPoster.setTarget(window.parent),this._eventListener.listen(),window.addEventListener("focus",this._forceFocusToInput),window.hostedInput=this,this._eventPoster.post({type:Z.AttachSucceeded})},e.prototype.detach=function(){this._input.parentElement&&this._input.parentElement.removeChild(this._input),this._form.removeEventListener("submit",this._handleSubmit),this._unloadFonts(),window.removeEventListener("focus",this._forceFocusToInput),this._eventListener.stopListen()},e.prototype._formatValue=function(e){this._input.value=e},e.prototype._notifyChange=function(e){this._eventPoster.post({type:Z.Changed,payload:{fieldType:this._type}})},e.prototype._configureInput=function(){switch(this._input.style.backgroundColor="transparent",this._input.style.border="0",this._input.style.display="block",this._input.style.height="100%",this._input.style.margin="0",this._input.style.outline="none",this._input.style.padding="0",this._input.style.width="100%",this._input.id=(0,C.kebabCase)(this._type),this._input.placeholder=this._placeholder,this._input.autocomplete=this._autocomplete,this._input.setAttribute("aria-label",this._accessibilityLabel),this._applyStyles(this._styles.default),this._input.id){case"card-code":case"card-expiry":case"card-number":this._input.type="text",this._input.inputMode="numeric",this._input.pattern="[0-9]*";break;case"card-name":this._input.type="text",this._input.inputMode="text"}},e.prototype._applyStyles=function(e){var t=this;void 0===e&&(e={});var n={color:e.color,fontFamily:e.fontFamily,fontSize:e.fontSize,fontWeight:e.fontWeight};Object.keys(n).forEach((function(e){n[e]&&(t._input.style[e]=n[e]||"")}))},e.prototype._loadFonts=function(){this._fontLinks||(this._fontLinks=this._fontUrls.filter((function(e){return"fonts.googleapis.com"===a(e).hostname})).filter((function(e){return!document.querySelector("link[href='"+e+"'][rel='stylesheet']")})).map((function(e){var t=document.createElement("link");return t.rel="stylesheet",t.href=e,document.head.appendChild(t),t})))},e.prototype._unloadFonts=function(){this._fontLinks&&(this._fontLinks.forEach((function(e){e.parentElement&&e.parentElement.removeChild(e)})),this._fontLinks=void 0)},e.prototype._validateForm=function(){return(0,n.__awaiter)(this,void 0,void 0,(function(){var e,t;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return e=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(e)];case 1:return(t=n.sent()).isValid?this._applyStyles(this._styles.default):this._applyStyles(this._styles.error),this._eventPoster.post({type:Z.Validated,payload:t}),[2]}}))}))},e.prototype._processChange=function(e){e!==this._previousValue&&(this._isTouched=!0,this._formatValue(e),this._validateForm(),this._notifyChange(e),this._previousValue=e)},e}(),J=function(e){function t(t,n,r,i,a,o,s,u,d,c,p,l,m){var h=e.call(this,Y.CardExpiry,t,n,r,i,a,o,s,u,d,c,p,l)||this;return h._formatter=m,h}return(0,n.__extends)(t,e),t.prototype._formatValue=function(e){this._input.value=this._formatter.format(e)},t}($),K=function(e){function t(t,n,r,i,a,o,s,u,d,c,p,l,m,h,g){var _=e.call(this,t,n,r,i,a,o,s,u,d,c,p,l,m)||this;return _._autocompleteFieldset=h,_._formatter=g,_}return(0,n.__extends)(t,e),t.prototype.attach=function(){e.prototype.attach.call(this),this._autocompleteFieldset.attach()},t.prototype._notifyChange=function(e){var t=(0,V.number)(e).card,n=this._previousValue&&(0,V.number)(this._previousValue).card;(0,C.get)(n,"type")!==(0,C.get)(t,"type")&&this._eventPoster.post({type:Z.CardTypeChanged,payload:{cardType:t?t.type:void 0}});var r=this._formatter.unformat(e),i=this._previousValue?this._formatter.unformat(this._previousValue):"",a=r.length>=6&&(0,V.number)(r).isPotentiallyValid?r.substr(0,6):"";a!==(i.length>=6?i.substr(0,6):"")&&this._eventPoster.post({type:Z.BinChanged,payload:{bin:a}})},t.prototype._formatValue=function(e){var t=this._input.selectionEnd,n=this._formatter.format(e);t===e.length&&e.length<n.length?this._input.setSelectionRange(n.length,n.length):this._input.setSelectionRange(t||0,t||0),this._input.value=n},t}($),X=function(){function e(e){this._parentWindow=e}return e.prototype.getInputs=function(e){return Array.prototype.slice.call(this._parentWindow.frames).reduce((function(t,r){try{var i=r.hostedInput;return!i||e&&!e(i)?t:(0,n.__spreadArrays)(t,[i])}catch(e){if(e instanceof DOMException)return t;if(e instanceof Error&&"Permission denied"===e.message)return t;throw e}}),[])},e.prototype.getInputValues=function(e){return this.getInputs(e).reduce((function(e,t){var r;return(0,n.__assign)((0,n.__assign)({},e),((r={})[t.getType()]=t.getValue(),r))}),{})},e}(),ee=function(e){function t(t){var r=e.call(this,(0,n.__spreadArrays)(["Unable to proceed due to invalid user input values"],(0,C.flatMap)((0,C.values)(t),(function(e){return(0,C.map)(e,(function(e){return e.message}))}))).join(". "))||this;return r.errors=t,r.name="InvalidHostedFormValueError",r.type="invalid_hosted_form_value",r}return(0,n.__extends)(t,e),t}(r),te=function(){function e(e,t,r,i,a,o){var s=this;this._inputAggregator=e,this._inputValidator=t,this._inputStorage=r,this._eventPoster=i,this._paymentRequestSender=a,this._paymentRequestTransformer=o,this.handle=function(e){var t=e.payload.data;return(0,n.__awaiter)(s,void 0,void 0,(function(){var e,r,i,a,o;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return e=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(e)];case 1:if(r=n.sent(),this._eventPoster.post({type:Z.Validated,payload:r}),!r.isValid)return i=new ee(r.errors),[2,this._eventPoster.post({type:Z.SubmitFailed,payload:{error:{code:(0,C.snakeCase)(i.name),message:i.message}}})];n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transformWithHostedFormData(e,t,this._inputStorage.getNonce()||""))];case 3:return a=n.sent(),this._eventPoster.post({type:Z.SubmitSucceeded,payload:{response:a}}),[3,5];case 4:return o=n.sent(),this._eventPoster.post({type:Z.SubmitFailed,payload:this._isPaymentErrorResponse(o)?{error:o.body.errors[0],response:o}:{error:{code:(0,C.snakeCase)(o.name),message:o.message}}}),[3,5];case 5:return[2]}}))}))}}return e.prototype._isPaymentErrorResponse=function(e){var t=(e||{}).body,n=(void 0===t?{}:t).errors,r=void 0===n?[]:n;return"string"==typeof(r[0]&&r[0].code)&&"string"==typeof(r[0]&&r[0].message)},e}(),ne=function(e,t,r,i){var a=this;this._inputAggregator=e,this._inputValidator=t,this._eventPoster=r,this._storedCardRequestSender=i,this.handle=function(e){return(0,n.__awaiter)(a,void 0,void 0,(function(){var t,r,i,a,o,s,u,d,c,p,l;return(0,n.__generator)(this,(function(m){switch(m.label){case 0:return t=e.payload,r=t.data,i=t.fields,a=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(a)];case 1:if(o=m.sent(),this._eventPoster.post({type:Z.Validated,payload:o}),!o.isValid)return[2,this._eventPoster.post({type:Z.StoredCardFailed})];s=i.defaultInstrument,u=(0,n.__rest)(i,["defaultInstrument"]),d=a.cardExpiry?a.cardExpiry.split("/"):[],c=d[0],p=d[1],m.label=2;case 2:return m.trys.push([2,4,,5]),[4,this._storedCardRequestSender.submitPaymentInstrument(r,{billingAddress:u,instrument:{type:"card",cardholderName:a.cardName||"",number:a.cardNumber?a.cardNumber.replace(/ /g,""):"",expiryMonth:Number(c.trim()),expiryYear:Number("20"+p.trim()),verificationValue:null!==(l=a.cardCode)&&void 0!==l?l:""},defaultInstrument:s})];case 3:return m.sent(),this._eventPoster.post({type:Z.StoredCardSucceeded}),[3,5];case 4:return m.sent(),this._eventPoster.post({type:Z.StoredCardFailed}),[3,5];case 5:return[2]}}))}))}},re=require("yup"),ie=function(){function e(e){this._cardInstrument=e,this._completeSchema={cardCode:this._getCardCodeSchema(),cardCodeVerification:this._getCardCodeVerificationSchema(),cardExpiry:this._getCardExpirySchema(),cardName:this._getCardNameSchema(),cardNumber:this._getCardNumberSchema(),cardNumberVerification:this._getCardNumberVerificationSchema()},this._configureCardValidator()}return e.prototype.validate=function(e){return(0,n.__awaiter)(this,void 0,void 0,(function(){var t,r,i,a;return(0,n.__generator)(this,(function(o){switch(o.label){case 0:for(i in t={},r={errors:{},isValid:!0},e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=this._completeSchema[i],r.errors[i]=[]);o.label=1;case 1:return o.trys.push([1,3,,4]),[4,(0,re.object)(t).validate(e,{abortEarly:!1})];case 2:return o.sent(),[2,r];case 3:if("ValidationError"!==(a=o.sent()).name)throw a;return[2,{errors:Object.keys(r.errors).reduce((function(e,t){var r;return(0,n.__assign)((0,n.__assign)({},e),((r={})[t]=a.inner.filter((function(e){return e.path===t})).map((function(e){return{fieldType:e.path,message:e.errors.join(" "),type:e.type}})),r))}),{}),isValid:!1}];case 4:return[2]}}))}))},e.prototype._configureCardValidator=function(){var e=V.creditCardType.getTypeInfo("discover"),t=V.creditCardType.getTypeInfo("jcb"),r=V.creditCardType.getTypeInfo("visa");V.creditCardType.updateCard("visa",{lengths:(0,n.__spreadArrays)([13],r.lengths||[])}),V.creditCardType.updateCard("discover",{patterns:(0,n.__spreadArrays)(e.patterns||[],[[810,817]])}),V.creditCardType.addCard({niceType:"Mada",type:"mada",patterns:[400861,401757,407197,407395,409201,410685,412565,417633,419593,422817,422818,422819,428331,428671,428672,428673,431361,432328,434107,439954,440533,440647,440795,445564,446393,446404,446672,455036,455708,457865,458456,462220,468540,468541,468542,468543,483010,483011,483012,484783,486094,486095,486096,489317,489318,489319,493428,504300,506968,508160,513213,520058,521076,524130,524514,529415,529741,530060,530906,531095,531196,532013,535825,535989,536023,537767,539931,543085,543357,549760,554180,557606,558848,585265,588845,588846,588847,588848,588849,588850,588851,588982,588983,589005,589206,604906,605141,636120,968201,968202,968203,968204,968205,968206,968207,968208,968209,968210,968211],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}),V.creditCardType.updateCard("jcb",{patterns:(0,n.__spreadArrays)(t.patterns||[],[3088,3337,3338])})},e.prototype._getCardCodeSchema=function(){return(0,re.string)().required("CVV is required").test({message:"CVV must be valid",name:"invalid_card_code",test:function(e){var t=(0,V.number)(this.parent.cardNumber||"").card;return(0,V.cvv)(e,t&&t.code?t.code.size:void 0).isValid}})},e.prototype._getCardCodeVerificationSchema=function(){var e=this;return(0,re.string)().required("CVV is required").test({message:"CVV must be valid",name:"invalid_card_code",test:function(t){void 0===t&&(t="");var n=e._cardInstrument&&e._mapFromInstrumentCardType(e._cardInstrument.brand),r=n&&V.creditCardType.getTypeInfo(n);return(0,V.cvv)(t,r&&r.code?r.code.size:void 0).isValid}})},e.prototype._getCardExpirySchema=function(){return(0,re.string)().required("Expiration date is required").test({message:"Expiration date must be a valid future date in MM / YY format",name:"invalid_card_expiry",test:function(e){return(0,V.expirationDate)(e).isValid}})},e.prototype._getCardNameSchema=function(){return(0,re.string)().max(200).required("Full name is required")},e.prototype._getCardNumberSchema=function(){return(0,re.string)().required("Credit card number is required").test({message:"Credit card number must be valid",name:"invalid_card_number",test:function(e){return(0,V.number)(e).isValid}})},e.prototype._getCardNumberVerificationSchema=function(){var e=this;return(0,re.string)().required("Credit card number is required").test({message:"Credit card number must be valid",name:"invalid_card_number",test:function(e){return void 0===e&&(e=""),(0,V.number)(e).isValid}}).test({message:"The card number entered does not match the card stored in your account",name:"mismatched_card_number",test:function(t){return void 0===t&&(t=""),!!e._cardInstrument&&t.slice(-e._cardInstrument.last4.length)===e._cardInstrument.last4}})},e.prototype._mapFromInstrumentCardType=function(e){switch(e){case"amex":case"american_express":return"american-express";case"diners":return"diners-club";default:return e}},e}(),ae=function(){function e(e){this._parentOrigin=e}return e.prototype.create=function(e,t,n,r,i,a,o){void 0===n&&(n={}),void 0===r&&(r=[]),void 0===i&&(i=""),void 0===a&&(a=function(e){switch(e){case Y.CardCode:case Y.CardCodeVerification:return"CVC";case Y.CardExpiry:return"Expiration";case Y.CardName:return"Name on card";case Y.CardNumber:case Y.CardNumberVerification:return"Credit card number"}}(t));var s=z(t);return t===Y.CardNumber?this._createNumberInput(t,e,n,r,i,a,s):t===Y.CardNumberVerification?this._createNumberInput(t,e,n,r,i,a,s,o):t===Y.CardExpiry?this._createExpiryInput(e,n,r,i,a,s):t===Y.CardCodeVerification?this._createInput(t,e,n,r,i,a,s,o):this._createInput(t,e,n,r,i,a,s)},e.prototype.normalizeParentOrigin=function(e){this._parentOrigin!==e&&(this._parentOrigin!==o(a(e)).origin&&e!==o(a(this._parentOrigin)).origin||(this._parentOrigin=e))},e.prototype.getParentOrigin=function(){return this._parentOrigin},e.prototype._createExpiryInput=function(e,t,n,r,i,a){return void 0===i&&(i=""),void 0===a&&(a=""),new J(e,r,i,a,t,n,new c(this._parentOrigin),new y(this._parentOrigin,window.parent),new X(window.parent),new ie,this._createPaymentHandler(),this._createStoredCardHandler(),new x)},e.prototype._createNumberInput=function(e,t,n,r,i,a,o,s){return void 0===a&&(a=""),void 0===o&&(o=""),new K(e,t,i,a,o,n,r,new c(this._parentOrigin),new y(this._parentOrigin,window.parent),new X(window.parent),new ie(s),this._createPaymentHandler(s),this._createStoredCardHandler(s),new W(t,[Y.CardCode,Y.CardExpiry,Y.CardName],new X(window.parent)),new L)},e.prototype._createInput=function(e,t,n,r,i,a,o,s){return void 0===a&&(a=""),void 0===o&&(o=""),new $(e,t,i,a,o,n,r,new c(this._parentOrigin),new y(this._parentOrigin,window.parent),new X(window.parent),new ie(s),this._createPaymentHandler(s),this._createStoredCardHandler(s))},e.prototype._createPaymentHandler=function(e){return new te(new X(window.parent),new ie(e),m(),new y(this._parentOrigin,window.parent),new v((0,h.createClient)()),new B)},e.prototype._createStoredCardHandler=function(e){return new ne(new X(window.parent),new ie(e),new y(this._parentOrigin,window.parent),new G((0,g.createRequestSender)()))},e}(),oe=function(e){function t(t){var n=e.call(this,t||"Unable to proceed due to invalid configuration provided for the hosted payment form.")||this;return n.name="InvalidHostedFormConfigError",n.type="invalid_hosted_form_config",n}return(0,n.__extends)(t,e),t}(r),se=function(){function e(e,t,n){this._factory=e,this._storage=t,this._eventListener=n}return e.prototype.initialize=function(e,t){var n=this;t&&this._storage.setNonce(t);var r=this._createFormContainer(e);return this._resetPageStyles(e),this._eventListener.listen(),(0,_.fromEvent)(this._eventListener,Q.AttachRequested).pipe((0,f.map)((function(e){var t=e.payload,i=t.accessibilityLabel,a=t.cardInstrument,o=t.fontUrls,s=t.placeholder,u=t.styles,d=t.origin,c=t.type;d&&n._factory.normalizeParentOrigin(d);var p=n._factory.create(r,c,u,o,s,i,a);return p.attach(),p})),(0,f.take)(1)).toPromise()},e.prototype._resetPageStyles=function(e){[document.querySelector("html"),document.querySelector("body"),document.getElementById(e)].forEach((function(e){e&&(e.style.height="100%",e.style.width="100%",e.style.overflow="hidden",e.style.padding="0",e.style.margin="0")}))},e.prototype._createFormContainer=function(e){var t=document.getElementById(e);if(!t)throw new oe("Unable to proceed because the provided container ID is not valid.");var n=document.createElement("form"),r=document.createElement("button");return n.noValidate=!0,n.style.height="100%",n.style.width="100%",r.style.display="none",t.appendChild(n),n.appendChild(r),n},e}();function ue(e){var t=e.containerId,n=e.nonce,r=e.parentOrigin;return new se(new ae(r),m(),new c(r)).initialize(t,n)}var de=new y("*",window.parent);function ce(e){de.post({type:Z.AttachFailed,payload:{error:e}})}module.exports=t})();
|
|
2
2
|
//# sourceMappingURL=hosted-form.js.map
|