Merge pull request 'fix(shop): accept an order without a payment method (BIT-30361)' (#305) from task/BIT-30361-manual-payment into main
ci / rust (push) Successful in 4m24s
ci / typescript (push) Successful in 10m41s

This commit was merged in pull request #305.
This commit is contained in:
spark committed 2026-11-25 01:44:18 +00:00
commit 452d84bff2
7 files changed
+62 -2

No files matched your search

+11
View File
@@ -388,6 +388,17 @@ export async function registerShopAdminRoutes(app: FastifyInstance, deps: { db:
return { orders: views };
});
/** Payment collected outside the shop. Delivery starts; the admin owns handing the work over. */
app.post("/v1/orders/:id/payment-received", { preHandler: authenticate }, async (req) => {
const { id } = IdParams.parse(req.params);
const order = await db.order.findUnique({ where: { id } });
if (!order) throw notFound("order_not_found");
await requireMembership(db, req, order.organizationId, "ADMIN");
if (order.status !== "PENDING") throw badRequest("order_not_pending");
await shop.markPaid(id, "manual");
return shop.orderView(id, null);
});
app.post("/v1/orders/:id/items/:itemId/shipped", { preHandler: authenticate }, async (req) => {
const { id, itemId } = z.object({ id: z.uuid(), itemId: z.uuid() }).parse(req.params);
const order = await db.order.findUnique({ where: { id }, include: { items: { where: { id: itemId } } } });
+6 -1
View File
@@ -497,7 +497,12 @@ export class ShopService {
await this.markPaid(order.id, press ? "press" : "free");
return { order: await this.orderView(order.id, order.accessToken), checkoutUrl: null, token: order.accessToken };
}
if (!org.stripeSecretSealed || !secrets) throw new ShopError("payments_not_configured", 503);
// No payment method: the order is still accepted. An admin collects the money out of band
// and only then does delivery start. Invoicing stays off until a provider is connected.
if (!org.stripeSecretSealed || !secrets) {
this.deps.log.info({ orderId: order.id }, "shop: order accepted without a payment method");
return { order: await this.orderView(order.id, order.accessToken), checkoutUrl: null, token: order.accessToken };
}
const checkout = await createCheckout(
secrets.open(org.stripeSecretSealed),
{
+25
View File
@@ -212,6 +212,31 @@ describe("shop", () => {
expect((await ctx.db.order.findUniqueOrThrow({ where: { id: order.id } })).status).toBe("FULFILLED");
});
it("accepts an order when Stripe is off, and delivery waits until an admin records the payment", async () => {
const s = await setup();
expect((await s.api("PUT", `/v1/orgs/${s.orgId}/shop-settings`, { stripeSecretKey: "", stripeWebhookSecret: "" })).statusCode).toBe(200);
const g = await gallery(s, { title: "Sem Stripe" });
const created = await pub("POST", "/v1/public/orders", {
gallery: g.slug,
email: "[email protected]",
name: "Ana Costa",
country: "PT",
items: [{ photoId: s.photos[0], productId: s.digital.id, quantity: 1 }],
});
expect(created.statusCode).toBe(201);
const body = created.json() as { order: { id: string; status: string; totalCents: number }; checkoutUrl: string | null };
expect(body.checkoutUrl).toBeNull();
expect(body.order).toMatchObject({ status: "PENDING" });
expect(body.order.totalCents).toBeGreaterThan(0);
expect(await shop.claimDownloads(5)).toEqual([]);
const paid = await s.api("POST", `/v1/orders/${body.order.id}/payment-received`);
expect(paid.statusCode).toBe(200);
expect(paid.json()).toMatchObject({ status: "PAID" });
const [itemId] = await shop.claimDownloads(5);
expect(itemId).toEqual(expect.any(String));
});
it("reverse-charges VAT for EU businesses with a valid number, and gives free galleries away", async () => {
const s = await setup();
const g = await gallery(s, { title: "Clube" });
+2
View File
@@ -1113,6 +1113,8 @@ export const t = {
orderStatus: { PENDING: "por pagar", PAID: "paga", FULFILLED: "concluída", CANCELLED: "cancelada", REFUNDED: "reembolsada" },
itemStatus: { PENDING: "a preparar", RUNNING: "a preparar", READY: "pronto", SHIPPED: "enviado", FAILED: "falhou" },
markShipped: "Marcar enviada",
collectPayment: "Pagamento recebido",
confirmCollectPayment: "Recebeste o pagamento fora da loja? A encomenda passa a paga e ficas responsável por entregar o trabalho.",
reverseCharge: "Autoliquidação",
noOrders: "Sem encomendas.",
productsHelp: "Preços com IVA incluído. JPEG: tamanho do lado maior (0 = original). Impressões: tamanho e prazo de envio.",
+10
View File
@@ -387,6 +387,16 @@ function Orders({ orgId, isAdmin }: { orgId: string; isAdmin: boolean }) {
{o.invoice.number}
</a>
)}
{isAdmin && o.status === "PENDING" && !o.checkoutUrl && o.totalCents > 0 && (
<button
className="ml-3 underline"
onClick={() => {
if (window.confirm(t.shop.confirmCollectPayment)) void api.recordPayment(o.id).then(replace);
}}
>
{t.shop.collectPayment}
</button>
)}
{isAdmin && (o.status === "PAID" || o.status === "FULFILLED") && (
<button
className="ml-3 underline"
+3 -1
View File
@@ -39,7 +39,9 @@ export default async function OrderPage({ params, searchParams }: { params: Prom
</header>
{order.status === "PENDING" && (
<p className="notice" style={{ marginTop: 24 }}>
Assim que o pagamento for confirmado (por Multibanco pode demorar algumas horas) as fotos aparecem aqui e enviamos-te um email.
{order.checkoutUrl
? "Assim que o pagamento for confirmado (por Multibanco pode demorar algumas horas) as fotos aparecem aqui e enviamos-te um email."
: "A encomenda ficou registada. O pagamento combina-se à parte; quando estiver confirmado, as fotos aparecem aqui e enviamos-te um email."}
{order.checkoutUrl && (
<>
{" "}
+5
View File
@@ -591,6 +591,11 @@ export class ApiClient {
return this.request<OrderView>("POST", `/v1/orders/${orderId}/items/${itemId}/shipped`);
}
/** Payment taken outside the shop. The caller is responsible for delivering the work. */
recordPayment(orderId: string) {
return this.request<OrderView>("POST", `/v1/orders/${orderId}/payment-received`);
}
retryOrder(orderId: string) {
return this.request<OrderView>("POST", `/v1/orders/${orderId}/retry`);
}