Initial commit
This commit is contained in:
46
api/hooks/cart/get_read.js
Normal file
46
api/hooks/cart/get_read.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const { getCart, getRedirectUrl } = require("../lib/bigcommerceRestAPI")
|
||||
const { bigcommerceStoreHash, bigcommerceBaseURL, bigCommerceCliendId, bigCommerceClientSecret } = require("../config")
|
||||
const { getCustomerById, getLoginUrl } = require("../lib/bigcommerceRestAPI")
|
||||
const { withAccount } = require("../lib/utils")
|
||||
const { mapRestApiCartToGraphQL } = require("./helper")
|
||||
;(function () {
|
||||
if (context.user.auth()) return {}
|
||||
const checkout = context.request().query("checkout")
|
||||
const loggedInCheckout = context.request().query("loggedInCheckout")
|
||||
if (checkout) {
|
||||
if (loggedInCheckout) {
|
||||
withAccount((loginClaims) => {
|
||||
const cartId = context.request().param("id")
|
||||
const cart = getCart(cartId)
|
||||
const { checkoutURL } = getRedirectUrl(cartId)
|
||||
const loginUrl = getLoginUrl(
|
||||
loginClaims.bigCommerceId,
|
||||
bigcommerceStoreHash,
|
||||
bigcommerceBaseURL,
|
||||
bigCommerceCliendId,
|
||||
bigCommerceClientSecret,
|
||||
checkoutURL.split(bigcommerceBaseURL).pop()
|
||||
)
|
||||
throw {
|
||||
status: 200,
|
||||
data: cart && {
|
||||
cart: mapRestApiCartToGraphQL(cart),
|
||||
checkoutURL: loginUrl,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
const cartId = context.request().param("id")
|
||||
const cart = getCart(cartId)
|
||||
const { checkoutURL, embeddedCheckoutURL } = getRedirectUrl(cartId)
|
||||
|
||||
throw {
|
||||
status: 200,
|
||||
data: cart && {
|
||||
cart: mapRestApiCartToGraphQL(cart),
|
||||
checkoutURL: checkoutURL,
|
||||
embeddedCheckoutURL: embeddedCheckoutURL,
|
||||
},
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user