@@ -5,11 +5,21 @@ const sessionKey = 'foobar123';
55const endpoint = 'https://example.com' ;
66const originUrl = `${ window . location . protocol } ://${ window . location . host } ` ;
77
8- function getSourceUrl ( locale = '' ) {
8+ function getDataParam ( custom = null ) {
9+ if ( ! custom ) return '' ;
10+
11+ return ClicksignVerify . base64EncodeUrl ( JSON . stringify ( { custom } ) ) ;
12+ }
13+
14+ function getSourceUrl ( locale = '' , custom = null ) {
915 const prefix = `${ endpoint } /app/verify` ;
1016 const verifyPath = locale ? `${ prefix } /${ locale } ` : prefix ;
17+ const query = new URLSearchParams ( { origin : originUrl } ) ;
18+ const data = getDataParam ( custom ) ;
19+
20+ if ( data ) query . set ( 'data' , data ) ;
1121
12- return `${ verifyPath } /transactions/${ sessionKey } ?origin= ${ originUrl } ` ;
22+ return `${ verifyPath } /transactions/${ sessionKey } ?${ query . toString ( ) } ` ;
1323}
1424
1525function createContainerElement ( ) {
@@ -27,6 +37,8 @@ describe('ClicksignVerify', () => {
2737
2838 instance . endpoint = endpoint ;
2939 instance . origin = originUrl ;
40+ instance . locale = '' ;
41+ instance . custom = null ;
3042 instance . listen = { } ;
3143 } ) ;
3244
@@ -39,6 +51,7 @@ describe('ClicksignVerify', () => {
3951 expect ( instance . origin ) . toBe ( originUrl ) ;
4052 expect ( instance . endpoint ) . toBe ( endpoint ) ;
4153 expect ( instance . locale ) . toBe ( '' ) ;
54+ expect ( instance . custom ) . toBeNull ( ) ;
4255 expect ( instance . source ) . toBe ( getSourceUrl ( ) ) ;
4356 } ) ;
4457
@@ -102,6 +115,53 @@ describe('ClicksignVerify', () => {
102115 } ) ;
103116 } ) ;
104117
118+ describe ( 'Customization' , ( ) => {
119+ it ( 'should initialize custom as null by default' , ( ) => {
120+ expect ( instance . custom ) . toBeNull ( ) ;
121+ } ) ;
122+
123+ it ( 'should include custom colors in data query param in the iframe source URL when custom colors is set' , ( ) => {
124+ const custom = {
125+ colors : {
126+ buttonTextColor : '#ffffff' ,
127+ buttonBackgroundColor : '#000000' ,
128+ } ,
129+ } ;
130+
131+ instance . custom = custom ;
132+ instance . start ( containerElementId ) ;
133+
134+ const iframeElement = document . getElementById ( containerElementId ) . children [ 0 ] ;
135+ const iframeSrcUrl = new URL ( iframeElement . src ) ;
136+
137+ expect ( instance . params ) . toContain ( 'data=' ) ;
138+ expect ( instance . source ) . toBe ( getSourceUrl ( '' , custom ) ) ;
139+ expect ( iframeSrcUrl . searchParams . get ( 'data' ) ) . toBe ( getDataParam ( custom ) ) ;
140+ } ) ;
141+ } ) ;
142+
143+ describe ( 'Query Params' , ( ) => {
144+ it ( 'should include origin query param in the iframe source URL' , ( ) => {
145+ instance . start ( containerElementId ) ;
146+
147+ const iframeElement = document . getElementById ( containerElementId ) . children [ 0 ] ;
148+ const iframeSrcUrl = new URL ( iframeElement . src ) ;
149+
150+ expect ( instance . params ) . toBe ( `?${ new URLSearchParams ( { origin : originUrl } ) . toString ( ) } ` ) ;
151+ expect ( iframeSrcUrl . searchParams . get ( 'origin' ) ) . toBe ( originUrl ) ;
152+ } ) ;
153+
154+ it ( 'should not include data query param when there is no payload' , ( ) => {
155+ instance . start ( containerElementId ) ;
156+
157+ const iframeElement = document . getElementById ( containerElementId ) . children [ 0 ] ;
158+ const iframeSrcUrl = new URL ( iframeElement . src ) ;
159+
160+ expect ( instance . params ) . not . toContain ( 'data=' ) ;
161+ expect ( iframeSrcUrl . searchParams . get ( 'data' ) ) . toBeNull ( ) ;
162+ } ) ;
163+ } ) ;
164+
105165 describe ( 'Events' , ( ) => {
106166 const eventMock = vi . fn ( ) ;
107167 const events = [ 'loaded' , 'completed' , 'error' ] ;
0 commit comments