@bigcommerce/checkout-sdk 1.631.0 → 1.631.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-v2-iframe-content.d.ts +40 -52
- package/dist/hosted-form-v2-iframe-content.js +1 -1
- package/dist/hosted-form-v2-iframe-content.js.map +1 -1
- package/dist/hosted-form-v2-iframe-content.umd.js +1 -1
- package/dist/hosted-form-v2-iframe-content.umd.js.LICENSE.txt +8 -0
- package/dist/hosted-form-v2-iframe-content.umd.js.map +1 -1
- package/dist/hosted-form-v2-iframe-host.d.ts +37 -26
- package/dist/hosted-form-v2-iframe-host.js +1 -1
- package/dist/hosted-form-v2-iframe-host.js.map +1 -1
- package/dist/hosted-form-v2-iframe-host.umd.js +1 -1
- package/dist/hosted-form-v2-iframe-host.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PaymentErrorResponseBody } from '@bigcommerce/checkout-sdk/payment-integration-api';
|
|
1
|
+
import { RequestSender } from '@bigcommerce/request-sender';
|
|
3
2
|
import { Response } from '@bigcommerce/request-sender';
|
|
4
3
|
|
|
5
4
|
declare interface HostedFieldAttachEvent {
|
|
@@ -16,13 +15,13 @@ declare interface HostedFieldAttachEvent {
|
|
|
16
15
|
|
|
17
16
|
declare interface HostedFieldEventMap {
|
|
18
17
|
[HostedFieldEventType.AttachRequested]: HostedFieldAttachEvent;
|
|
19
|
-
[HostedFieldEventType.
|
|
18
|
+
[HostedFieldEventType.SubmitManualOrderRequested]: HostedFieldSubmitManualOrderRequestEvent;
|
|
20
19
|
[HostedFieldEventType.ValidateRequested]: HostedFieldValidateRequestEvent;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
declare enum HostedFieldEventType {
|
|
24
23
|
AttachRequested = "HOSTED_FIELD:ATTACH_REQUESTED",
|
|
25
|
-
|
|
24
|
+
SubmitManualOrderRequested = "HOSTED_FIELD:SUBMIT_MANUAL_ORDER_REQUESTED",
|
|
26
25
|
ValidateRequested = "HOSTED_FIELD:VALIDATE_REQUESTED"
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -34,11 +33,10 @@ declare interface HostedFieldStylesMap {
|
|
|
34
33
|
focus?: HostedFieldStyles;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
declare interface
|
|
38
|
-
type: HostedFieldEventType.
|
|
36
|
+
declare interface HostedFieldSubmitManualOrderRequestEvent {
|
|
37
|
+
type: HostedFieldEventType.SubmitManualOrderRequested;
|
|
39
38
|
payload: {
|
|
40
|
-
data:
|
|
41
|
-
fields: HostedFieldType[];
|
|
39
|
+
data: HostedFormManualOrderData;
|
|
42
40
|
};
|
|
43
41
|
}
|
|
44
42
|
|
|
@@ -63,8 +61,9 @@ declare type HostedFormErrorDataKeys = 'number' | 'expirationDate' | 'expiration
|
|
|
63
61
|
|
|
64
62
|
declare type HostedFormErrorsData = Partial<Record<HostedFormErrorDataKeys, HostedFormErrorData>>;
|
|
65
63
|
|
|
66
|
-
declare interface
|
|
67
|
-
|
|
64
|
+
declare interface HostedFormManualOrderData {
|
|
65
|
+
paymentMethodId: string;
|
|
66
|
+
paymentSessionToken: string;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
declare class HostedInput {
|
|
@@ -79,7 +78,7 @@ declare class HostedInput {
|
|
|
79
78
|
protected _eventPoster: IframeEventPoster<HostedInputEvent>;
|
|
80
79
|
protected _inputAggregator: HostedInputAggregator;
|
|
81
80
|
protected _inputValidator: HostedInputValidator;
|
|
82
|
-
protected
|
|
81
|
+
protected _manualOrderPaymentHandler: HostedInputManualOrderPaymentHandler;
|
|
83
82
|
protected _input: HTMLInputElement;
|
|
84
83
|
protected _previousValue?: string;
|
|
85
84
|
private _fontLinks?;
|
|
@@ -160,7 +159,7 @@ declare interface HostedInputEnterEvent {
|
|
|
160
159
|
};
|
|
161
160
|
}
|
|
162
161
|
|
|
163
|
-
declare type HostedInputEvent = HostedInputAttachSuccessEvent | HostedInputAttachErrorEvent | HostedInputBinChangeEvent | HostedInputBlurEvent | HostedInputChangeEvent | HostedInputCardTypeChangeEvent | HostedInputEnterEvent | HostedInputFocusEvent |
|
|
162
|
+
declare type HostedInputEvent = HostedInputAttachSuccessEvent | HostedInputAttachErrorEvent | HostedInputBinChangeEvent | HostedInputBlurEvent | HostedInputChangeEvent | HostedInputCardTypeChangeEvent | HostedInputEnterEvent | HostedInputFocusEvent | HostedInputSubmitManualOrderSuccessEvent | HostedInputSubmitManualOrderErrorEvent | HostedInputValidateEvent;
|
|
164
163
|
|
|
165
164
|
declare enum HostedInputEventType {
|
|
166
165
|
AttachSucceeded = "HOSTED_INPUT:ATTACH_SUCCEEDED",
|
|
@@ -171,8 +170,8 @@ declare enum HostedInputEventType {
|
|
|
171
170
|
CardTypeChanged = "HOSTED_INPUT:CARD_TYPE_CHANGED",
|
|
172
171
|
Entered = "HOSTED_INPUT:ENTERED",
|
|
173
172
|
Focused = "HOSTED_INPUT:FOCUSED",
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
SubmitManualOrderSucceeded = "HOSTED_INPUT:SUBMIT_MANUAL_ORDER_SUCCEEDED",
|
|
174
|
+
SubmitManualOrderFailed = "HOSTED_INPUT:SUBMIT_MANUAL_ORDER_FAILED",
|
|
176
175
|
Validated = "HOSTED_INPUT:VALIDATED"
|
|
177
176
|
}
|
|
178
177
|
|
|
@@ -188,25 +187,25 @@ declare interface HostedInputInitializeErrorData {
|
|
|
188
187
|
redirectUrl: string;
|
|
189
188
|
}
|
|
190
189
|
|
|
191
|
-
declare
|
|
192
|
-
containerId: string;
|
|
193
|
-
nonce?: string;
|
|
194
|
-
origin: string;
|
|
195
|
-
parentOrigin: string;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
declare class HostedInputPaymentHandler {
|
|
190
|
+
declare class HostedInputManualOrderPaymentHandler {
|
|
199
191
|
private _inputAggregator;
|
|
200
192
|
private _inputValidator;
|
|
201
193
|
private _inputStorage;
|
|
202
194
|
private _eventPoster;
|
|
203
|
-
private
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
handle: (event: HostedFieldSubmitRequestEvent) => Promise<void>;
|
|
195
|
+
private _manualOrderPaymentRequestSender;
|
|
196
|
+
constructor(_inputAggregator: HostedInputAggregator, _inputValidator: HostedInputValidator, _inputStorage: HostedInputStorage, _eventPoster: IframeEventPoster<HostedInputEvent>, _manualOrderPaymentRequestSender: ManualOrderPaymentRequestSender);
|
|
197
|
+
handle: (event: HostedFieldSubmitManualOrderRequestEvent) => Promise<void>;
|
|
207
198
|
private _isPaymentErrorResponse;
|
|
208
199
|
}
|
|
209
200
|
|
|
201
|
+
declare interface HostedInputOptions {
|
|
202
|
+
containerId: string;
|
|
203
|
+
nonce?: string;
|
|
204
|
+
origin: string;
|
|
205
|
+
parentOrigin: string;
|
|
206
|
+
paymentOrigin: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
210
209
|
declare class HostedInputStorage {
|
|
211
210
|
private _nonce?;
|
|
212
211
|
setNonce(nonce: string): void;
|
|
@@ -221,19 +220,16 @@ declare interface HostedInputStylesMap {
|
|
|
221
220
|
focus?: HostedInputStyles;
|
|
222
221
|
}
|
|
223
222
|
|
|
224
|
-
declare interface
|
|
225
|
-
type: HostedInputEventType.
|
|
223
|
+
declare interface HostedInputSubmitManualOrderErrorEvent {
|
|
224
|
+
type: HostedInputEventType.SubmitManualOrderFailed;
|
|
226
225
|
payload: {
|
|
227
226
|
error: PaymentErrorData;
|
|
228
227
|
response?: Response<PaymentErrorResponseBody>;
|
|
229
228
|
};
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
declare interface
|
|
233
|
-
type: HostedInputEventType.
|
|
234
|
-
payload: {
|
|
235
|
-
response: Response<unknown>;
|
|
236
|
-
};
|
|
231
|
+
declare interface HostedInputSubmitManualOrderSuccessEvent {
|
|
232
|
+
type: HostedInputEventType.SubmitManualOrderSucceeded;
|
|
237
233
|
}
|
|
238
234
|
|
|
239
235
|
declare interface HostedInputValidateErrorData {
|
|
@@ -315,29 +311,21 @@ declare class IframeEventPoster<TEvent, TContext = undefined> {
|
|
|
315
311
|
setContext(context: TContext): void;
|
|
316
312
|
}
|
|
317
313
|
|
|
318
|
-
declare
|
|
319
|
-
|
|
314
|
+
declare class ManualOrderPaymentRequestSender {
|
|
315
|
+
private _requestSender;
|
|
316
|
+
private _paymentOrigin;
|
|
317
|
+
constructor(_requestSender: RequestSender, _paymentOrigin: string);
|
|
318
|
+
submitPayment(requestInitializationData: HostedFormManualOrderData, instrumentFormData: HostedInputValues, nonce?: string): Promise<void>;
|
|
320
319
|
}
|
|
321
320
|
|
|
322
|
-
declare
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
* @class
|
|
326
|
-
* @param {BigpayClient} client
|
|
327
|
-
*/
|
|
328
|
-
constructor(_client: any);
|
|
329
|
-
submitPayment(payload: PaymentRequestBody): Promise<Response<any>>;
|
|
330
|
-
initializeOffsitePayment(payload: PaymentRequestBody, target?: string): Promise<void>;
|
|
331
|
-
private _transformResponse;
|
|
321
|
+
declare interface PaymentErrorData {
|
|
322
|
+
code: string;
|
|
323
|
+
message?: string;
|
|
332
324
|
}
|
|
333
325
|
|
|
334
|
-
declare
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
authToken: string;
|
|
338
|
-
values: HostedInputValues;
|
|
339
|
-
nonce: string;
|
|
340
|
-
};
|
|
326
|
+
declare interface PaymentErrorResponseBody {
|
|
327
|
+
status: string;
|
|
328
|
+
errors: PaymentErrorData[];
|
|
341
329
|
}
|
|
342
330
|
|
|
343
331
|
export declare function initializeHostedInput(options: HostedInputOptions): Promise<HostedInput>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{initializeHostedInput:()=>j,notifyInitializeError:()=>z});const n=require("tslib"),r=function(t){function e(e){var n,r,i=this.constructor,o=t.call(this,e||"An unexpected error has occurred.")||this;return o.name="StandardError",o.type="standard",n=o,r=i.prototype,Object.setPrototypeOf?Object.setPrototypeOf(n,r):n.__proto__=r,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(o,i):o.stack=new Error(o.message).stack,o}return(0,n.__extends)(e,t),e}(Error),i=function(t){function e(e){var n=t.call(this,e||"Invalid arguments have been provided.")||this;return n.name="InvalidArgumentError",n.type="invalid_argument",n}return(0,n.__extends)(e,t),e}(r);function o(t){if(!/^(https?:)?\/\//.test(t))throw new i("The provided URL must be absolute.");var e=document.createElement("a");e.href=t;var n=e.port&&-1!==t.indexOf(e.hostname+":"+e.port)?e.port:"";return{hash:e.hash,hostname:e.hostname,href:e.href,origin:e.protocol+"//"+e.hostname+(n?":"+n:""),pathname:e.pathname,port:n,protocol:e.protocol,search:e.search}}function a(t){return o(0===t.hostname.indexOf("www")?t.href:t.href.replace(t.hostname,"www."+t.hostname))}const s=function(t,e,r){return e&&r?u(0,e,r):function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return(0,n.__extends)(e,t),e}(t);return Object.getOwnPropertyNames(t.prototype).forEach((function(n){var r=Object.getOwnPropertyDescriptor(t.prototype,n);r&&"constructor"!==n&&Object.defineProperty(e.prototype,n,u(t.prototype,n,r))})),e}(t)};function u(t,e,r){if("function"!=typeof r.value)return r;var i=r.value;return{get:function(){var t=i.bind(this);return Object.defineProperty(this,e,(0,n.__assign)((0,n.__assign)({},r),{value:t})),t},set:function(t){i=t}}}function p(t,e){return t.type===e}const c=function(){function t(t){this._sourceOrigins=[o(t).origin,a(o(t)).origin],this._isListening=!1,this._listeners={}}return t.prototype.listen=function(){this._isListening||(this._isListening=!0,window.addEventListener("message",this._handleMessage))},t.prototype.stopListen=function(){this._isListening&&(this._isListening=!1,window.removeEventListener("message",this._handleMessage))},t.prototype.addListener=function(t,e){var n=this._listeners[t];n||(this._listeners[t]=n=[]),-1===n.indexOf(e)&&n.push(e)},t.prototype.removeListener=function(t,e){var n=this._listeners[t];if(n){var r=n.indexOf(e);r>=0&&n.splice(r,1)}},t.prototype.trigger=function(t,e){var n=this._listeners[t.type];n&&n.forEach((function(n){return e?n(t,e):n(t)}))},t.prototype._handleMessage=function(t){if(-1!==this._sourceOrigins.indexOf(t.origin)&&p(t.data,t.data.type)){var e=t.data,r=e.context,i=(0,n.__rest)(e,["context"]);this.trigger(i,r)}},(0,n.__decorate)([s],t.prototype,"_handleMessage",null),t}(),d=function(){function t(){}return t.prototype.setNonce=function(t){this._nonce=t},t.prototype.getNonce=function(){return this._nonce},t}();var h;function l(){return h=h||new d}const _=require("@bigcommerce/bigpay-client"),f=require("rxjs"),y=require("rxjs/operators"),m=function(){function t(t,e,n){this._targetWindow=e,this._context=n,this._targetOrigin="*"===t?"*":o(t).origin}return t.prototype.post=function(t,e){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 o=e&&(0,f.fromEvent)(window,"message").pipe((0,y.filter)((function(t){return t.origin===r._targetOrigin&&p(t.data,t.data.type)&&-1!==[e.successType,e.errorType].indexOf(t.data.type)})),(0,y.map)((function(t){if(e.errorType===t.data.type)throw t.data;return t.data})),(0,y.take)(1)).toPromise();return i.postMessage((0,n.__assign)((0,n.__assign)({},t),{context:this._context}),this._targetOrigin),o}},t.prototype.setTarget=function(t){this._targetWindow=t},t.prototype.setContext=function(t){this._context=t},t}();var g;!function(t){t.CardCode="cardCode",t.CardExpiry="cardExpiry",t.CardName="cardName",t.CardNumber="cardNumber"}(g||(g={}));const v=g;var E=function(){function t(t){this._client=t}return t.prototype.submitPayment=function(t){var e=this;return new Promise((function(n,r){e._client.submitPayment(t,(function(t,i){t?r(e._transformResponse(t)):n(e._transformResponse(i))}))}))},t.prototype.initializeOffsitePayment=function(t,e){var n=this;return new Promise((function(){n._client.initializeOffsitePayment(t,null,e)}))},t.prototype._transformResponse=function(t){return{headers:t.headers,body:t.data,status:t.status,statusText:t.statusText}},t}(),w=function(){function t(){}return t.prototype.transform=function(){return{}},t.prototype.transformWithHostedFormData=function(t,e,n){return{authToken:e.authToken,values:t,nonce:n}},t}();const b=function(){function t(){}return t.prototype.format=function(t){var e=t.split(new RegExp("\\s*/\\s*")),n=e[0],r=void 0===n?"":n,i=e[1],o=void 0===i?"":i,a=r.slice(0,2),s=4===o.length?o.slice(-2):o?o.slice(0,2):r.slice(2);return t.length<2?r:t.length>3&&!s?a:a+" / "+s},t.prototype.toObject=function(t){var e=t.split(new RegExp("\\s*/\\s*")),n=e[0],r=void 0===n?"":n,i=e[1],o=void 0===i?"":i;return/^\d+$/.test(r)&&/^\d+$/.test(o)?{month:1===r.length?"0"+r:r.slice(0,2),year:2===o.length?"20"+o:o.slice(0,4)}:{month:"",year:""}},t}(),C=require("card-validator"),T=require("lodash"),S=function(){function t(){}return t.prototype.format=function(t){var e=(0,C.number)(t).card;if(!e)return t;var n=(0,T.max)((0,C.creditCardType)(t).map((function(t){return(0,T.max)(t.lengths)}))),r=this.unformat(t).slice(0,n);return e.gaps.filter((function(t){return r.length>t})).reduce((function(t,e,n){return[t.slice(0,e+n),t.slice(e+n)].join(" ")}),r)},t.prototype.unformat=function(t){return(0,C.number)(t).card?t.replace(new RegExp(" ","g"),""):t},t}();function O(t){switch(t){case v.CardCode:return"cc-csc";case v.CardExpiry:return"cc-exp";case v.CardName:return"cc-name";case v.CardNumber:return"cc-number";default:return""}}const I=function(){function t(t,e,n){var r=this;this._form=t,this._fieldTypes=e,this._inputAggregator=n,this._handleChange=function(t){var e=t.target;if(!e)throw new Error("Unable to get a reference to the target of the change event.");var n=r._inputAggregator.getInputs().find((function(t){return r._getAutocompleteElementId(t.getType())===e.id}));n&&n.setValue(e.value)},this._inputs=this._fieldTypes.map((function(t){return r._createInput(t)}))}return t.prototype.attach=function(){var t=this;this._inputs.forEach((function(e){return t._form.appendChild(e)}))},t.prototype.detach=function(){this._inputs.forEach((function(t){t.parentElement&&t.parentElement.removeChild(t)}))},t.prototype._createInput=function(t){var e=document.createElement("input");return e.autocomplete=O(t),e.id=this._getAutocompleteElementId(t),e.tabIndex=-1,e.style.position="absolute",e.style.opacity="0",e.style.zIndex="-1",e.addEventListener("change",this._handleChange),e},t.prototype._getAutocompleteElementId=function(t){return"autocomplete-"+(0,T.kebabCase)(t)},t}();var P,x;!function(t){t.AttachRequested="HOSTED_FIELD:ATTACH_REQUESTED",t.SubmitRequested="HOSTED_FIELD:SUBMITTED_REQUESTED",t.ValidateRequested="HOSTED_FIELD:VALIDATE_REQUESTED"}(P||(P={})),function(t){t.AttachSucceeded="HOSTED_INPUT:ATTACH_SUCCEEDED",t.AttachFailed="HOSTED_INPUT:ATTACH_FAILED",t.BinChanged="HOSTED_INPUT:BIN_CHANGED",t.Blurred="HOSTED_INPUT:BLURRED",t.Changed="HOSTED_INPUT:CHANGED",t.CardTypeChanged="HOSTED_INPUT:CARD_TYPE_CHANGED",t.Entered="HOSTED_INPUT:ENTERED",t.Focused="HOSTED_INPUT:FOCUSED",t.SubmitSucceeded="HOSTED_INPUT:SUBMIT_SUCCEEDED",t.SubmitFailed="HOSTED_INPUT:SUBMIT_FAILED",t.Validated="HOSTED_INPUT:VALIDATED"}(x||(x={}));const V=function(){function t(t,e,n,r,i,o,a,s,u,p,c,d){var h=this;this._type=t,this._form=e,this._placeholder=n,this._accessibilityLabel=r,this._autocomplete=i,this._styles=o,this._fontUrls=a,this._eventListener=s,this._eventPoster=u,this._inputAggregator=p,this._inputValidator=c,this._paymentHandler=d,this._isTouched=!1,this._handleInput=function(t){var e=t.target;h._processChange(e.value)},this._handleBlur=function(){h._applyStyles(h._styles.default),h._validateForm(),h._eventPoster.post({type:x.Blurred,payload:{fieldType:h._type}})},this._handleFocus=function(){h._applyStyles(h._styles.focus),h._eventPoster.post({type:x.Focused,payload:{fieldType:h._type}})},this._handleValidate=function(){h._validateForm()},this._handleSubmit=function(t){t.preventDefault(),h._eventPoster.post({type:x.Entered,payload:{fieldType:h._type}})},this._forceFocusToInput=function(){document.activeElement===document.body&&(navigator.userAgent.toLowerCase().indexOf("safari")>-1?""===h._input.value&&(h._input.setAttribute("value"," "),h._input.setSelectionRange(0,1),h._input.setAttribute("value","")):h._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(P.ValidateRequested,this._handleValidate),this._eventListener.addListener(P.SubmitRequested,this._paymentHandler.handle),this._configureInput()}return t.prototype.getType=function(){return this._type},t.prototype.getValue=function(){return this._input.value},t.prototype.setValue=function(t){this._processChange(t)},t.prototype.isTouched=function(){return this._isTouched},t.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:x.AttachSucceeded})},t.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()},t.prototype._formatValue=function(t){this._input.value=t},t.prototype._notifyChange=function(t){this._eventPoster.post({type:x.Changed,payload:{fieldType:this._type}})},t.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,T.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"}},t.prototype._applyStyles=function(t){var e=this;void 0===t&&(t={});var n={color:t.color,fontFamily:t.fontFamily,fontSize:t.fontSize,fontWeight:t.fontWeight};Object.keys(n).forEach((function(t){n[t]&&(e._input.style[t]=n[t]||"")}))},t.prototype._loadFonts=function(){this._fontLinks||(this._fontLinks=this._fontUrls.filter((function(t){return"fonts.googleapis.com"===o(t).hostname})).filter((function(t){return!document.querySelector("link[href='"+t+"'][rel='stylesheet']")})).map((function(t){var e=document.createElement("link");return e.rel="stylesheet",e.href=t,document.head.appendChild(e),e})))},t.prototype._unloadFonts=function(){this._fontLinks&&(this._fontLinks.forEach((function(t){t.parentElement&&t.parentElement.removeChild(t)})),this._fontLinks=void 0)},t.prototype._validateForm=function(){return(0,n.__awaiter)(this,void 0,void 0,(function(){var t,e;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return t=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(t)];case 1:return(e=n.sent()).isValid?this._applyStyles(this._styles.default):this._applyStyles(this._styles.error),this._eventPoster.post({type:x.Validated,payload:e}),[2]}}))}))},t.prototype._processChange=function(t){t!==this._previousValue&&(this._isTouched=!0,this._formatValue(t),this._validateForm(),this._notifyChange(t),this._previousValue=t)},t}(),L=function(t){function e(e,n,r,i,o,a,s,u,p,c,d,h){var l=t.call(this,v.CardExpiry,e,n,r,i,o,a,s,u,p,c,d)||this;return l._formatter=h,l}return(0,n.__extends)(e,t),e.prototype._formatValue=function(t){this._input.value=this._formatter.format(t)},e}(V),D=function(t){function e(e,n,r,i,o,a,s,u,p,c,d,h,l,_){var f=t.call(this,e,n,r,i,o,a,s,u,p,c,d,h)||this;return f._autocompleteFieldset=l,f._formatter=_,f}return(0,n.__extends)(e,t),e.prototype.attach=function(){t.prototype.attach.call(this),this._autocompleteFieldset.attach()},e.prototype._notifyChange=function(t){var e=(0,C.number)(t).card,n=this._previousValue&&(0,C.number)(this._previousValue).card;(0,T.get)(n,"type")!==(0,T.get)(e,"type")&&this._eventPoster.post({type:x.CardTypeChanged,payload:{cardType:e?e.type:void 0}});var r=this._formatter.unformat(t),i=this._previousValue?this._formatter.unformat(this._previousValue):"",o=r.length>=6&&(0,C.number)(r).isPotentiallyValid?r.substr(0,6):"";o!==(i.length>=6?i.substr(0,6):"")&&this._eventPoster.post({type:x.BinChanged,payload:{bin:o}})},e.prototype._formatValue=function(t){var e=this._input.selectionEnd,n=this._formatter.format(t);e===t.length&&t.length<n.length?this._input.setSelectionRange(n.length,n.length):this._input.setSelectionRange(e||0,e||0),this._input.value=n},e}(V),A=function(){function t(t){this._parentWindow=t}return t.prototype.getInputs=function(t){return Array.prototype.slice.call(this._parentWindow.frames).reduce((function(e,r){try{var i=r.hostedInput;return!i||t&&!t(i)?e:(0,n.__spreadArrays)(e,[i])}catch(t){if(t instanceof DOMException)return e;if(t instanceof Error&&"Permission denied"===t.message)return e;throw t}}),[])},t.prototype.getInputValues=function(t){return this.getInputs(t).reduce((function(t,e){var r;return(0,n.__assign)((0,n.__assign)({},t),((r={})[e.getType()]=e.getValue(),r))}),{})},t}(),N=function(t){function e(e){var r=t.call(this,(0,n.__spreadArrays)(["Unable to proceed due to invalid user input values"],(0,T.flatMap)((0,T.values)(e),(function(t){return(0,T.map)(t,(function(t){return t.message}))}))).join(". "))||this;return r.errors=e,r.name="InvalidHostedFormValueError",r.type="invalid_hosted_form_value",r}return(0,n.__extends)(e,t),e}(r),F=function(){function t(t,e,r,i,o,a){var s=this;this._inputAggregator=t,this._inputValidator=e,this._inputStorage=r,this._eventPoster=i,this._paymentRequestSender=o,this._paymentRequestTransformer=a,this.handle=function(t){var e=t.payload.data;return(0,n.__awaiter)(s,void 0,void 0,(function(){var t,r,i,o,a;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return t=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(t)];case 1:if(r=n.sent(),this._eventPoster.post({type:x.Validated,payload:r}),!r.isValid)return i=new N(r.errors),[2,this._eventPoster.post({type:x.SubmitFailed,payload:{error:{code:(0,T.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(t,e,this._inputStorage.getNonce()||""))];case 3:return o=n.sent(),this._eventPoster.post({type:x.SubmitSucceeded,payload:{response:o}}),[3,5];case 4:return a=n.sent(),this._eventPoster.post({type:x.SubmitFailed,payload:this._isPaymentErrorResponse(a)?{error:a.body.errors[0],response:a}:{error:{code:(0,T.snakeCase)(a.name),message:a.message}}}),[3,5];case 5:return[2]}}))}))}}return t.prototype._isPaymentErrorResponse=function(t){var e=(t||{}).body,n=(void 0===e?{}:e).errors,r=void 0===n?[]:n;return"string"==typeof(r[0]&&r[0].code)&&"string"==typeof(r[0]&&r[0].message)},t}(),H=require("yup"),U=function(){function t(){this._completeSchema={cardCode:this._getCardCodeSchema(),cardExpiry:this._getCardExpirySchema(),cardName:this._getCardNameSchema(),cardNumber:this._getCardNumberSchema()},this._configureCardValidator()}return t.prototype.validate=function(t){return(0,n.__awaiter)(this,void 0,void 0,(function(){var e,r,i,o;return(0,n.__generator)(this,(function(a){switch(a.label){case 0:for(i in e={},r={errors:{},isValid:!0},t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=this._completeSchema[i],r.errors[i]=[]);a.label=1;case 1:return a.trys.push([1,3,,4]),[4,(0,H.object)(e).validate(t,{abortEarly:!1})];case 2:return a.sent(),[2,r];case 3:if("ValidationError"!==(o=a.sent()).name)throw o;return[2,{errors:Object.keys(r.errors).reduce((function(t,e){var r;return(0,n.__assign)((0,n.__assign)({},t),((r={})[e]=o.inner.filter((function(t){return t.path===e})).map((function(t){return{fieldType:t.path,message:t.errors.join(" "),type:t.type}})),r))}),{}),isValid:!1}];case 4:return[2]}}))}))},t.prototype._configureCardValidator=function(){var t=C.creditCardType.getTypeInfo("discover"),e=C.creditCardType.getTypeInfo("visa");C.creditCardType.updateCard("visa",{lengths:(0,n.__spreadArrays)([13],e.lengths||[])}),C.creditCardType.updateCard("discover",{patterns:(0,n.__spreadArrays)(t.patterns||[],[[810,817]])}),C.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}})},t.prototype._getCardCodeSchema=function(){return(0,H.string)().required("CVV is required").test({message:"CVV must be valid",name:"invalid_card_code",test:function(t){var e=(0,C.number)(this.parent.cardNumber||"").card;return(0,C.cvv)(t,e&&e.code?e.code.size:void 0).isValid}})},t.prototype._getCardExpirySchema=function(){return(0,H.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(t){return(0,C.expirationDate)(t).isValid}})},t.prototype._getCardNameSchema=function(){return(0,H.string)().max(200).required("Full name is required")},t.prototype._getCardNumberSchema=function(){return(0,H.string)().required("Credit card number is required").test({message:"Credit card number must be valid",name:"invalid_card_number",test:function(t){return(0,C.number)(t).isValid}})},t}(),R=function(){function t(t){this._parentOrigin=t}return t.prototype.create=function(t,e,n,r,i,o){void 0===n&&(n={}),void 0===r&&(r=[]),void 0===i&&(i=""),void 0===o&&(o=function(t){switch(t){case v.CardCode:return"CVC";case v.CardExpiry:return"Expiration";case v.CardName:return"Name on card";case v.CardNumber:return"Credit card number"}}(e));var a=O(e);return e===v.CardNumber?this._createNumberInput(e,t,n,r,i,o,a):e===v.CardExpiry?this._createExpiryInput(t,n,r,i,o,a):this._createInput(e,t,n,r,i,o,a)},t.prototype.normalizeParentOrigin=function(t){this._parentOrigin!==t&&(this._parentOrigin!==a(o(t)).origin&&t!==a(o(this._parentOrigin)).origin||(this._parentOrigin=t))},t.prototype.getParentOrigin=function(){return this._parentOrigin},t.prototype._createExpiryInput=function(t,e,n,r,i,o){return void 0===i&&(i=""),void 0===o&&(o=""),new L(t,r,i,o,e,n,new c(this._parentOrigin),new m(this._parentOrigin,window.parent),new A(window.parent),new U,this._createPaymentHandler(),new b)},t.prototype._createNumberInput=function(t,e,n,r,i,o,a){return void 0===o&&(o=""),void 0===a&&(a=""),new D(t,e,i,o,a,n,r,new c(this._parentOrigin),new m(this._parentOrigin,window.parent),new A(window.parent),new U,this._createPaymentHandler(),new I(e,[v.CardCode,v.CardExpiry,v.CardName],new A(window.parent)),new S)},t.prototype._createInput=function(t,e,n,r,i,o,a){return void 0===o&&(o=""),void 0===a&&(a=""),new V(t,e,i,o,a,n,r,new c(this._parentOrigin),new m(this._parentOrigin,window.parent),new A(window.parent),new U,this._createPaymentHandler())},t.prototype._createPaymentHandler=function(){return new F(new A(window.parent),new U,l(),new m(this._parentOrigin,window.parent),new E((0,_.createClient)()),new w)},t}(),q=function(t){function e(e){var n=t.call(this,e||"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)(e,t),e}(r),k=function(){function t(t,e,n){this._factory=t,this._storage=e,this._eventListener=n}return t.prototype.initialize=function(t,e){var n=this;e&&this._storage.setNonce(e);var r=this._createFormContainer(t);return this._resetPageStyles(t),this._eventListener.listen(),(0,f.fromEvent)(this._eventListener,P.AttachRequested).pipe((0,y.map)((function(t){var e=t.payload,i=e.accessibilityLabel,o=e.fontUrls,a=e.placeholder,s=e.styles,u=e.origin,p=e.type;u&&n._factory.normalizeParentOrigin(u);var c=n._factory.create(r,p,s,o,a,i);return c.attach(),c})),(0,y.take)(1)).toPromise()},t.prototype._resetPageStyles=function(t){[document.querySelector("html"),document.querySelector("body"),document.getElementById(t)].forEach((function(t){t&&(t.style.height="100%",t.style.width="100%",t.style.overflow="hidden",t.style.padding="0",t.style.margin="0")}))},t.prototype._createFormContainer=function(t){var e=document.getElementById(t);if(!e)throw new q("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",e.appendChild(n),n.appendChild(r),n},t}();function j(t){var e=t.containerId,n=t.nonce,r=t.parentOrigin;return new k(new R(r),l(),new c(r)).initialize(e,n)}var M=new m("*",window.parent);function z(t){M.post({type:x.AttachFailed,payload:{error:t}})}module.exports=e})();
|
|
1
|
+
(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{initializeHostedInput:()=>j,notifyInitializeError:()=>z});const n=require("tslib"),r=function(t){function e(e){var n,r,i=this.constructor,o=t.call(this,e||"An unexpected error has occurred.")||this;return o.name="StandardError",o.type="standard",n=o,r=i.prototype,Object.setPrototypeOf?Object.setPrototypeOf(n,r):n.__proto__=r,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(o,i):o.stack=new Error(o.message).stack,o}return(0,n.__extends)(e,t),e}(Error),i=function(t){function e(e){var n=t.call(this,e||"Invalid arguments have been provided.")||this;return n.name="InvalidArgumentError",n.type="invalid_argument",n}return(0,n.__extends)(e,t),e}(r);function o(t){if(!/^(https?:)?\/\//.test(t))throw new i("The provided URL must be absolute.");var e=document.createElement("a");e.href=t;var n=e.port&&-1!==t.indexOf(e.hostname+":"+e.port)?e.port:"";return{hash:e.hash,hostname:e.hostname,href:e.href,origin:e.protocol+"//"+e.hostname+(n?":"+n:""),pathname:e.pathname,port:n,protocol:e.protocol,search:e.search}}function a(t){return o(0===t.hostname.indexOf("www")?t.href:t.href.replace(t.hostname,"www."+t.hostname))}const s=function(t,e,r){return e&&r?u(0,e,r):function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return(0,n.__extends)(e,t),e}(t);return Object.getOwnPropertyNames(t.prototype).forEach((function(n){var r=Object.getOwnPropertyDescriptor(t.prototype,n);r&&"constructor"!==n&&Object.defineProperty(e.prototype,n,u(t.prototype,n,r))})),e}(t)};function u(t,e,r){if("function"!=typeof r.value)return r;var i=r.value;return{get:function(){var t=i.bind(this);return Object.defineProperty(this,e,(0,n.__assign)((0,n.__assign)({},r),{value:t})),t},set:function(t){i=t}}}function p(t,e){return t.type===e}const c=function(){function t(t){this._sourceOrigins=[o(t).origin,a(o(t)).origin],this._isListening=!1,this._listeners={}}return t.prototype.listen=function(){this._isListening||(this._isListening=!0,window.addEventListener("message",this._handleMessage))},t.prototype.stopListen=function(){this._isListening&&(this._isListening=!1,window.removeEventListener("message",this._handleMessage))},t.prototype.addListener=function(t,e){var n=this._listeners[t];n||(this._listeners[t]=n=[]),-1===n.indexOf(e)&&n.push(e)},t.prototype.removeListener=function(t,e){var n=this._listeners[t];if(n){var r=n.indexOf(e);r>=0&&n.splice(r,1)}},t.prototype.trigger=function(t,e){var n=this._listeners[t.type];n&&n.forEach((function(n){return e?n(t,e):n(t)}))},t.prototype._handleMessage=function(t){if(-1!==this._sourceOrigins.indexOf(t.origin)&&p(t.data,t.data.type)){var e=t.data,r=e.context,i=(0,n.__rest)(e,["context"]);this.trigger(i,r)}},(0,n.__decorate)([s],t.prototype,"_handleMessage",null),t}(),d=function(){function t(){}return t.prototype.setNonce=function(t){this._nonce=t},t.prototype.getNonce=function(){return this._nonce},t}();var h;function l(){return h=h||new d}const _=require("@bigcommerce/request-sender"),f=require("rxjs"),y=require("rxjs/operators"),m=function(){function t(t,e,n){this._targetWindow=e,this._context=n,this._targetOrigin="*"===t?"*":o(t).origin}return t.prototype.post=function(t,e){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 o=e&&(0,f.fromEvent)(window,"message").pipe((0,y.filter)((function(t){return t.origin===r._targetOrigin&&p(t.data,t.data.type)&&-1!==[e.successType,e.errorType].indexOf(t.data.type)})),(0,y.map)((function(t){if(e.errorType===t.data.type)throw t.data;return t.data})),(0,y.take)(1)).toPromise();return i.postMessage((0,n.__assign)((0,n.__assign)({},t),{context:this._context}),this._targetOrigin),o}},t.prototype.setTarget=function(t){this._targetWindow=t},t.prototype.setContext=function(t){this._context=t},t}();var g;!function(t){t.CardCode="cardCode",t.CardExpiry="cardExpiry",t.CardName="cardName",t.CardNumber="cardNumber"}(g||(g={}));const v=g;var E;!function(t){t.Json="application/json",t.JsonV1="application/vnd.bc.v1+json"}(E||(E={}));const b=E;var w=function(){function t(t,e){this._requestSender=t,this._paymentOrigin=e}return t.prototype.submitPayment=function(t,e,r){var i,o;return(0,n.__awaiter)(this,void 0,void 0,(function(){var a,s,u,p,c,d;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return a=t.paymentMethodId,s=t.paymentSessionToken,u=e.cardExpiry?e.cardExpiry.split("/"):[],p=u[0],c=u[1],d={headers:{Accept:b.Json,"Content-Type":b.Json,"X-Payment-Session-Token":s},body:{instrument:{type:"card",name:null!==(i=e.cardName)&&void 0!==i?i:"",number:e.cardNumber?e.cardNumber.replace(/ /g,""):"",expires:{month:Number(p.trim()),year:Number("20"+c.trim())},verification_value:null!==(o=e.cardCode)&&void 0!==o?o:void 0},payment_method_id:a,form_nonce:null!=r?r:void 0}},[4,this._requestSender.post(this._paymentOrigin+"/payments",d)];case 1:return n.sent(),[2]}}))}))},t}();const C=function(){function t(){}return t.prototype.format=function(t){var e=t.split(new RegExp("\\s*/\\s*")),n=e[0],r=void 0===n?"":n,i=e[1],o=void 0===i?"":i,a=r.slice(0,2),s=4===o.length?o.slice(-2):o?o.slice(0,2):r.slice(2);return t.length<2?r:t.length>3&&!s?a:a+" / "+s},t.prototype.toObject=function(t){var e=t.split(new RegExp("\\s*/\\s*")),n=e[0],r=void 0===n?"":n,i=e[1],o=void 0===i?"":i;return/^\d+$/.test(r)&&/^\d+$/.test(o)?{month:1===r.length?"0"+r:r.slice(0,2),year:2===o.length?"20"+o:o.slice(0,4)}:{month:"",year:""}},t}(),O=require("card-validator"),T=require("lodash"),S=function(){function t(){}return t.prototype.format=function(t){var e=(0,O.number)(t).card;if(!e)return t;var n=(0,T.max)((0,O.creditCardType)(t).map((function(t){return(0,T.max)(t.lengths)}))),r=this.unformat(t).slice(0,n);return e.gaps.filter((function(t){return r.length>t})).reduce((function(t,e,n){return[t.slice(0,e+n),t.slice(e+n)].join(" ")}),r)},t.prototype.unformat=function(t){return(0,O.number)(t).card?t.replace(new RegExp(" ","g"),""):t},t}();function I(t){switch(t){case v.CardCode:return"cc-csc";case v.CardExpiry:return"cc-exp";case v.CardName:return"cc-name";case v.CardNumber:return"cc-number";default:return""}}const P=function(){function t(t,e,n){var r=this;this._form=t,this._fieldTypes=e,this._inputAggregator=n,this._handleChange=function(t){var e=t.target;if(!e)throw new Error("Unable to get a reference to the target of the change event.");var n=r._inputAggregator.getInputs().find((function(t){return r._getAutocompleteElementId(t.getType())===e.id}));n&&n.setValue(e.value)},this._inputs=this._fieldTypes.map((function(t){return r._createInput(t)}))}return t.prototype.attach=function(){var t=this;this._inputs.forEach((function(e){return t._form.appendChild(e)}))},t.prototype.detach=function(){this._inputs.forEach((function(t){t.parentElement&&t.parentElement.removeChild(t)}))},t.prototype._createInput=function(t){var e=document.createElement("input");return e.autocomplete=I(t),e.id=this._getAutocompleteElementId(t),e.tabIndex=-1,e.style.position="absolute",e.style.opacity="0",e.style.zIndex="-1",e.addEventListener("change",this._handleChange),e},t.prototype._getAutocompleteElementId=function(t){return"autocomplete-"+(0,T.kebabCase)(t)},t}();var x,V;!function(t){t.AttachRequested="HOSTED_FIELD:ATTACH_REQUESTED",t.SubmitManualOrderRequested="HOSTED_FIELD:SUBMIT_MANUAL_ORDER_REQUESTED",t.ValidateRequested="HOSTED_FIELD:VALIDATE_REQUESTED"}(x||(x={})),function(t){t.AttachSucceeded="HOSTED_INPUT:ATTACH_SUCCEEDED",t.AttachFailed="HOSTED_INPUT:ATTACH_FAILED",t.BinChanged="HOSTED_INPUT:BIN_CHANGED",t.Blurred="HOSTED_INPUT:BLURRED",t.Changed="HOSTED_INPUT:CHANGED",t.CardTypeChanged="HOSTED_INPUT:CARD_TYPE_CHANGED",t.Entered="HOSTED_INPUT:ENTERED",t.Focused="HOSTED_INPUT:FOCUSED",t.SubmitManualOrderSucceeded="HOSTED_INPUT:SUBMIT_MANUAL_ORDER_SUCCEEDED",t.SubmitManualOrderFailed="HOSTED_INPUT:SUBMIT_MANUAL_ORDER_FAILED",t.Validated="HOSTED_INPUT:VALIDATED"}(V||(V={}));const L=function(){function t(t,e,n,r,i,o,a,s,u,p,c,d){var h=this;this._type=t,this._form=e,this._placeholder=n,this._accessibilityLabel=r,this._autocomplete=i,this._styles=o,this._fontUrls=a,this._eventListener=s,this._eventPoster=u,this._inputAggregator=p,this._inputValidator=c,this._manualOrderPaymentHandler=d,this._isTouched=!1,this._handleInput=function(t){var e=t.target;h._processChange(e.value)},this._handleBlur=function(){h._applyStyles(h._styles.default),h._validateForm(),h._eventPoster.post({type:V.Blurred,payload:{fieldType:h._type}})},this._handleFocus=function(){h._applyStyles(h._styles.focus),h._eventPoster.post({type:V.Focused,payload:{fieldType:h._type}})},this._handleValidate=function(){h._validateForm()},this._handleSubmit=function(t){t.preventDefault(),h._eventPoster.post({type:V.Entered,payload:{fieldType:h._type}})},this._forceFocusToInput=function(){document.activeElement===document.body&&(navigator.userAgent.toLowerCase().indexOf("safari")>-1?""===h._input.value&&(h._input.setAttribute("value"," "),h._input.setSelectionRange(0,1),h._input.setAttribute("value","")):h._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(x.ValidateRequested,this._handleValidate),this._eventListener.addListener(x.SubmitManualOrderRequested,this._manualOrderPaymentHandler.handle),this._configureInput()}return t.prototype.getType=function(){return this._type},t.prototype.getValue=function(){return this._input.value},t.prototype.setValue=function(t){this._processChange(t)},t.prototype.isTouched=function(){return this._isTouched},t.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:V.AttachSucceeded})},t.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()},t.prototype._formatValue=function(t){this._input.value=t},t.prototype._notifyChange=function(t){this._eventPoster.post({type:V.Changed,payload:{fieldType:this._type}})},t.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,T.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"}},t.prototype._applyStyles=function(t){var e=this;void 0===t&&(t={});var n={color:t.color,fontFamily:t.fontFamily,fontSize:t.fontSize,fontWeight:t.fontWeight};Object.keys(n).forEach((function(t){n[t]&&(e._input.style[t]=n[t]||"")}))},t.prototype._loadFonts=function(){this._fontLinks||(this._fontLinks=this._fontUrls.filter((function(t){return"fonts.googleapis.com"===o(t).hostname})).filter((function(t){return!document.querySelector("link[href='"+t+"'][rel='stylesheet']")})).map((function(t){var e=document.createElement("link");return e.rel="stylesheet",e.href=t,document.head.appendChild(e),e})))},t.prototype._unloadFonts=function(){this._fontLinks&&(this._fontLinks.forEach((function(t){t.parentElement&&t.parentElement.removeChild(t)})),this._fontLinks=void 0)},t.prototype._validateForm=function(){return(0,n.__awaiter)(this,void 0,void 0,(function(){var t,e;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return t=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(t)];case 1:return(e=n.sent()).isValid?this._applyStyles(this._styles.default):this._applyStyles(this._styles.error),this._eventPoster.post({type:V.Validated,payload:e}),[2]}}))}))},t.prototype._processChange=function(t){t!==this._previousValue&&(this._isTouched=!0,this._formatValue(t),this._validateForm(),this._notifyChange(t),this._previousValue=t)},t}(),A=function(t){function e(e,n,r,i,o,a,s,u,p,c,d,h){var l=t.call(this,v.CardExpiry,e,n,r,i,o,a,s,u,p,c,d)||this;return l._formatter=h,l}return(0,n.__extends)(e,t),e.prototype._formatValue=function(t){this._input.value=this._formatter.format(t)},e}(L),N=function(t){function e(e,n,r,i,o,a,s,u,p,c,d,h,l,_){var f=t.call(this,e,n,r,i,o,a,s,u,p,c,d,h)||this;return f._autocompleteFieldset=l,f._formatter=_,f}return(0,n.__extends)(e,t),e.prototype.attach=function(){t.prototype.attach.call(this),this._autocompleteFieldset.attach()},e.prototype._notifyChange=function(t){var e=(0,O.number)(t).card,n=this._previousValue&&(0,O.number)(this._previousValue).card;(0,T.get)(n,"type")!==(0,T.get)(e,"type")&&this._eventPoster.post({type:V.CardTypeChanged,payload:{cardType:e?e.type:void 0}});var r=this._formatter.unformat(t),i=this._previousValue?this._formatter.unformat(this._previousValue):"",o=r.length>=6&&(0,O.number)(r).isPotentiallyValid?r.substr(0,6):"";o!==(i.length>=6?i.substr(0,6):"")&&this._eventPoster.post({type:V.BinChanged,payload:{bin:o}})},e.prototype._formatValue=function(t){var e=this._input.selectionEnd,n=this._formatter.format(t);e===t.length&&t.length<n.length?this._input.setSelectionRange(n.length,n.length):this._input.setSelectionRange(e||0,e||0),this._input.value=n},e}(L),D=function(){function t(t){this._parentWindow=t}return t.prototype.getInputs=function(t){return Array.prototype.slice.call(this._parentWindow.frames).reduce((function(e,r){try{var i=r.hostedInput;return!i||t&&!t(i)?e:(0,n.__spreadArrays)(e,[i])}catch(t){if(t instanceof DOMException)return e;if(t instanceof Error&&"Permission denied"===t.message)return e;throw t}}),[])},t.prototype.getInputValues=function(t){return this.getInputs(t).reduce((function(t,e){var r;return(0,n.__assign)((0,n.__assign)({},t),((r={})[e.getType()]=e.getValue(),r))}),{})},t}(),F=function(t){function e(e){var r=t.call(this,(0,n.__spreadArrays)(["Unable to proceed due to invalid user input values"],(0,T.flatMap)((0,T.values)(e),(function(t){return(0,T.map)(t,(function(t){return t.message}))}))).join(". "))||this;return r.errors=e,r.name="InvalidHostedFormValueError",r.type="invalid_hosted_form_value",r}return(0,n.__extends)(e,t),e}(r),U=function(){function t(t,e,r,i,o){var a=this;this._inputAggregator=t,this._inputValidator=e,this._inputStorage=r,this._eventPoster=i,this._manualOrderPaymentRequestSender=o,this.handle=function(t){return(0,n.__awaiter)(a,void 0,void 0,(function(){var e,r,i,o,a;return(0,n.__generator)(this,(function(n){switch(n.label){case 0:return e=t.payload.data,r=this._inputAggregator.getInputValues(),[4,this._inputValidator.validate(r)];case 1:if(i=n.sent(),this._eventPoster.post({type:V.Validated,payload:i}),!i.isValid)return o=new F(i.errors),[2,this._eventPoster.post({type:V.SubmitManualOrderFailed,payload:{error:{code:(0,T.snakeCase)(o.name),message:o.message}}})];n.label=2;case 2:return n.trys.push([2,4,,5]),[4,this._manualOrderPaymentRequestSender.submitPayment(e,r,this._inputStorage.getNonce())];case 3:return n.sent(),this._eventPoster.post({type:V.SubmitManualOrderSucceeded}),[3,5];case 4:return a=n.sent(),this._eventPoster.post({type:V.SubmitManualOrderFailed,payload:this._isPaymentErrorResponse(a)?{error:a.body.errors[0],response:a}:{error:{code:(0,T.snakeCase)(a.name),message:a.message}}}),[3,5];case 5:return[2]}}))}))}}return t.prototype._isPaymentErrorResponse=function(t){var e=(t||{}).body,n=(void 0===e?{}:e).errors,r=void 0===n?[]:n;return"string"==typeof(r[0]&&r[0].code)&&"string"==typeof(r[0]&&r[0].message)},t}(),M=require("yup"),R=function(){function t(){this._completeSchema={cardCode:this._getCardCodeSchema(),cardExpiry:this._getCardExpirySchema(),cardName:this._getCardNameSchema(),cardNumber:this._getCardNumberSchema()},this._configureCardValidator()}return t.prototype.validate=function(t){return(0,n.__awaiter)(this,void 0,void 0,(function(){var e,r,i,o;return(0,n.__generator)(this,(function(a){switch(a.label){case 0:for(i in e={},r={errors:{},isValid:!0},t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=this._completeSchema[i],r.errors[i]=[]);a.label=1;case 1:return a.trys.push([1,3,,4]),[4,(0,M.object)(e).validate(t,{abortEarly:!1})];case 2:return a.sent(),[2,r];case 3:if("ValidationError"!==(o=a.sent()).name)throw o;return[2,{errors:Object.keys(r.errors).reduce((function(t,e){var r;return(0,n.__assign)((0,n.__assign)({},t),((r={})[e]=o.inner.filter((function(t){return t.path===e})).map((function(t){return{fieldType:t.path,message:t.errors.join(" "),type:t.type}})),r))}),{}),isValid:!1}];case 4:return[2]}}))}))},t.prototype._configureCardValidator=function(){var t=O.creditCardType.getTypeInfo("discover"),e=O.creditCardType.getTypeInfo("visa");O.creditCardType.updateCard("visa",{lengths:(0,n.__spreadArrays)([13],e.lengths||[])}),O.creditCardType.updateCard("discover",{patterns:(0,n.__spreadArrays)(t.patterns||[],[[810,817]])}),O.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}})},t.prototype._getCardCodeSchema=function(){return(0,M.string)().required("CVV is required").test({message:"CVV must be valid",name:"invalid_card_code",test:function(t){var e=(0,O.number)(this.parent.cardNumber||"").card;return(0,O.cvv)(t,e&&e.code?e.code.size:void 0).isValid}})},t.prototype._getCardExpirySchema=function(){return(0,M.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(t){return(0,O.expirationDate)(t).isValid}})},t.prototype._getCardNameSchema=function(){return(0,M.string)().max(200).required("Full name is required")},t.prototype._getCardNumberSchema=function(){return(0,M.string)().required("Credit card number is required").test({message:"Credit card number must be valid",name:"invalid_card_number",test:function(t){return(0,O.number)(t).isValid}})},t}(),q=function(){function t(t,e){this._parentOrigin=t,this._paymentOrigin=e}return t.prototype.create=function(t,e,n,r,i,o){void 0===n&&(n={}),void 0===r&&(r=[]),void 0===i&&(i=""),void 0===o&&(o=function(t){switch(t){case v.CardCode:return"CVC";case v.CardExpiry:return"Expiration";case v.CardName:return"Name on card";case v.CardNumber:return"Credit card number"}}(e));var a=I(e);return e===v.CardNumber?this._createNumberInput(e,t,n,r,i,o,a):e===v.CardExpiry?this._createExpiryInput(t,n,r,i,o,a):this._createInput(e,t,n,r,i,o,a)},t.prototype.normalizeParentOrigin=function(t){this._parentOrigin!==t&&(this._parentOrigin!==a(o(t)).origin&&t!==a(o(this._parentOrigin)).origin||(this._parentOrigin=t))},t.prototype.getParentOrigin=function(){return this._parentOrigin},t.prototype._createExpiryInput=function(t,e,n,r,i,o){return void 0===i&&(i=""),void 0===o&&(o=""),new A(t,r,i,o,e,n,new c(this._parentOrigin),new m(this._parentOrigin,window.parent),new D(window.parent),new R,this._createManualOrderPaymentHandler(),new C)},t.prototype._createNumberInput=function(t,e,n,r,i,o,a){return void 0===o&&(o=""),void 0===a&&(a=""),new N(t,e,i,o,a,n,r,new c(this._parentOrigin),new m(this._parentOrigin,window.parent),new D(window.parent),new R,this._createManualOrderPaymentHandler(),new P(e,[v.CardCode,v.CardExpiry,v.CardName],new D(window.parent)),new S)},t.prototype._createInput=function(t,e,n,r,i,o,a){return void 0===o&&(o=""),void 0===a&&(a=""),new L(t,e,i,o,a,n,r,new c(this._parentOrigin),new m(this._parentOrigin,window.parent),new D(window.parent),new R,this._createManualOrderPaymentHandler())},t.prototype._createManualOrderPaymentHandler=function(){return new U(new D(window.parent),new R,l(),new m(this._parentOrigin,window.parent),new w((0,_.createRequestSender)(),this._paymentOrigin))},t}(),H=function(t){function e(e){var n=t.call(this,e||"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)(e,t),e}(r),k=function(){function t(t,e,n){this._factory=t,this._storage=e,this._eventListener=n}return t.prototype.initialize=function(t,e){var n=this;e&&this._storage.setNonce(e);var r=this._createFormContainer(t);return this._resetPageStyles(t),this._eventListener.listen(),(0,f.fromEvent)(this._eventListener,x.AttachRequested).pipe((0,y.map)((function(t){var e=t.payload,i=e.accessibilityLabel,o=e.fontUrls,a=e.placeholder,s=e.styles,u=e.origin,p=e.type;u&&n._factory.normalizeParentOrigin(u);var c=n._factory.create(r,p,s,o,a,i);return c.attach(),c})),(0,y.take)(1)).toPromise()},t.prototype._resetPageStyles=function(t){[document.querySelector("html"),document.querySelector("body"),document.getElementById(t)].forEach((function(t){t&&(t.style.height="100%",t.style.width="100%",t.style.overflow="hidden",t.style.padding="0",t.style.margin="0")}))},t.prototype._createFormContainer=function(t){var e=document.getElementById(t);if(!e)throw new H("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",e.appendChild(n),n.appendChild(r),n},t}();function j(t){var e=t.containerId,n=t.nonce,r=t.parentOrigin,i=t.paymentOrigin;return new k(new q(r,i),l(),new c(r)).initialize(e,n)}var B=new m("*",window.parent);function z(t){B.post({type:V.AttachFailed,payload:{error:t}})}module.exports=e})();
|
|
2
2
|
//# sourceMappingURL=hosted-form-v2-iframe-content.js.map
|