From 9d5b23a24b6f099b5c32e6d64fa63cc8752f7cea Mon Sep 17 00:00:00 2001 From: Andy Rudge Date: Mon, 30 Nov 2020 08:50:52 -0500 Subject: [PATCH] Utilize new anonymous basket transfer token fetching (#5) * Utilize new anonymous basket transfer token fetching --- src/components/BasketTransfer.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/BasketTransfer.js b/src/components/BasketTransfer.js index 45efbba..7c73f8a 100644 --- a/src/components/BasketTransfer.js +++ b/src/components/BasketTransfer.js @@ -5,20 +5,22 @@ export default function transferBasket(lineItems) { // if you need an apiKey reach out to TTS-Digital-OPE-MPLS@Target.com let apiKey = "892df78add06fbe4bdac11646e00d9273f0aa6ea" let partnerName = "cartster" // partner name is assigned to each external partner + // This token url is not accessible to the public internet. + // For more details on how to fetch your own basket transfer tokens, reach out to TTS-Digital-OPE-MPLS@Target.com + let authTokenUrl = "https://cartstertapapi.dev.target.com/gsp/external_token/v1" + let partnersCommerceHost = "https://api.target.com/" var accessToken // this function: // - Gets an auth token // - Sends a request to add ingredient items to a cart // - Re-directs to Target.com checkout page - fetch("https://gsp.target.com/gsp/authorizations/v1/client_tokens", { - method: "POST", - body: JSON.stringify({client_name: partnerName}), + fetch(authTokenUrl, { + method: "GET", headers: { "cache-control": "no-cache", "content-type": "application/json" }, - credentials: 'include' }) .then(response => response.json()) .then(data => { @@ -26,7 +28,7 @@ export default function transferBasket(lineItems) { return accessToken; }) .then(accessToken => { - return fetch("https://api.target.com/commerce_partners/v1/cart_items", { + return fetch(partnersCommerceHost+"/commerce_partners/v1/cart_items", { method: "POST", body: JSON.stringify({ cart_items: lineItems @@ -42,6 +44,6 @@ export default function transferBasket(lineItems) { .then(response => response.json()) .then(data => { console.log(data); - window.location.href = "https://www.target.com/co-cart"; + window.location.href = "https://www.target.com/co-cart?access_token="+accessToken; }); }