Skip to content

Commit

Permalink
Merge pull request #171 from samchon/features/local
Browse files Browse the repository at this point in the history
Fix duplicated cancel histories archiving problem.
  • Loading branch information
samchon authored Nov 3, 2023
2 parents 563170e + cfa1389 commit 90a3980
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin/
lib/
migrations/
node_modules/

package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion packages/fake-iamport-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fake-iamport-server",
"version": "5.0.1",
"version": "5.0.2",
"description": "Fake iamport server for testing",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/fake-toss-payments-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fake-toss-payments-server",
"version": "5.0.1",
"version": "5.0.2",
"description": "Fake toss-payments server for testing",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/iamport-server-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iamport-server-api",
"version": "5.0.1",
"version": "5.0.2",
"description": "API for Iamport Server",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/iamport-server-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"info": {
"title": "Iamport API",
"description": "Built by [fake-iamport-server](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server) with [nestia](https://github.com/samchon/nestia)",
"version": "5.0.1",
"version": "5.0.2",
"license": {
"name": "MIT"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/payment-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/payment-api",
"version": "5.0.1",
"version": "5.0.2",
"description": "API for Payment Backend",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -35,8 +35,8 @@
},
"dependencies": {
"@nestia/fetcher": "^2.3.4",
"iamport-server-api": "^5.0.1",
"toss-payments-server-api": "^5.0.1",
"iamport-server-api": "^5.0.2",
"toss-payments-server-api": "^5.0.2",
"typia": "^5.2.4"
}
}
2 changes: 1 addition & 1 deletion packages/payment-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
],
"info": {
"version": "5.0.1",
"version": "5.0.2-dev.20231103",
"title": "@samchon/payment-backend",
"description": "Payment Backend Server",
"license": {
Expand Down
16 changes: 8 additions & 8 deletions packages/payment-backend/docs/ERD.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Payments
```mermaid
erDiagram
payment_reservations {
"payment_reservations" {
String id PK
String source_schema
String source_table
Expand All @@ -19,7 +19,7 @@ payment_reservations {
String password
DateTime created_at
}
payment_histories {
"payment_histories" {
String id PK
String source_schema
String source_table
Expand All @@ -37,32 +37,32 @@ payment_histories {
DateTime paid_at "nullable"
DateTime cancelled_at "nullable"
}
payment_history_cancels {
"payment_history_cancels" {
String id PK
String payment_history_id FK
Float amount
String reason
String data
DateTime created_at
}
payment_history_webhooks {
"payment_history_webhooks" {
String id PK
String payment_history_id FK
String previous
String current
String data
DateTime created_at
}
payment_history_webhook_responses {
"payment_history_webhook_responses" {
String id PK
String payment_history_webhook_id FK
Int status "nullable"
String body "nullable"
DateTime created_at
}
payment_history_cancels }|--|| payment_histories : history
payment_history_webhooks }|--|| payment_histories : history
payment_history_webhook_responses }|--|| payment_history_webhooks : webhook
"payment_history_cancels" }|--|| "payment_histories" : history
"payment_history_webhooks" }|--|| "payment_histories" : history
"payment_history_webhook_responses" }|--|| "payment_history_webhooks" : webhook
```

### `payment_reservations`
Expand Down
16 changes: 7 additions & 9 deletions packages/payment-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/payment-backend",
"version": "5.0.1",
"version": "5.0.2",
"description": "Payment Backend Server",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -12,12 +12,10 @@
"build:prisma": "prisma generate --schema=src/schema.prisma",
"build:sdk": "rimraf src/api/functional && nestia sdk",
"build:swagger": "nestia swagger",
"build:test": "rimraf bin && tsc -p test/tsconfig.json",
"build:test": "npm run build:prisma && rimraf bin && tsc -p test/tsconfig.json",
"dev": "npm run build:test -- --watch",
"eslint": "eslint src && eslint test",
"eslint:fix": "eslint src --fix && eslint test --fix",
"package:api": "npm run build:api && cd packages/api && npm publish",
"package:models": "npm run build:models && cd packags/models && npm publish",
"prepare": "ts-patch install && npm run build:prisma",
"prettier": "prettier src --write && prettier test --write",
"-----------------------------------------------": "",
Expand Down Expand Up @@ -67,14 +65,14 @@
"@typescript-eslint/parser": "^5.26.0",
"cli": "^1.0.1",
"copyfiles": "^2.4.1",
"iamport-server-api": "^5.0.1",
"iamport-server-api": "^5.0.2",
"nestia": "^5.0.1",
"pm2": "^4.5.6",
"prettier": "^2.6.2",
"prisma-markdown": "^1.0.0",
"prisma-markdown": "^1.0.5",
"rimraf": "^3.0.2",
"sloc": "^0.2.1",
"toss-payments-server-api": "^5.0.1",
"toss-payments-server-api": "^5.0.2",
"ts-node": "^10.9.1",
"ts-patch": "^3.0.2",
"typescript": "^5.2.2",
Expand All @@ -86,8 +84,8 @@
"bcryptjs": "^2.4.3",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
"fake-iamport-server": "^5.0.1",
"fake-toss-payments-server": "^5.0.1",
"fake-iamport-server": "^5.0.2",
"fake-toss-payments-server": "^5.0.2",
"git-last-commit": "^1.0.0",
"inquirer": "^8.2.5",
"mutex-server": "^0.3.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/payment-backend/src/executable/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Singleton } from "tstl/thread/Singleton";

import { PaymentBackend } from "../PaymentBackend";
import { PaymentGlobal } from "../PaymentGlobal";
import { PaymentUpdator } from "../PaymentUpdator";
import { Scheduler } from "../schedulers/Scheduler";
import { ErrorUtil } from "../utils/ErrorUtil";

Expand Down Expand Up @@ -59,8 +60,13 @@ async function main(): Promise<void> {
global.process.on("unhandledRejection", handle_error);

// SCHEDULER ONLY WHEN MASTER
if (PaymentGlobal.mode !== "real" || process.argv[3] === "master")
if (PaymentGlobal.mode !== "real" || process.argv[3] === "master") {
if (PaymentGlobal.mode === "local")
try {
await PaymentUpdator.master();
} catch {}
await Scheduler.repeat();
}
}
main().catch((exp) => {
console.log(exp);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { IPaymentCancelHistory } from "@samchon/payment-api/lib/structures/payme
import { IPaymentHistory } from "@samchon/payment-api/lib/structures/payments/IPaymentHistory";
import { IIamportPayment } from "iamport-server-api/lib/structures/IIamportPayment";
import { ITossPayment } from "toss-payments-server-api/lib/structures/ITossPayment";
import { sleep_for } from "tstl";
import { v4 } from "uuid";

import { PaymentGlobal } from "../../PaymentGlobal";
Expand Down Expand Up @@ -42,7 +41,6 @@ export namespace PaymentCancelHistoryProvider {
source_id: input.source.id,
})(input.password);
const props: IPaymentHistory.IProps = await request(history)(input);
await sleep_for(50);
return PaymentHistoryProvider.update(history)(props);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,15 @@ export namespace PaymentHistoryProvider {
(history: IEntity) =>
async (input: IPaymentHistory.IProps): Promise<IPaymentHistory> => {
// RE-CONSTRUCT CANCEL HISTORIES
await PaymentGlobal.prisma.payment_history_cancels.deleteMany({
where: { payment_history_id: history.id },
});
await PaymentGlobal.prisma.payment_history_cancels.createMany({
data: input.cancels.map(
PaymentCancelHistoryProvider.collect(history),
),
skipDuplicates: true,
});

// UPDATE HISTORY
const record = await PaymentGlobal.prisma.payment_histories.update({
await PaymentGlobal.prisma.payment_histories.update({
where: { id: history.id },
data: {
currency: input.currency,
Expand All @@ -170,6 +168,11 @@ export namespace PaymentHistoryProvider {
},
...json.select(),
});
const record =
await PaymentGlobal.prisma.payment_histories.findFirstOrThrow({
where: { id: history.id },
...json.select(),
});
return json.transform(record);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/payment-backend/src/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ model payment_history_cancels {
/// 귀속 결제 이력.
history payment_histories @relation(fields: [payment_history_id], references: [id], onDelete: Cascade)
@@index([payment_history_id])
@@unique([payment_history_id, amount, reason, created_at])
}

/// 웹훅 이벤트 레코드.
Expand Down
Loading

0 comments on commit 90a3980

Please sign in to comment.