1
1
/* eslint-disable eslint-comments/disable-enable-pair, no-else-return */
2
2
import arrayFrom from 'core-js-pure/stable/array/from' ;
3
- import { getStorage as getBelterStorage } from '@krakenjs/belter/src' ;
3
+ import { getStorage as getBelterStorage , uniqueID as createBelterID } from '@krakenjs/belter/src' ;
4
4
import { SDK_QUERY_KEYS , SDK_SETTINGS } from '@paypal/sdk-constants/src' ;
5
5
import {
6
6
getClientID ,
@@ -14,6 +14,8 @@ import {
14
14
getCSPNonce ,
15
15
getNamespace as getSDKNamespace ,
16
16
getDefaultNamespace as getDefaultSDKNamespace ,
17
+ getGlobalSessionID as getSDKGlobalSessionID ,
18
+ setGlobalSessionID as setSDKGlobalSessionID ,
17
19
getSessionID as getSDKSessionID ,
18
20
getStorageID as getSDKStorageID ,
19
21
getStorageState as getSDKStorageState ,
@@ -161,6 +163,23 @@ export function getStorage() {
161
163
return getBelterStorage ( { name : getNamespace ( ) } ) ;
162
164
}
163
165
166
+ // Uses SDK methods to get and set a global session ID
167
+ // value will be passed in message_render events
168
+ // and used to correlate with button events
169
+ export function getOrCreateGlobalSessionID ( ) {
170
+ if ( __MESSAGES__ . __TARGET__ === 'SDK' ) {
171
+ let globalSessionID = getSDKGlobalSessionID ( ) ;
172
+ if ( ! globalSessionID ) {
173
+ globalSessionID = createBelterID ( ) ;
174
+ setSDKGlobalSessionID ( globalSessionID ) ;
175
+ }
176
+
177
+ return globalSessionID ;
178
+ } else {
179
+ return getStorage ( ) . getSessionID ( ) ;
180
+ }
181
+ }
182
+
164
183
// Use SDK methods when available, otherwise manually fetch storage via belter
165
184
// see: https://github.com/paypal/paypal-sdk-client/blob/master/src/session.js
166
185
export function getSessionID ( ) {
0 commit comments