v0.1.2: checkout fixes for CMS v0.2.0 (#18)
build / test (push) Successful in 10s
build / build (push) Successful in 1m5s

Co-authored-by: Michael Czechowski <mail@librete.ch>
This commit was merged in pull request #18.
This commit is contained in:
libretech authored and Michael Czechowski committed 2026-10-15 10:23:27 +02:00
1 parent 60b8f1ab58
commit fccff147ba
29 files changed
+1108 -71

No files matched your search

+13 -4
View File
@@ -64,7 +64,7 @@
<div v-else>
<div v-if="!hasPaymentError" id="paypal-button-container" class="payment sticky top-4" ref="paymentContainer"></div>
<div v-else class="p-4 lg:p-8 text-center mx-auto rounded-md bg-rose-100" data-e2e="payment-error">
<span class="text-rose-800">Es ist ein Fehler aufgetreten. Bitte versuche es erneut.</span>
<span class="text-rose-800">{{ paymentErrorMessage || "Es ist ein Fehler aufgetreten. Bitte versuche es erneut." }}</span>
</div>
<!-- Trust signals -->
@@ -190,6 +190,8 @@
<script setup lang="ts">
import { numberFormatter } from "~/utils/numberFormatter";
import { trackEvent } from "~/utils/trackEvent";
import { checkoutErrorMessageFor } from "~/utils/checkoutError";
import { isAlreadyCaptured } from "~/utils/captureResponse";
import type { Order } from "~/types";
const config = useRuntimeConfig();
@@ -197,6 +199,7 @@ const shopApi = useShopApi();
const CART_UUID_KEY = "shop:cart";
const hasPaymentError = ref(false);
const paymentErrorMessage = ref("");
const hasOrderError = ref(false);
const hasAuthorisedPayment = ref(false);
const orderData = ref<Order>({} as Order);
@@ -298,6 +301,7 @@ async function initializePayPalButtons() {
return response.id;
} catch (error) {
console.error("Error creating PayPal order:", error);
paymentErrorMessage.value = checkoutErrorMessageFor(error);
hasPaymentError.value = true;
trackEvent("checkout-payment-error", {
stage: "create-order",
@@ -309,10 +313,14 @@ async function initializePayPalButtons() {
onApprove: async (data) => {
try {
// Capture payment server-side (CMS captures via PayPal server SDK and updates order)
const capturedOrder = await shopApi.capturePayment(orderData.value.uuid, data.orderID!);
const captured = await shopApi.capturePayment(orderData.value.uuid, data.orderID!);
if (capturedOrder.paymentAuthorised) {
orderData.value = capturedOrder;
if (isAlreadyCaptured(captured)) {
// An earlier capture of this PayPal order went through: reload the paid order, keeping the shown one if that fails.
orderData.value = await shopApi.getOrder(orderData.value.uuid).catch(() => orderData.value);
await handleSuccessfulPayment();
} else if (captured.paymentAuthorised) {
orderData.value = captured;
await handleSuccessfulPayment();
} else {
console.error("Payment capture did not result in authorisation");
@@ -324,6 +332,7 @@ async function initializePayPalButtons() {
}
} catch (error) {
console.error("Error capturing payment:", error);
paymentErrorMessage.value = checkoutErrorMessageFor(error);
hasPaymentError.value = true;
trackEvent("checkout-payment-error", {
stage: "capture-exception",