mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
add core return to orders
This commit is contained in:
@@ -203,7 +203,6 @@ export async function refreshToken({ request, origin }: { request: NextRequest;
|
||||
return { success: false, message: `no_refresh_token` };
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log('data response from initial fetch to refresh', data);
|
||||
const { access_token, expires_in, refresh_token } = data;
|
||||
|
||||
const customerAccessToken = await exchangeAccessToken(
|
||||
@@ -238,10 +237,7 @@ export async function checkExpires({
|
||||
let isExpired = false;
|
||||
if (parseInt(expiresAt, 10) - 1000 < new Date().getTime()) {
|
||||
isExpired = true;
|
||||
console.log('Isexpired is true, we are running refresh token!');
|
||||
const refresh = await refreshToken({ request, origin });
|
||||
console.log('refresh', refresh);
|
||||
//this will return success: true or success: false - depending on result of refresh
|
||||
return { ranRefresh: isExpired, refresh };
|
||||
}
|
||||
return { ranRefresh: isExpired, success: true };
|
||||
@@ -364,8 +360,6 @@ export async function isLoggedIn(request: NextRequest, origin: string) {
|
||||
//return { success: false, message: `no_refresh_token` }
|
||||
} else {
|
||||
const refreshData = isExpired?.refresh?.data;
|
||||
//console.log ("refresh data", refreshData)
|
||||
console.log('We used the refresh token, so now going to reset the token and cookies');
|
||||
const newCustomerAccessToken = refreshData?.customerAccessToken;
|
||||
const expires_in = refreshData?.expires_in;
|
||||
//const test_expires_in = 180 //to test to see if it expires in 60 seconds!
|
||||
@@ -468,7 +462,6 @@ export async function authorize(request: NextRequest, origin: string) {
|
||||
//sets an expires time 2 minutes before expiration which we can use in refresh strategy
|
||||
//const test_expires_in = 180 //to test to see if it expires in 60 seconds!
|
||||
const expiresAt = new Date(new Date().getTime() + (expires_in! - 120) * 1000).getTime() + '';
|
||||
console.log('expires at', expiresAt);
|
||||
|
||||
return await createAllCookies({
|
||||
response: authResponse,
|
||||
|
@@ -50,6 +50,33 @@ const orderMetafieldsFragment = /* GraphQL */ `
|
||||
orderConfirmation: metafield(namespace: "custom", key: "customer_confirmation") {
|
||||
value
|
||||
}
|
||||
coreReturnStatus: metafield(namespace: "custom", key: "core_status") {
|
||||
value
|
||||
}
|
||||
coreReturnDeadline: metafield(namespace: "custom", key: "core_return_deadline") {
|
||||
value
|
||||
}
|
||||
coreReturnName: metafield(namespace: "custom", key: "core_return_name") {
|
||||
value
|
||||
}
|
||||
coreReturnEmail: metafield(namespace: "custom", key: "core_return_email") {
|
||||
value
|
||||
}
|
||||
coreReturnPhone: metafield(namespace: "custom", key: "core_return_phone") {
|
||||
value
|
||||
}
|
||||
coreReturnAddress: metafield(namespace: "custom", key: "core_return_address") {
|
||||
value
|
||||
}
|
||||
coreReturnCity: metafield(namespace: "custom", key: "core_return_city") {
|
||||
value
|
||||
}
|
||||
coreReturnState: metafield(namespace: "custom", key: "core_return_state") {
|
||||
value
|
||||
}
|
||||
coreReturnZip: metafield(namespace: "custom", key: "core_return_zip") {
|
||||
value
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
@@ -136,6 +136,9 @@ const userAgent = '*';
|
||||
const placeholderProductImage =
|
||||
'https://cdn.shopify.com/shopifycloud/customer-account-web/production/assets/8bc6556601c510713d76.svg';
|
||||
|
||||
const placeholderPaymentIcon =
|
||||
'https://cdn.shopify.com/shopifycloud/customer-account-web/production/assets/7bea2f.svg';
|
||||
|
||||
const key = process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN!;
|
||||
const adminAccessToken = process.env.SHOPIFY_ADMIN_API_ACCESS_TOKEN!;
|
||||
|
||||
@@ -597,15 +600,17 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
||||
const orderTransactions: Transaction[] = shopifyOrder.transactions?.map((transaction) => ({
|
||||
processedAt: transaction.processedAt,
|
||||
paymentIcon: {
|
||||
url: transaction.paymentIcon.url,
|
||||
altText: transaction.paymentIcon.altText,
|
||||
url: transaction.paymentIcon?.url || placeholderPaymentIcon,
|
||||
altText: transaction.paymentIcon?.altText || 'Payment Icon',
|
||||
width: 100,
|
||||
height: 100
|
||||
},
|
||||
paymentDetails: {
|
||||
last4: transaction.paymentDetails.last4,
|
||||
cardBrand: transaction.paymentDetails.cardBrand
|
||||
},
|
||||
paymentDetails: transaction.paymentDetails
|
||||
? {
|
||||
last4: transaction.paymentDetails.last4,
|
||||
cardBrand: transaction.paymentDetails.cardBrand
|
||||
}
|
||||
: undefined,
|
||||
transactionAmount: reshapeMoney(transaction.transactionAmount.presentmentMoney)!
|
||||
}));
|
||||
|
||||
@@ -642,7 +647,17 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
||||
warrantyActivationOdometer: shopifyOrder.warrantyActivationOdometer,
|
||||
warrantyActivationSelfInstall: shopifyOrder.warrantyActivationSelfInstall,
|
||||
warrantyActivationVIN: shopifyOrder.warrantyActivationVIN,
|
||||
orderConfirmation: shopifyOrder.orderConfirmation
|
||||
orderConfirmation: shopifyOrder.orderConfirmation,
|
||||
coreReturnStatus: shopifyOrder.coreReturnStatus,
|
||||
coreReturnDeadline: shopifyOrder.coreReturnDeadline,
|
||||
coreReturnName: shopifyOrder.coreReturnName,
|
||||
coreReturnAddress: shopifyOrder.coreReturnAddress,
|
||||
coreReturnEmail: shopifyOrder.coreReturnEmail,
|
||||
coreReturnPhone: shopifyOrder.coreReturnPhone,
|
||||
coreReturnCity: shopifyOrder.coreReturnCity,
|
||||
coreReturnState: shopifyOrder.coreReturnState,
|
||||
coreReturnZip: shopifyOrder.coreReturnZip,
|
||||
coreReturnDescription: shopifyOrder.coreReturnDescription
|
||||
};
|
||||
|
||||
if (shopifyOrder.customer) {
|
||||
@@ -1182,14 +1197,24 @@ export const getFile = async (id: string) => {
|
||||
};
|
||||
|
||||
export async function getProductFilters(
|
||||
{ collection }: { collection: string },
|
||||
{ collection, make }: { collection: string; make?: string | string[] },
|
||||
filterId: string
|
||||
): Promise<Filter | null | undefined> {
|
||||
const [namespace, metafieldKey] = MAKE_FILTER_ID.split('.').slice(-2);
|
||||
const _make = Array.isArray(make) ? make : make ? [make] : undefined;
|
||||
|
||||
const res = await shopifyFetch<ShopifyCollectionProductsOperation>({
|
||||
query: getProductFiltersQuery,
|
||||
tags: [TAGS.collections, TAGS.products],
|
||||
variables: {
|
||||
handle: collection
|
||||
handle: collection,
|
||||
...(_make
|
||||
? {
|
||||
filters: _make.map((make) => ({
|
||||
productMetafield: { namespace, key: metafieldKey, value: make }
|
||||
}))
|
||||
}
|
||||
: {})
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -105,7 +105,7 @@ export type Fulfillment = {
|
||||
export type Transaction = {
|
||||
processedAt: string;
|
||||
paymentIcon: Image;
|
||||
paymentDetails: {
|
||||
paymentDetails?: {
|
||||
last4: string;
|
||||
cardBrand: string;
|
||||
};
|
||||
@@ -196,8 +196,8 @@ type ShopifyShippingLine = {
|
||||
type ShopifyOrderTransaction = {
|
||||
id: string;
|
||||
processedAt: string;
|
||||
paymentIcon: ShopifyPaymentIconImage;
|
||||
paymentDetails: ShopifyCardPaymentDetails;
|
||||
paymentIcon: ShopifyPaymentIconImage | null;
|
||||
paymentDetails: ShopifyCardPaymentDetails | null;
|
||||
transactionAmount: ShopifyMoneyBag;
|
||||
giftCardDetails: ShopifyGiftCardDetails | null;
|
||||
status: string;
|
||||
@@ -879,6 +879,14 @@ export enum WarrantyStatus {
|
||||
LimitedActivated = 'Limited Activation'
|
||||
}
|
||||
|
||||
export enum CoreReturnStatus {
|
||||
CoreNeeded = 'Core Needed',
|
||||
PickupRequested = 'Pickup Requested',
|
||||
BOLCreated = 'BOL Created',
|
||||
CoreReceived = 'Core Received',
|
||||
CoreRefunded = 'Core Refunded'
|
||||
}
|
||||
|
||||
export type ShopifyOrderMetafield = {
|
||||
orderConfirmation: ShopifyMetafield | null;
|
||||
warrantyStatus: ShopifyMetafield | null;
|
||||
@@ -888,6 +896,16 @@ export type ShopifyOrderMetafield = {
|
||||
warrantyActivationSelfInstall: ShopifyMetafield | null;
|
||||
warrantyActivationVIN: ShopifyMetafield | null;
|
||||
warrantyActivationMileage: ShopifyMetafield | null;
|
||||
coreReturnStatus: ShopifyMetafield | null;
|
||||
coreReturnDeadline: ShopifyMetafield | null;
|
||||
coreReturnName: ShopifyMetafield | null;
|
||||
coreReturnAddress: ShopifyMetafield | null;
|
||||
coreReturnEmail: ShopifyMetafield | null;
|
||||
coreReturnPhone: ShopifyMetafield | null;
|
||||
coreReturnCity: ShopifyMetafield | null;
|
||||
coreReturnState: ShopifyMetafield | null;
|
||||
coreReturnZip: ShopifyMetafield | null;
|
||||
coreReturnDescription: ShopifyMetafield | null;
|
||||
};
|
||||
|
||||
export type File = {
|
||||
|
@@ -8,11 +8,7 @@ export function cx(...args: ClassValue[]) {
|
||||
}
|
||||
export const focusInput = [
|
||||
// base
|
||||
'focus:ring-2',
|
||||
// ring color
|
||||
'focus:ring-blue-200 focus:dark:ring-blue-700/30',
|
||||
// border color
|
||||
'focus:border-blue-500 focus:dark:border-blue-700'
|
||||
'focus:ring-2 focus:ring-offset-4'
|
||||
];
|
||||
|
||||
export const hasErrorInput = [
|
||||
|
Reference in New Issue
Block a user