@open-mercato/core 0.9.1-develop.7467.1.3b2bb92d47 → 0.9.1-develop.7469.1.cdaab9b883
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/payment_gateways/migrations/Migration20261009120000_payment_gateways.js +53 -0
- package/dist/modules/payment_gateways/migrations/Migration20261009120000_payment_gateways.js.map +7 -0
- package/dist/modules/sales/commands/documents.js +6 -3
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/lib/convertedOrderTotals.js +51 -0
- package/dist/modules/sales/lib/convertedOrderTotals.js.map +7 -0
- package/package.json +7 -7
- package/src/modules/payment_gateways/migrations/Migration20261009120000_payment_gateways.ts +53 -0
- package/src/modules/sales/commands/documents.ts +6 -3
- package/src/modules/sales/lib/convertedOrderTotals.ts +79 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Migration } from "@mikro-orm/migrations";
|
|
2
|
+
const WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE = "gateway_webhook_events_idempotency_unique";
|
|
3
|
+
class Migration20261009120000_payment_gateways extends Migration {
|
|
4
|
+
async up() {
|
|
5
|
+
this.addSql(`lock table "gateway_webhook_events" in share row exclusive mode;`);
|
|
6
|
+
this.addSql(`
|
|
7
|
+
delete from "gateway_webhook_events" duplicate
|
|
8
|
+
using (
|
|
9
|
+
select
|
|
10
|
+
event."id",
|
|
11
|
+
row_number() over (
|
|
12
|
+
partition by event."idempotency_key", event."provider_key", event."organization_id", event."tenant_id"
|
|
13
|
+
order by event."processed_at" asc, event."id" asc
|
|
14
|
+
) as claim_rank
|
|
15
|
+
from "gateway_webhook_events" event
|
|
16
|
+
) ranked
|
|
17
|
+
where duplicate."id" = ranked."id"
|
|
18
|
+
and ranked.claim_rank > 1;
|
|
19
|
+
`);
|
|
20
|
+
this.addSql(`
|
|
21
|
+
do $$
|
|
22
|
+
begin
|
|
23
|
+
if exists (
|
|
24
|
+
select 1
|
|
25
|
+
from pg_constraint
|
|
26
|
+
where conname = '${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}'
|
|
27
|
+
and conrelid = to_regclass('"gateway_webhook_events"')
|
|
28
|
+
and contype = 'u'
|
|
29
|
+
) then
|
|
30
|
+
return;
|
|
31
|
+
end if;
|
|
32
|
+
drop index if exists "${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}";
|
|
33
|
+
alter table "gateway_webhook_events"
|
|
34
|
+
add constraint "${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}"
|
|
35
|
+
unique ("idempotency_key", "provider_key", "organization_id", "tenant_id");
|
|
36
|
+
end
|
|
37
|
+
$$;
|
|
38
|
+
`);
|
|
39
|
+
}
|
|
40
|
+
async down() {
|
|
41
|
+
this.addSql(
|
|
42
|
+
`alter table "gateway_webhook_events" drop constraint if exists "${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}";`
|
|
43
|
+
);
|
|
44
|
+
this.addSql(
|
|
45
|
+
`create index if not exists "${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}" on "gateway_webhook_events" ("idempotency_key", "provider_key", "organization_id", "tenant_id");`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
Migration20261009120000_payment_gateways,
|
|
51
|
+
WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=Migration20261009120000_payment_gateways.js.map
|
package/dist/modules/payment_gateways/migrations/Migration20261009120000_payment_gateways.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/payment_gateways/migrations/Migration20261009120000_payment_gateways.ts"],
|
|
4
|
+
"sourcesContent": ["import { Migration } from '@mikro-orm/migrations'\n\nexport const WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE = 'gateway_webhook_events_idempotency_unique'\n\nexport class Migration20261009120000_payment_gateways extends Migration {\n override async up(): Promise<void> {\n this.addSql(`lock table \"gateway_webhook_events\" in share row exclusive mode;`)\n\n this.addSql(`\n delete from \"gateway_webhook_events\" duplicate\n using (\n select\n event.\"id\",\n row_number() over (\n partition by event.\"idempotency_key\", event.\"provider_key\", event.\"organization_id\", event.\"tenant_id\"\n order by event.\"processed_at\" asc, event.\"id\" asc\n ) as claim_rank\n from \"gateway_webhook_events\" event\n ) ranked\n where duplicate.\"id\" = ranked.\"id\"\n and ranked.claim_rank > 1;\n `)\n\n this.addSql(`\n do $$\n begin\n if exists (\n select 1\n from pg_constraint\n where conname = '${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}'\n and conrelid = to_regclass('\"gateway_webhook_events\"')\n and contype = 'u'\n ) then\n return;\n end if;\n drop index if exists \"${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}\";\n alter table \"gateway_webhook_events\"\n add constraint \"${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}\"\n unique (\"idempotency_key\", \"provider_key\", \"organization_id\", \"tenant_id\");\n end\n $$;\n `)\n }\n\n override async down(): Promise<void> {\n this.addSql(\n `alter table \"gateway_webhook_events\" drop constraint if exists \"${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}\";`,\n )\n this.addSql(\n `create index if not exists \"${WEBHOOK_EVENTS_IDEMPOTENCY_UNIQUE}\" on \"gateway_webhook_events\" (\"idempotency_key\", \"provider_key\", \"organization_id\", \"tenant_id\");`,\n )\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAEnB,MAAM,oCAAoC;AAE1C,MAAM,iDAAiD,UAAU;AAAA,EACtE,MAAe,KAAoB;AACjC,SAAK,OAAO,kEAAkE;AAE9E,SAAK,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAaX;AAED,SAAK,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAMa,iCAAiC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAM9B,iCAAiC;AAAA;AAAA,4BAErC,iCAAiC;AAAA;AAAA;AAAA;AAAA,KAIxD;AAAA,EACH;AAAA,EAEA,MAAe,OAAsB;AACnC,SAAK;AAAA,MACH,mEAAmE,iCAAiC;AAAA,IACtG;AACA,SAAK;AAAA,MACH,+BAA+B,iCAAiC;AAAA,IAClE;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -101,6 +101,7 @@ import {
|
|
|
101
101
|
loadPaymentSnapshot,
|
|
102
102
|
restorePaymentSnapshot
|
|
103
103
|
} from "./payments.js";
|
|
104
|
+
import { resolveConvertedOrderFeeTotals } from "../lib/convertedOrderTotals.js";
|
|
104
105
|
import {
|
|
105
106
|
mapOrderLineEntityToSnapshot,
|
|
106
107
|
mapQuoteLineEntityToSnapshot,
|
|
@@ -5026,9 +5027,11 @@ const convertQuoteToOrderCommand = {
|
|
|
5026
5027
|
subtotalGrossAmount: snapshot.quote.subtotalGrossAmount,
|
|
5027
5028
|
discountTotalAmount: snapshot.quote.discountTotalAmount,
|
|
5028
5029
|
taxTotalAmount: snapshot.quote.taxTotalAmount,
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5030
|
+
...resolveConvertedOrderFeeTotals({
|
|
5031
|
+
totalsSnapshot: snapshot.quote.totalsSnapshot,
|
|
5032
|
+
currencyCode: snapshot.quote.currencyCode,
|
|
5033
|
+
adjustments: snapshot.adjustments
|
|
5034
|
+
}),
|
|
5032
5035
|
grandTotalNetAmount: snapshot.quote.grandTotalNetAmount,
|
|
5033
5036
|
grandTotalGrossAmount: snapshot.quote.grandTotalGrossAmount,
|
|
5034
5037
|
paidTotalAmount: "0",
|