This commit is contained in:
lxy 2024-06-26 13:45:37 +08:00
parent ae185dd5a0
commit c58326d980
6 changed files with 33 additions and 23 deletions

View File

@ -208,7 +208,9 @@ async function tryCompleteAccountPay(payId, context) {
await context.operate('pay', {
id: await generateNewIdAsync(),
action: 'succeedPaying',
data: {},
data: {
successAt: Date.now(),
},
filter: {
id: payId2,
}

View File

@ -72,7 +72,8 @@ export default class Account {
getState(pay) {
throw new Error("account类型的pay不应该需要查询此状态");
}
close(pay) {
throw new Error("account类型的pay无法关闭");
async close(pay) {
// throw new Error("account类型的pay无法关闭");
return;
}
}

View File

@ -211,7 +211,9 @@ async function tryCompleteAccountPay(payId, context) {
await context.operate('pay', {
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'succeedPaying',
data: {},
data: {
successAt: Date.now(),
},
filter: {
id: payId2,
}

View File

@ -75,8 +75,9 @@ class Account {
getState(pay) {
throw new Error("account类型的pay不应该需要查询此状态");
}
close(pay) {
throw new Error("account类型的pay无法关闭");
async close(pay) {
// throw new Error("account类型的pay无法关闭");
return;
}
}
exports.default = Account;

View File

@ -201,13 +201,13 @@ async function tryCompleteAccountPay(payId: string, context: BRC) {
const { order } = pay;
if (order) {
const { price, iState, pay$order: pays } = order;
assert(iState === 'paying');
const successfulPayIds: string[] = [];
const accountPayIds: string[] = [];
let totalPaid = 0;
pays?.forEach(
(pay) => {
const { iState, entity, paid, price } = pay;
@ -224,13 +224,15 @@ async function tryCompleteAccountPay(payId: string, context: BRC) {
}
}
);
if (totalPaid === price) {
for (const payId2 of successfulPayIds) {
await context.operate('pay', {
id: await generateNewIdAsync(),
action: 'succeedPaying',
data: {},
data: {
successAt: Date.now(),
},
filter: {
id: payId2,
}
@ -251,7 +253,7 @@ async function tryCompleteAccountPay(payId: string, context: BRC) {
}, {});
}
return accountPayIds.length;
}
}
}
return 0;
}
@ -586,7 +588,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
return cnt;
},
} as UpdateTriggerInTxn<EntityDict, 'pay', BRC>,
} as UpdateTriggerInTxn<EntityDict, 'pay', BRC>,
{
name: '当pay完成支付时计算其refundable和forbidRefundAt',
entity: 'pay',
@ -623,7 +625,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
action: ['startPaying', 'continuePaying', 'succeedPaying'],
attributes: ['paid'],
when: 'after',
fn: async({ operation }, context, option) => {
fn: async ({ operation }, context, option) => {
const { filter } = operation;
const ids = getRelevantIds(filter!);
assert(ids.length === 1);
@ -636,12 +638,12 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
name: '当有pay关闭时如果是account类型的将金额还给account否则检查会否测试相关Account pay是否需要关闭',
action: 'close',
when: 'after',
fn: async({ operation }, context, option) => {
fn: async ({ operation }, context, option) => {
const { filter } = operation;
const ids = getRelevantIds(filter!);
assert(ids.length === 1);
const [ pay ] = await context.select('pay', {
const [pay] = await context.select('pay', {
data: {
id: 1,
price: 1,

View File

@ -34,12 +34,13 @@ export default class Account implements PayClazz {
return ['refuding', undefined];
}
decodePayNotification(params: Record<string, any>, body: any): Promise<{
payId: string;
iState: string | null | undefined;
extra?: EntityDict['pay']['Update']['data'] | undefined; }> {
payId: string;
iState: string | null | undefined;
extra?: EntityDict['pay']['Update']['data'] | undefined;
}> {
throw new Error("account类型的pay不需调用此接口");
}
async prepay(pay: EntityDict['pay']['Schema'], data: EntityDict['pay']['Update']['data'], context: BRC) {
const { entity, entityId, price } = pay;
assert(entity === 'account' && entityId);
@ -77,13 +78,14 @@ export default class Account implements PayClazz {
data.meta = {};
data.paid = paid;
}
}
}
getState(pay: EntityDict['pay']['Schema']): Promise<[string, EntityDict['pay']['Update']['data']]> {
throw new Error("account类型的pay不应该需要查询此状态");
}
close(pay: EntityDict['pay']['Schema']): Promise<void> {
throw new Error("account类型的pay无法关闭");
async close(pay: EntityDict['pay']['Schema']): Promise<void> {
// throw new Error("account类型的pay无法关闭");
return;
}
}