-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
M-OC
committed
Aug 29, 2019
1 parent
4cc5854
commit 55a85ba
Showing
6 changed files
with
235 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getClientID, getMerchantID } from '@paypal/sdk-client/src'; | ||
|
||
export const getPropertyId = ({ paramsToPropertyIdUrl }) => { | ||
return new Promise(resolve => { | ||
const clientId = getClientID(); | ||
const merchantId = getMerchantID()[0]; | ||
const propertyIdKey = `property-id-${ clientId }-${ merchantId }`; | ||
const savedPropertyId = window.localStorage.getItem(propertyIdKey); | ||
const currentUrl = `${ window.location.protocol }//${ window.location.host }`; | ||
if (savedPropertyId) { | ||
return resolve(savedPropertyId); | ||
} | ||
let url; | ||
if (paramsToPropertyIdUrl) { | ||
url = paramsToPropertyIdUrl(); | ||
} else { | ||
url = 'https://paypal.com/tagmanager/containers/xo'; | ||
} | ||
return window.fetch(`${ url }?mrid=${ merchantId }&url=${ encodeURIComponent(currentUrl) }`) | ||
.then(res => { | ||
if (res.status === 200) { | ||
return res; | ||
} | ||
}) | ||
.then(r => r.json()).then(container => { | ||
window.localStorage.setItem(propertyIdKey, container.id); | ||
resolve(container.id); | ||
}) | ||
.catch(() => { | ||
// doing nothing for now since there's no logging | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -462,9 +462,9 @@ describe('paypal.Tracker', () => { | |
JSON.stringify({ | ||
oldUserId: 'abc123', | ||
user: { | ||
id: 'abc123', | ||
email: '__test__email9', | ||
name: '__test__userName9', | ||
id: 'abc123' | ||
}, | ||
propertyId, | ||
trackingType: 'setUser', | ||
|
@@ -496,9 +496,9 @@ describe('paypal.Tracker', () => { | |
JSON.stringify({ | ||
oldUserId: 'abc123', | ||
user: { | ||
id: 'abc123', | ||
email: '[email protected]', | ||
name: '__test__name', | ||
id: 'abc123' | ||
}, | ||
propertyId, | ||
trackingType: 'setUser', | ||
|
@@ -544,9 +544,9 @@ describe('paypal.Tracker', () => { | |
currencyCode: 'USD', | ||
cartEventType: 'addToCart', | ||
user: { | ||
id: 'abc123', | ||
email: '__test__email2', | ||
name: '__test__name1', | ||
id: 'abc123' | ||
}, | ||
propertyId, | ||
trackingType: 'cartEvent', | ||
|
Oops, something went wrong.