rapida-partner 8.14.0 → 8.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -13,6 +13,22 @@ export type TStoreDeliveryMethod = "delivery" | "pickup";
|
|
|
13
13
|
/** Como o cliente paga: online (Mercado Pago) ou na entrega/retirada. */
|
|
14
14
|
export type TStorePaymentMethod = "online" | "onDelivery";
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Forma de pagamento detalhada escolhida no pedido (balcão, mesa ou checkout).
|
|
18
|
+
* Só aparecem as formas que o cliente ligou em IStoreSettings.paymentChoices.
|
|
19
|
+
* - "debitCard" e "creditCard": na maquininha.
|
|
20
|
+
* - "pixTerminal": Pix na maquininha (com taxa e prazo D+0).
|
|
21
|
+
* - "pixDirect": Pix direto para a chave da loja (IStoreSettings.pixKey), sem taxa.
|
|
22
|
+
* - "cash": dinheiro, com troco em changeFor.
|
|
23
|
+
*/
|
|
24
|
+
export type TStorePaymentChoice = "debitCard" | "creditCard" | "pixTerminal" | "pixDirect" | "cash";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Destino do pedido na mesa: comer no local ou levar para casa. Obrigatório
|
|
28
|
+
* no checkout da mesa; sem ele o pedido não é confirmado.
|
|
29
|
+
*/
|
|
30
|
+
export type TStoreConsumptionMode = "dineIn" | "takeaway";
|
|
31
|
+
|
|
16
32
|
/**
|
|
17
33
|
* Meio do pagamento online, informado pelo Mercado Pago (Fase 8.1), para o
|
|
18
34
|
* vendedor ver "Pago no Pix" ou "Pago no cartão". Veja storeOnlinePaymentTypeOf.
|
|
@@ -129,6 +145,10 @@ export interface IStoreOrder {
|
|
|
129
145
|
// pagamento: changeFor é o valor para o troco, e o vendedor marca
|
|
130
146
|
// paymentReceived quando receber.
|
|
131
147
|
paymentMethod?: TStorePaymentMethod;
|
|
148
|
+
// Forma detalhada escolhida (Pagamentos por pedido, fase 1); vazio em pedidos anteriores.
|
|
149
|
+
paymentChoice?: TStorePaymentChoice;
|
|
150
|
+
// Destino na mesa (fase 1): vazio fora da mesa.
|
|
151
|
+
consumptionMode?: TStoreConsumptionMode;
|
|
132
152
|
changeFor?: number;
|
|
133
153
|
paymentReceived?: boolean;
|
|
134
154
|
// Meio do pagamento online (Fase 8.1); vazio no pagamento na entrega.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TStorePaymentChoice } from "./store-order.interface";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Funcionalidades opcionais da loja (`skeleton` "ecommerce" ou "marketplace").
|
|
3
5
|
* Cada uma tem duas camadas: `IProjectStore.features` decide se o código dela é
|
|
@@ -155,6 +157,13 @@ export interface IStoreSettings extends Partial<Record<TStoreFeatureToggle, bool
|
|
|
155
157
|
// a loja deixa de oferecer o pagamento online. Só vale com payOnDeliveryEnabled ligado,
|
|
156
158
|
// para a loja nunca ficar sem forma de pagamento.
|
|
157
159
|
payOnDeliveryOnly?: boolean;
|
|
160
|
+
// Formas de pagamento detalhadas que o cliente liga para o balcão, a mesa e o checkout
|
|
161
|
+
// (Pagamentos por pedido, fase 1). Sem a lista, nenhuma forma detalhada aparece.
|
|
162
|
+
paymentChoices?: TStorePaymentChoice[];
|
|
163
|
+
// Formas da entrega que a loja liga (maquininha e dinheiro). Obrigatória quando o pagamento na entrega está ligado.
|
|
164
|
+
deliveryPaymentChoices?: TStorePaymentChoice[];
|
|
165
|
+
// Chave Pix da loja, usada pela forma "pixDirect" (sem taxa, com confirmação manual pelo vendedor).
|
|
166
|
+
pixKey?: string;
|
|
158
167
|
// Funcionalidade "stockReservation": por quantos minutos o pedido aguardando
|
|
159
168
|
// pagamento segura o estoque (de 5 a 60). Vencido o prazo, o pedido é
|
|
160
169
|
// cancelado, o link de pagamento expira e a quantidade volta. Sem o campo,
|
|
@@ -80,6 +80,17 @@
|
|
|
80
80
|
},
|
|
81
81
|
"minimumOrderValue": { "type": "number", "minimum": 0 },
|
|
82
82
|
"payOnDeliveryOnly": { "type": "boolean" },
|
|
83
|
+
"paymentChoices": {
|
|
84
|
+
"type": "array",
|
|
85
|
+
"uniqueItems": true,
|
|
86
|
+
"items": { "enum": ["debitCard", "creditCard", "pixTerminal", "pixDirect", "cash"] }
|
|
87
|
+
},
|
|
88
|
+
"deliveryPaymentChoices": {
|
|
89
|
+
"type": "array",
|
|
90
|
+
"uniqueItems": true,
|
|
91
|
+
"items": { "enum": ["debitCard", "creditCard", "pixTerminal", "cash"] }
|
|
92
|
+
},
|
|
93
|
+
"pixKey": { "type": "string" },
|
|
83
94
|
"reservationMinutes": { "type": "integer", "minimum": 5, "maximum": 60 },
|
|
84
95
|
"ordersPaused": { "type": "boolean" },
|
|
85
96
|
"aboutText": { "type": "string" },
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import settingsSchema from "../schemas/store-settings.ref.json";
|
|
3
|
+
import {
|
|
4
|
+
isStorePaymentChoiceAllowed,
|
|
5
|
+
STORE_DELIVERY_PAYMENT_CHOICES,
|
|
6
|
+
STORE_PAYMENT_CHOICES,
|
|
7
|
+
storeDeliveryPaymentChoicesOf,
|
|
8
|
+
storePaymentChoicesOf,
|
|
9
|
+
} from "./store-payment";
|
|
10
|
+
|
|
11
|
+
describe("storePaymentChoicesOf", () => {
|
|
12
|
+
test("mostra só as formas ligadas, na ordem do balcão", () => {
|
|
13
|
+
expect(storePaymentChoicesOf({ paymentChoices: ["creditCard", "cash"], pixKey: "chave" })).toEqual(["cash", "creditCard"]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("sem lista, nenhuma forma detalhada aparece", () => {
|
|
17
|
+
expect(storePaymentChoicesOf({})).toEqual([]);
|
|
18
|
+
expect(storePaymentChoicesOf({ paymentChoices: [] })).toEqual([]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("Pix direto some sem chave da loja, mesmo ligado", () => {
|
|
22
|
+
expect(storePaymentChoicesOf({ paymentChoices: ["pixDirect", "debitCard"] })).toEqual(["debitCard"]);
|
|
23
|
+
expect(storePaymentChoicesOf({ paymentChoices: ["pixDirect"], pixKey: " " })).toEqual([]);
|
|
24
|
+
expect(storePaymentChoicesOf({ paymentChoices: ["pixDirect"], pixKey: "11999999999" })).toEqual(["pixDirect"]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("repetição na lista não duplica a forma", () => {
|
|
28
|
+
expect(storePaymentChoicesOf({ paymentChoices: ["cash", "cash"] })).toEqual(["cash"]);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("storeDeliveryPaymentChoicesOf", () => {
|
|
33
|
+
test("só as formas da entrega, na ordem do checkout; Pix direto nunca entra", () => {
|
|
34
|
+
expect(storeDeliveryPaymentChoicesOf({ deliveryPaymentChoices: ["cash", "debitCard"] })).toEqual(["debitCard", "cash"]);
|
|
35
|
+
expect(storeDeliveryPaymentChoicesOf({ deliveryPaymentChoices: ["pixDirect" as never] })).toEqual([]);
|
|
36
|
+
expect(storeDeliveryPaymentChoicesOf({})).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("isStorePaymentChoiceAllowed", () => {
|
|
41
|
+
test("no balcão e na mesa, aceita só forma ligada e com destino", () => {
|
|
42
|
+
const settings = { paymentChoices: ["pixTerminal" as const, "pixDirect" as const] };
|
|
43
|
+
expect(isStorePaymentChoiceAllowed("pixTerminal", settings, "counter")).toBe(true);
|
|
44
|
+
expect(isStorePaymentChoiceAllowed("pixDirect", settings, "counter")).toBe(false);
|
|
45
|
+
expect(isStorePaymentChoiceAllowed("cash", settings, "counter")).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("na entrega, vale deliveryPaymentChoices, não paymentChoices", () => {
|
|
49
|
+
const settings = { paymentChoices: ["debitCard" as const], deliveryPaymentChoices: ["cash" as const] };
|
|
50
|
+
expect(isStorePaymentChoiceAllowed("cash", settings, "delivery")).toBe(true);
|
|
51
|
+
expect(isStorePaymentChoiceAllowed("cash", settings, "counter")).toBe(false);
|
|
52
|
+
expect(isStorePaymentChoiceAllowed("debitCard", settings, "delivery")).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("na entrega, Pix direto nunca vale, mesmo com chave da loja", () => {
|
|
56
|
+
const settings = { deliveryPaymentChoices: ["pixDirect" as never], pixKey: "11999999999" };
|
|
57
|
+
expect(isStorePaymentChoiceAllowed("pixDirect", settings, "delivery")).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("store-settings.ref.json", () => {
|
|
62
|
+
const enumOf = (property: "paymentChoices" | "deliveryPaymentChoices"): string[] =>
|
|
63
|
+
[...settingsSchema.properties[property].items.enum].sort();
|
|
64
|
+
|
|
65
|
+
test("o enum de paymentChoices tem as mesmas formas de STORE_PAYMENT_CHOICES", () => {
|
|
66
|
+
expect(enumOf("paymentChoices")).toEqual([...STORE_PAYMENT_CHOICES].sort());
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("o enum de deliveryPaymentChoices tem as mesmas formas de STORE_DELIVERY_PAYMENT_CHOICES", () => {
|
|
70
|
+
expect(enumOf("deliveryPaymentChoices")).toEqual([...STORE_DELIVERY_PAYMENT_CHOICES].sort());
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { TStoreConsumptionMode, TStorePaymentChoice } from "../interfaces/store-order.interface";
|
|
2
|
+
import type { IStoreSettings } from "../interfaces/store-settings.interface";
|
|
3
|
+
|
|
4
|
+
/** Formas detalhadas de pagamento, na ordem em que aparecem no balcão e no checkout. */
|
|
5
|
+
export const STORE_PAYMENT_CHOICES: TStorePaymentChoice[] = ["cash", "debitCard", "creditCard", "pixTerminal", "pixDirect"];
|
|
6
|
+
|
|
7
|
+
/** Formas que existem na entrega (maquininha e dinheiro), na ordem do checkout. Pix direto não entra. */
|
|
8
|
+
export const STORE_DELIVERY_PAYMENT_CHOICES: TStorePaymentChoice[] = ["debitCard", "creditCard", "pixTerminal", "cash"];
|
|
9
|
+
|
|
10
|
+
/** Destinos do pedido na mesa, na ordem do checkout. */
|
|
11
|
+
export const STORE_CONSUMPTION_MODES: TStoreConsumptionMode[] = ["dineIn", "takeaway"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Formas que a loja aceita de fato: só as ligadas em paymentChoices, sem repetição
|
|
15
|
+
* e na ordem de STORE_PAYMENT_CHOICES. "pixDirect" só entra com pixKey preenchida,
|
|
16
|
+
* para a loja nunca mostrar um Pix sem destino.
|
|
17
|
+
*/
|
|
18
|
+
export const storePaymentChoicesOf = (settings: Pick<IStoreSettings, "paymentChoices" | "pixKey">): TStorePaymentChoice[] => {
|
|
19
|
+
const enabled = new Set(settings.paymentChoices ?? []);
|
|
20
|
+
const hasPixKey = (settings.pixKey ?? "").trim().length > 0;
|
|
21
|
+
return STORE_PAYMENT_CHOICES.filter((choice) => enabled.has(choice) && (choice !== "pixDirect" || hasPixKey));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Formas da entrega que a loja liga (deliveryPaymentChoices), sem repetição e na ordem do checkout.
|
|
26
|
+
* Pix direto nunca entra: a entrega só aceita maquininha e dinheiro.
|
|
27
|
+
*/
|
|
28
|
+
export const storeDeliveryPaymentChoicesOf = (settings: Pick<IStoreSettings, "deliveryPaymentChoices">): TStorePaymentChoice[] => {
|
|
29
|
+
const enabled = new Set(settings.deliveryPaymentChoices ?? []);
|
|
30
|
+
return STORE_DELIVERY_PAYMENT_CHOICES.filter((choice) => enabled.has(choice));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Onde o pedido é pago: "counter" no balcão e na mesa (paymentChoices) e
|
|
35
|
+
* "delivery" na entrega (deliveryPaymentChoices).
|
|
36
|
+
*/
|
|
37
|
+
export type TStorePaymentContext = "counter" | "delivery";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Vale gravar a forma no pedido: ela precisa estar entre as formas que a loja aceita
|
|
41
|
+
* onde o pedido é pago. No balcão e na mesa valem as de paymentChoices; na entrega,
|
|
42
|
+
* as de deliveryPaymentChoices.
|
|
43
|
+
*/
|
|
44
|
+
export const isStorePaymentChoiceAllowed = (
|
|
45
|
+
choice: TStorePaymentChoice,
|
|
46
|
+
settings: Pick<IStoreSettings, "paymentChoices" | "deliveryPaymentChoices" | "pixKey">,
|
|
47
|
+
context: TStorePaymentContext,
|
|
48
|
+
): boolean =>
|
|
49
|
+
(context === "delivery" ? storeDeliveryPaymentChoicesOf(settings) : storePaymentChoicesOf(settings)).includes(choice);
|