11/* eslint-disable eslint-comments/disable-enable-pair, no-else-return */
22import 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' ;
44import { SDK_QUERY_KEYS , SDK_SETTINGS } from '@paypal/sdk-constants/src' ;
55import {
66 getClientID ,
@@ -14,6 +14,8 @@ import {
1414 getCSPNonce ,
1515 getNamespace as getSDKNamespace ,
1616 getDefaultNamespace as getDefaultSDKNamespace ,
17+ getGlobalSessionID as getSDKGlobalSessionID ,
18+ setGlobalSessionID as setSDKGlobalSessionID ,
1719 getSessionID as getSDKSessionID ,
1820 getStorageID as getSDKStorageID ,
1921 getStorageState as getSDKStorageState ,
@@ -161,6 +163,23 @@ export function getStorage() {
161163 return getBelterStorage ( { name : getNamespace ( ) } ) ;
162164}
163165
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+
164183// Use SDK methods when available, otherwise manually fetch storage via belter
165184// see: https://github.com/paypal/paypal-sdk-client/blob/master/src/session.js
166185export function getSessionID ( ) {
0 commit comments