Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart was not cleaning after GiftCards payment #131

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions domains/cart-redis/server/plugins/manage-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import { QueryName } from "~/server/queries";
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook("beforeResponse", async (event, { body }) => {
if (event.method == "POST") {
await cartAddItem(event, body);
await cartRemoveItem(event, body);
await cartUpdateItem(event, body);
await updateAddress(event, body);
await addAddress(event, body);
await createUpdatePartner(event, body);
await applyCoupon(event, body);
await applyGiftCard(event, body);
await clearCartAfterPaymentConfirmation(event, body);
await Promise.all([
cartAddItem(event, body),
cartRemoveItem(event, body),
cartUpdateItem(event, body),
updateAddress(event, body),
addAddress(event, body),
createUpdatePartner(event, body),
applyCoupon(event, body),
applyGiftCard(event, body),
clearCartAfterCreditCardPaymentConfirmation(event, body),
clearCartAfterGiftCardPaymentConfirmation(event, body),
]);
}
});
});
Expand Down Expand Up @@ -173,7 +176,10 @@ async function createUpdatePartner(event: any, body: any) {
}
}

async function clearCartAfterPaymentConfirmation(event: any, body: any) {
async function clearCartAfterCreditCardPaymentConfirmation(
event: any,
body: any
) {
const requestBody = await readBody(event);

const paymentSuccess =
Expand All @@ -191,3 +197,25 @@ async function clearCartAfterPaymentConfirmation(event: any, body: any) {
}
}
}

async function clearCartAfterGiftCardPaymentConfirmation(
event: any,
body: any
) {
const requestBody = await readBody(event);

const paymentSuccess = body?.makeGiftCardPayment?.done;

if (
requestBody[0]?.mutationName === MutationName.MakeGiftCardPaymentMutation
) {
const session = await useSession(event, {
password: "b013b03ac2231e0b448e9a22ba488dcf",
});

const keyName = `cache:cart:${session?.id}`;
if (paymentSuccess) {
await useStorage().removeItem(keyName);
}
}
}
21 changes: 10 additions & 11 deletions domains/checkout/components/CheckoutSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { makeGiftCardPayment, loading: discountLoading } = useDiscount();
const { loadPaymentMethods, paymentProviders } = usePayment();

const selectedProvider = ref<PaymentProvider | null>(null);
const isPaymentReady = ref(false);
const isPaymentWithCardReady = ref(false);
const providerPaymentHandler = ref();
const loading = ref(false);
const showPaymentModal = ref(false);
Expand All @@ -30,12 +30,7 @@ onMounted(async () => {
});

const handleGiftCardPayment = async () => {
const paymentProcessed = await makeGiftCardPayment();
if (paymentProcessed) {
router.push("/thank-you");
} else {
router.push("/payment-fail");
}
await makeGiftCardPayment();
};
</script>

