Skip to content

Commit c079cd5

Browse files
committed
fix(POS-1250): make 3ds iframe configurable from the outside
1 parent 516bd28 commit c079cd5

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

src/processout/actionhandler.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ module ProcessOut {
6161
}
6262

6363
export type IframeOverride = {
64-
width: number,
65-
height: number
64+
width: number | string,
65+
height: number | string,
6666
}
6767

6868
export class ActionHandlerOptions {
@@ -74,8 +74,8 @@ module ProcessOut {
7474
public newWindowWidth?: number;
7575

7676
// Specifies how big the iframe is, it can be overridden by IframeOverride
77-
public iframeWidth: number = 440;
78-
public iframeHeight: number = 480;
77+
public iframeWidth: number | string = 440;
78+
public iframeHeight: number | string = 480;
7979

8080
// gatewayLogo is shown when the action is done on another tab or window
8181
public gatewayLogo?: string;
@@ -144,8 +144,14 @@ module ProcessOut {
144144

145145
if(override) {
146146
this.flow = ActionFlow.IFrame;
147-
this.iframeWidth = override.width;
148-
this.iframeHeight = override.height;
147+
148+
if (override.width) {
149+
this.iframeWidth = override.width;
150+
}
151+
152+
if (override.height) {
153+
this.iframeHeight = override.height;
154+
}
149155
}
150156
}
151157
}
@@ -228,9 +234,15 @@ module ProcessOut {
228234
iframeWrapper.style.width = "100%";
229235
iframeWrapper.setAttribute("style", "position: fixed; top: 0; left: 0; background: rgba(0, 0, 0, 0.5); z-index: 9999999; overflow: auto;");
230236

237+
// If the option is number it means that we should use pixels here for the sake of
238+
// backward compatibility. If not - then we use it as value since user can pass
239+
// any unit like percentages e.g. 100%, calc(100% - 80px), 30rem etc
240+
const width = typeof this.options.iframeWidth === 'number' ? `${this.options.iframeWidth}px` : this.options.iframeWidth
241+
const height = typeof this.options.iframeHeight === 'number' ? `${this.options.iframeHeight}px` : this.options.iframeHeight;
242+
231243
// Create the iframe to be used later
232244
var iframe = document.createElement("iframe");
233-
iframe.setAttribute("style", `margin: 1em auto; width: ${this.options.iframeWidth}px; height: ${this.options.iframeHeight}px; max-width: 100%; max-height: 100%; display: block; box-shadow: 0 15px 35px rgba(50, 50, 93, 0.1), 0 5px 15px rgba(0, 0, 0, 0.07); background-color: #ECEFF1; background-image: url("${this.instance.endpoint("js", "/images/loader.gif")}"); background-repeat: no-repeat; background-position: center;")`);
245+
iframe.setAttribute("style", `margin: 1em auto; width: ${width}; height: ${height}; max-width: 100%; max-height: 100%; display: block; box-shadow: 0 15px 35px rgba(50, 50, 93, 0.1), 0 5px 15px rgba(0, 0, 0, 0.07); background-color: #ECEFF1; background-image: url("${this.instance.endpoint("js", "/images/loader.gif")}"); background-repeat: no-repeat; background-position: center;")`);
234246
iframe.setAttribute("frameborder", "0");
235247
iframe.onload = function() {
236248
// Remove the background loader once it is actually loaded

src/processout/processout.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ module ProcessOut {
13951395
options: any,
13961396
success: (data: any) => void,
13971397
error: (err: Exception) => void,
1398+
iframeOverride?: IframeOverride,
13981399
): void {
13991400
if (val instanceof Card || val instanceof CardForm)
14001401
return this.tokenize(
@@ -1408,6 +1409,7 @@ module ProcessOut {
14081409
options,
14091410
success,
14101411
error,
1412+
iframeOverride,
14111413
)
14121414
}.bind(this),
14131415
error,
@@ -1420,6 +1422,7 @@ module ProcessOut {
14201422
options,
14211423
success,
14221424
error,
1425+
iframeOverride,
14231426
)
14241427
}
14251428

@@ -1430,6 +1433,7 @@ module ProcessOut {
14301433
options: any,
14311434
success: (data: any) => void,
14321435
error: (err: Exception) => void,
1436+
iframeOverride?: IframeOverride,
14331437
): void {
14341438
this.handleCardActions(
14351439
"PUT",
@@ -1439,6 +1443,8 @@ module ProcessOut {
14391443
options,
14401444
success,
14411445
error,
1446+
undefined,
1447+
iframeOverride,
14421448
)
14431449
}
14441450

@@ -1460,6 +1466,7 @@ module ProcessOut {
14601466
success: (data: any) => void,
14611467
error: (err: Exception) => void,
14621468
apiRequestOptions?: apiRequestOptions,
1469+
iframeOverride?: IframeOverride,
14631470
): void {
14641471
const url: string = `invoices/${invoiceID}/capture`
14651472
this.threeDSInitiationURL = `invoices/${invoiceID}/three-d-s`
@@ -1474,6 +1481,7 @@ module ProcessOut {
14741481
success,
14751482
error,
14761483
apiRequestOptions,
1484+
iframeOverride,
14771485
)
14781486
}
14791487

@@ -1493,6 +1501,7 @@ module ProcessOut {
14931501
success: (data: any) => void,
14941502
error: (err: Exception) => void,
14951503
apiRequestOptions?: apiRequestOptions,
1504+
iframeOverride?: IframeOverride,
14961505
): void {
14971506
this.handleCardActions(
14981507
"POST",
@@ -1503,6 +1512,7 @@ module ProcessOut {
15031512
success,
15041513
error,
15051514
apiRequestOptions,
1515+
iframeOverride,
15061516
)
15071517
}
15081518

@@ -1521,6 +1531,7 @@ module ProcessOut {
15211531
options: any,
15221532
success: (data: any) => void,
15231533
error: (err: Exception) => void,
1534+
iframeOverride?: IframeOverride,
15241535
): void {
15251536
if (!options) options = {}
15261537
options.incremental = true
@@ -1532,6 +1543,8 @@ module ProcessOut {
15321543
options,
15331544
success,
15341545
error,
1546+
undefined,
1547+
iframeOverride,
15351548
)
15361549
}
15371550

@@ -1576,6 +1589,7 @@ module ProcessOut {
15761589
success: (data: any) => void,
15771590
error: (err: Exception) => void,
15781591
apiRequestOptions?: apiRequestOptions,
1592+
iframeOverride?: IframeOverride,
15791593
): void {
15801594
// returns this.hppInitialURL only once during the first call from HPP, then returns the endpoint
15811595
const getEndpoint = (): string => {
@@ -1646,6 +1660,7 @@ module ProcessOut {
16461660
success,
16471661
error,
16481662
apiRequestOptions,
1663+
iframeOverride,
16491664
)
16501665
}.bind(this)
16511666

@@ -1672,10 +1687,15 @@ module ProcessOut {
16721687
success,
16731688
error,
16741689
apiRequestOptions,
1690+
iframeOverride,
16751691
)
16761692
}.bind(this),
16771693
error,
1678-
new ActionHandlerOptions(opts),
1694+
new ActionHandlerOptions(
1695+
opts,
1696+
undefined,
1697+
opts !== ActionHandlerOptions.ThreeDSChallengeFlowNoIframe ? iframeOverride : undefined
1698+
)
16791699
)
16801700
break
16811701

@@ -1698,7 +1718,11 @@ module ProcessOut {
16981718
gReq.body = `threeDSMethodData={"threeDS2FingerprintTimeout":true}`
16991719
nextStep(gReq.token())
17001720
},
1701-
new ActionHandlerOptions(ActionHandlerOptions.ThreeDSFingerprintFlow),
1721+
new ActionHandlerOptions(
1722+
ActionHandlerOptions.ThreeDSFingerprintFlow,
1723+
undefined,
1724+
iframeOverride,
1725+
),
17021726
)
17031727
break
17041728

@@ -1708,7 +1732,11 @@ module ProcessOut {
17081732
data.customer_action.value,
17091733
nextStep,
17101734
error,
1711-
new ActionHandlerOptions(ActionHandlerOptions.ThreeDSChallengeFlow),
1735+
new ActionHandlerOptions(
1736+
ActionHandlerOptions.ThreeDSChallengeFlow,
1737+
undefined,
1738+
iframeOverride,
1739+
),
17121740
)
17131741
break
17141742

0 commit comments

Comments
 (0)