Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Utilize new anonymous basket transfer token fetching (#5)
Browse files Browse the repository at this point in the history
* Utilize new anonymous basket transfer token fetching
  • Loading branch information
arudge authored Nov 30, 2020
1 parent b9023e6 commit 9d5b23a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/components/BasketTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
});
}

0 comments on commit 9d5b23a

Please sign in to comment.