Expand All @@ -46,7 +41,7 @@ const handleGiftCardPayment = async () => {
size="lg"
class="w-full mb-4 md:mb-0"
:disabled="discountLoading"
@click="handleGiftCardPayment"
@click.prevent="handleGiftCardPayment"
>
{{ $t("placeOrder") }}
</SfButton>
Expand All @@ -55,7 +50,7 @@ const handleGiftCardPayment = async () => {
v-else
size="lg"
class="w-full mb-4 md:mb-0"
:disabled="!selectedProvider || !isPaymentReady || loading"
:disabled="!selectedProvider || !isPaymentWithCardReady || loading"
@click="providerPaymentHandler"
>
{{ $t("placeOrder") }}
Expand All @@ -82,12 +77,16 @@ const handleGiftCardPayment = async () => {
</i18n-t>
</p>
<component
v-if="showPaymentModal && !!selectedProvider?.code"
v-if="
showPaymentModal &&
!!selectedProvider?.code &&
!hasFullPaymentWithGiftCard
"
:is="getPaymentProviderComponentName(selectedProvider?.code)"
:key="selectedProvider?.id"
:provider="selectedProvider"
:cart="cart"
@is-payment-ready="($event: any) => (isPaymentReady = $event)"
@is-payment-ready="($event: any) => (isPaymentWithCardReady = $event)"
@provider-payment-handler="
($event: any) => (providerPaymentHandler = $event)
"
Expand Down
28 changes: 17 additions & 11 deletions domains/checkout/composables/useDiscount.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { useToast } from 'vue-toastification';
import { useToast } from "vue-toastification";
import type {
ApplyGiftCardResponse,
ApplyDiscountsResponse,
MakeGiftCardPaymentResponse,
MutationApplyCouponArgs,
MutationApplyGiftCardArgs,
} from '~/graphql';
import { MutationName } from '~/server/mutations';
} from "~/graphql";
import { MutationName } from "~/server/mutations";

export const useDiscount = () => {
const { $sdk } = useNuxtApp();
const toast = useToast();
const router = useRouter();
const { loadCart } = useCart();

const loading = ref(false);

const applyGiftCard = async (promo: MutationApplyGiftCardArgs) => {
return $sdk().odoo.mutation<
MutationApplyGiftCardArgs,
ApplyGiftCardResponse
ApplyDiscountsResponse
>({ mutationName: MutationName.ApplyGiftCardMutation }, promo);
};

const applyCoupon = async (promo: MutationApplyCouponArgs) => {
return $sdk().odoo.mutation<MutationApplyCouponArgs, ApplyGiftCardResponse>(
{ mutationName: MutationName.ApplyCouponMutation },
promo
);
return $sdk().odoo.mutation<
MutationApplyCouponArgs,
ApplyDiscountsResponse
>({ mutationName: MutationName.ApplyCouponMutation }, promo);
};

const applyDiscount = async (promoCode: string) => {
Expand All @@ -43,7 +44,7 @@ export const useDiscount = () => {
}

await loadCart(false);
toast.success('Promotion has been applied!');
toast.success("Promotion has been applied!");
};

const makeGiftCardPayment = async () => {
Expand All @@ -61,7 +62,12 @@ export const useDiscount = () => {
return;
}

return data.value;
if (!data.value.makeGiftCardPayment.done) {
router.push("/payment-fail");
return;
}

router.push("/thank-you");
};

return {
Expand Down
2 changes: 1 addition & 1 deletion graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type ApplyDiscountsResponse = AsyncData<
>;
export type MakeGiftCardPaymentResponse = AsyncData<
{
done: Boolean;
makeGiftCardPayment: { done: Boolean };
},
H3Error
>;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"dependencies": {
"@adyen/adyen-web": "4.7.3",
"@erpgap/odoo-sdk": "^0.7.0",
"@erpgap/odoo-sdk-api-client": "^0.7.0",
"@erpgap/odoo-sdk": "^2.0.4",
"@erpgap/odoo-sdk-api-client": "^2.0.4",
"@nuxt/image": "^1.7.0",
"@nuxt/scripts": "^0.4.3",
"@nuxtjs/algolia": "^1.10.2",
Expand Down
47 changes: 11 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,10 @@
enabled "2.0.x"
kuler "^2.0.0"

"@erpgap/odoo-sdk-api-client@^0.7.0":
version "0.7.2"
resolved "https://registry.yarnpkg.com/@erpgap/odoo-sdk-api-client/-/odoo-sdk-api-client-0.7.2.tgz#fbd1715964302a52afbd55158cb77f86489bd979"
integrity sha512-VXak6dhGh4PComFE6ZMuGt4DRX2tgXA54hmmQ0UVY5nYOkySk8+tgMaXtl57F4+BmfPOvKAyu9MiA/gv7bqxXQ==
"@erpgap/odoo-sdk-api-client@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@erpgap/odoo-sdk-api-client/-/odoo-sdk-api-client-2.0.4.tgz#b78954027ceeefdca65ad04f97bea33dace90bc8"
integrity sha512-bt0/ACjX3R6lsI1H6tI/90jnm2jYA4SXQuwJGoQn8SzLkWhoqbfpz4n9lBNGfZ3INHt6Q+IdrLMrFZ24NaZhvQ==
dependencies:
"@apollo/client" "^3.9.9"
"@vue-storefront/middleware" "3.5.1"
Expand All @@ -1108,10 +1108,10 @@
request-ip "^3.3.0"
winston "^3.9.0"

"@erpgap/odoo-sdk@^0.7.0":
version "0.7.2"
resolved "https://registry.yarnpkg.com/@erpgap/odoo-sdk/-/odoo-sdk-0.7.2.tgz#a2644ec652176eb4f6a81761276614af5713c398"
integrity sha512-t0g0s/gVmKuFQKcqoc+NFBhUgImWCLxiKdpahZtwBjgENHVx8FhIeNzNVs+mTmCUfHtUOybjH3pwNWnRLvOSBg==
"@erpgap/odoo-sdk@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@erpgap/odoo-sdk/-/odoo-sdk-2.0.4.tgz#5c98a6918bc4ba76d1c8dba09fce7ec64117189f"
integrity sha512-LxzAYOn+9iAh1fuaNk95+vA5/sAqDTwcxyqmExtgzda+p+Q0yh2xkOg1cR4UIseFwJrinr+PKq5oKxXpk48IIw==
dependencies:
"@apollo/client" "^3.7.16"
axios "^1.4.0"
Expand Down Expand Up @@ -10874,16 +10874,7 @@ string-env-interpolation@^1.0.1:
resolved "https://registry.yarnpkg.com/string-env-interpolation/-/string-env-interpolation-1.0.1.tgz#ad4397ae4ac53fe6c91d1402ad6f6a52862c7152"
integrity sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -10920,14 +10911,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -12061,7 +12045,7 @@ winston@^3.9.0:
triple-beam "^1.3.0"
winston-transport "^4.7.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -12079,15 +12063,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down