Skip to content

Commit

Permalink
Add a field terminalId to distinguish the device
Browse files Browse the repository at this point in the history
  • Loading branch information
danial303065 authored and MichaelKim20 committed Aug 22, 2024
1 parent ee32595 commit 699ffd1
Show file tree
Hide file tree
Showing 22 changed files with 178 additions and 1,265 deletions.
3 changes: 0 additions & 3 deletions packages/relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@
- 상점의 정산 정보 조회
- 상점의 인출 정보 조회

## 3. 마일리지를 사용한 결제 프로세스

[마일리지를 사용한 결제 프로세스](docs%2Floyalty-payment.md)
Binary file removed packages/relay/docs/loyalty-pament-diagram01.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram02.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram03.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram04.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram10.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram21.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram22.png
Binary file not shown.
Binary file removed packages/relay/docs/loyalty-pament-diagram23.png
Binary file not shown.
1,262 changes: 0 additions & 1,262 deletions packages/relay/docs/loyalty-payment.md

This file was deleted.

19 changes: 19 additions & 0 deletions packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ export class PaymentRouter {
const purchaseId: string = String(req.body.purchaseId).trim();
const amount: BigNumber = BigNumber.from(req.body.amount);
const currency: string = String(req.body.currency).trim();
const terminalId: string = req.body.terminalId !== undefined ? String(req.body.terminalId).trim() : "";

const feeRate = await this.contractManager.sideLedgerContract.getPaymentFee();
const rate = await this.contractManager.sideCurrencyRateContract.get(currency.toLowerCase());
Expand Down Expand Up @@ -505,6 +506,7 @@ export class PaymentRouter {
feeValue,
totalPoint,
totalValue,
terminalId,
paymentStatus: LoyaltyPaymentTaskStatus.OPENED_NEW,
contractStatus: ContractLoyaltyPaymentStatus.INVALID,
openNewTimestamp: ContractUtils.getTimeStamp(),
Expand Down Expand Up @@ -739,6 +741,7 @@ export class PaymentRouter {
currency: item.currency,
shopId: item.shopId,
account: item.account,
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
})
);
Expand Down Expand Up @@ -810,6 +813,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -848,6 +852,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -903,6 +908,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -998,6 +1004,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -1034,6 +1041,7 @@ export class PaymentRouter {
}

