This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilize new anonymous basket transfer token fetching (#5)
* Utilize new anonymous basket transfer token fetching
- Loading branch information
Showing
1 changed file
with
8 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,28 +5,30 @@ export default function transferBasket(lineItems) { | |
// if you need an apiKey reach out to [email protected] | ||
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 [email protected] | ||
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 => { | ||
accessToken = data.access_token; | ||
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; | ||
}); | ||
} |