fix: make payment event reduction monotonic
This commit is contained in:
@@ -84,8 +84,17 @@ export function databasePaymentStore(database = "default"): PaymentStore {
|
||||
async appendEvent(row) {
|
||||
try {
|
||||
const result = await db().exec(
|
||||
"INSERT INTO wrn_payment_event (id,intent_id,type,status,created_at,payload_json) VALUES (?,?,?,?,?,?) ON CONFLICT(id) DO NOTHING",
|
||||
[row.id, row.intentId, row.type, row.status, row.at, JSON.stringify(row.payload ?? null)],
|
||||
"INSERT INTO wrn_payment_event (id,intent_id,type,status,created_at,occurred_at,gateway_sequence,payload_json) VALUES (?,?,?,?,?,?,?,?) ON CONFLICT(id) DO NOTHING",
|
||||
[
|
||||
row.id,
|
||||
row.intentId,
|
||||
row.type,
|
||||
row.status,
|
||||
row.at,
|
||||
row.occurredAt ?? row.at,
|
||||
row.sequence === undefined ? null : String(row.sequence),
|
||||
JSON.stringify(row.payload ?? null),
|
||||
],
|
||||
);
|
||||
return result.changes > 0;
|
||||
} catch {
|
||||
@@ -95,7 +104,7 @@ export function databasePaymentStore(database = "default"): PaymentStore {
|
||||
async events(id) {
|
||||
return (
|
||||
await db().all<any>(
|
||||
"SELECT * FROM wrn_payment_event WHERE intent_id = ? ORDER BY created_at ASC, id ASC",
|
||||
"SELECT * FROM wrn_payment_event WHERE intent_id = ? ORDER BY occurred_at ASC, gateway_sequence ASC, id ASC",
|
||||
[id],
|
||||
)
|
||||
).map((row) => ({
|
||||
@@ -104,6 +113,8 @@ export function databasePaymentStore(database = "default"): PaymentStore {
|
||||
type: String(row.type),
|
||||
status: row.status,
|
||||
at: Number(row.created_at),
|
||||
occurredAt: Number(row.occurred_at ?? row.created_at),
|
||||
sequence: row.gateway_sequence == null ? undefined : String(row.gateway_sequence),
|
||||
payload: parse(row.payload_json, null),
|
||||
}));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user