const paymentId: string = String(req.body.paymentId).trim();
const terminalId: string = req.body.terminalId !== undefined ? String(req.body.terminalId).trim() : "";
const item = await this.storage.getPayment(paymentId);
if (item === undefined) {
return res.status(200).json(ResponseMessage.getErrorMessage("2003"));
Expand All @@ -1048,6 +1056,9 @@ export class PaymentRouter {
return res.status(200).json(ResponseMessage.getErrorMessage("2022"));
}

item.terminalId = terminalId;
await this.storage.updateTerminalId(item.paymentId, item.terminalId);

item.paymentStatus = LoyaltyPaymentTaskStatus.OPENED_CANCEL;
item.openCancelTimestamp = ContractUtils.getTimeStamp();
await this.storage.updateOpenCancelTimestamp(
Expand Down Expand Up @@ -1085,6 +1096,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -1151,6 +1163,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -1278,6 +1291,7 @@ export class PaymentRouter {
currency: item.currency,
shopId: item.shopId,
account: item.account,
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
txHash: tx.hash,
})
Expand Down Expand Up @@ -1325,6 +1339,7 @@ export class PaymentRouter {
currency: item.currency,
shopId: item.shopId,
account: item.account,
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
})
);
Expand Down Expand Up @@ -1397,6 +1412,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -1435,6 +1451,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -1490,6 +1507,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -1566,6 +1584,7 @@ export class PaymentRouter {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
};
}
Expand Down
14 changes: 14 additions & 0 deletions packages/relay/src/routers/ShopRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ export class ShopRouter {
const currency: string = String(req.body.currency).trim().toLowerCase();
const account: string = String(req.body.account).trim();
const signature: string = String(req.body.signature).trim(); // 서명
const terminalId: string = req.body.terminalId !== undefined ? String(req.body.terminalId).trim() : "";

const taskId = ContractUtils.getTaskId(shopId);
const item: ShopTaskData = {
Expand All @@ -448,6 +449,7 @@ export class ShopRouter {
currency,
status: ContractShopStatus.INVALID,
account,
terminalId,
taskStatus: ShopTaskStatus.OPENED,
timestamp: ContractUtils.getTimeStamp(),
txId: "",
Expand Down Expand Up @@ -532,6 +534,7 @@ export class ShopRouter {
name: item.name,
currency: item.currency,
status: item.status,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
account: item.account,
timestamp: item.timestamp,
Expand Down Expand Up @@ -572,6 +575,7 @@ export class ShopRouter {

const name: string = String(req.body.name).trim();
const currency: string = String(req.body.currency).trim().toLowerCase();
const terminalId: string = req.body.terminalId !== undefined ? String(req.body.terminalId).trim() : "";

const shopInfo = await this.contractManager.sideShopContract.shopOf(shopId);
if (shopInfo.status !== ContractShopStatus.INVALID) {
Expand All @@ -585,6 +589,7 @@ export class ShopRouter {
currency,
status: shopInfo.status,
account: shopInfo.account,
terminalId,
taskStatus: ShopTaskStatus.OPENED,
timestamp: ContractUtils.getTimeStamp(),
txId: "",
Expand Down Expand Up @@ -655,6 +660,7 @@ export class ShopRouter {
shopId: item.shopId,
name: item.name,
currency: item.currency,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
})
Expand Down Expand Up @@ -769,6 +775,7 @@ export class ShopRouter {
shopId: item.shopId,
name: item.name,
currency: item.currency,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
txHash: item.txId,
Expand Down Expand Up @@ -844,6 +851,7 @@ export class ShopRouter {
}

const status: number = Number(String(req.body.status).trim());
const terminalId: string = req.body.terminalId !== undefined ? String(req.body.terminalId).trim() : "";
const shopInfo = await this.contractManager.sideShopContract.shopOf(shopId);
if (shopInfo.status !== 0) {
const taskId = ContractUtils.getTaskId(shopId);
Expand All @@ -856,6 +864,7 @@ export class ShopRouter {
currency: shopInfo.currency,
status,
account: shopInfo.account,
terminalId,
taskStatus: ShopTaskStatus.OPENED,
timestamp: ContractUtils.getTimeStamp(),
txId: "",
Expand All @@ -878,6 +887,7 @@ export class ShopRouter {
taskId: item.taskId,
shopId: item.shopId,
status: item.status,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
})
Expand Down Expand Up @@ -928,6 +938,7 @@ export class ShopRouter {
taskId: item.taskId,
shopId: item.shopId,
status: item.status,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
})
Expand Down Expand Up @@ -1042,6 +1053,7 @@ export class ShopRouter {
taskId: item.taskId,
shopId: item.shopId,
status: item.status,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
txHash: item.txId,
Expand Down Expand Up @@ -1073,6 +1085,7 @@ export class ShopRouter {
taskId: item.taskId,
shopId: item.shopId,
status: item.status,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
})
Expand Down Expand Up @@ -1146,6 +1159,7 @@ export class ShopRouter {
currency: item.currency,
status: item.status,
account: item.account,
terminalId: item.terminalId,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/relay/src/scheduler/WatchScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export class WatchScheduler extends Scheduler {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
};
}
Expand Down Expand Up @@ -474,6 +475,7 @@ export class WatchScheduler extends Scheduler {
currency: item.currency,
status: item.status,
account: item.account,
terminalId: item.terminalId,
};
}
/// endregion
Expand Down
23 changes: 23 additions & 0 deletions packages/relay/src/storage/RelayStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class RelayStorage extends Storage {
feeValue: item.feeValue.toString(),
totalPoint: item.totalPoint.toString(),
totalValue: item.totalValue.toString(),
terminalId: item.terminalId,
paymentStatus: item.paymentStatus,
openNewTimestamp: item.openNewTimestamp,
closeNewTimestamp: item.closeNewTimestamp,
Expand Down Expand Up @@ -117,6 +118,7 @@ export class RelayStorage extends Storage {
feeValue: BigNumber.from(m.feeValue),
totalPoint: BigNumber.from(m.totalPoint),
totalValue: BigNumber.from(m.totalValue),
terminalId: m.terminalId,
paymentStatus: m.paymentStatus,
contractStatus: m.contractStatus,
openNewTimestamp: m.openNewTimestamp,
Expand Down Expand Up @@ -166,6 +168,22 @@ export class RelayStorage extends Storage {
});
}

public updateTerminalId(paymentId: string, terminalId: string): Promise<any> {
return new Promise<void>(async (resolve, reject) => {
this.queryForMapper("payment", "updateTerminal", {
paymentId,
terminalId,
})
.then(() => {
return resolve();
})
.catch((reason) => {
if (reason instanceof Error) return reject(reason);
return reject(new Error(reason));
});
});
}

public updatePaymentStatus(paymentId: string, paymentStatus: LoyaltyPaymentTaskStatus): Promise<any> {
return new Promise<void>(async (resolve, reject) => {
this.queryForMapper("payment", "updateStatus", {
Expand Down Expand Up @@ -407,6 +425,7 @@ export class RelayStorage extends Storage {
feeValue: BigNumber.from(m.feeValue),
totalPoint: BigNumber.from(m.totalPoint),
totalValue: BigNumber.from(m.totalValue),
terminalId: m.terminalId,
paymentStatus: m.paymentStatus,
contractStatus: m.contractStatus,
openNewTimestamp: m.openNewTimestamp,
Expand Down Expand Up @@ -452,6 +471,7 @@ export class RelayStorage extends Storage {
feeValue: BigNumber.from(m.feeValue),
totalPoint: BigNumber.from(m.totalPoint),
totalValue: BigNumber.from(m.totalValue),
terminalId: m.terminalId,
paymentStatus: m.paymentStatus,
contractStatus: m.contractStatus,
openNewTimestamp: m.openNewTimestamp,
Expand Down Expand Up @@ -487,6 +507,7 @@ export class RelayStorage extends Storage {
currency: item.currency,
name: item.name,
status: item.status,
terminalId: item.terminalId,
taskStatus: item.taskStatus,
timestamp: item.timestamp,
})
Expand Down Expand Up @@ -514,6 +535,7 @@ export class RelayStorage extends Storage {
name: m.name,
currency: m.currency,
status: m.status,
terminalId: m.terminalId,
taskStatus: m.taskStatus,
timestamp: m.timestamp,
txId: m.txId,
Expand Down Expand Up @@ -596,6 +618,7 @@ export class RelayStorage extends Storage {
name: m.name,
currency: m.currency,
status: m.status,
terminalId: m.terminalId,
taskStatus: m.taskStatus,
timestamp: m.timestamp,
txId: m.txId,
Expand Down
9 changes: 9 additions & 0 deletions packages/relay/src/storage/mapper/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"feeValue" ,
"totalPoint" ,
"totalValue" ,
"terminalId" ,
"paymentStatus" ,
"openNewTimestamp" ,
"closeNewTimestamp" ,
Expand All @@ -41,6 +42,7 @@
#{feeValue} ,
#{totalPoint} ,
#{totalValue} ,
#{terminalId} ,
${paymentStatus} ,
${openNewTimestamp} ,
${closeNewTimestamp} ,
Expand Down Expand Up @@ -80,6 +82,13 @@
WHERE "paymentId" = #{paymentId} AND "paymentStatus" <![CDATA[<]]> ${paymentStatus}
</update>

<update id="updateTerminal">
UPDATE payments
SET
"terminalId" = #{terminalId}
WHERE "paymentId" = #{paymentId}
</update>

<update id="updateStatus">
UPDATE payments
SET
Expand Down
Loading

0 comments on commit 699ffd1

Please sign in to comment.