@payloops/processor-core 0.0.1 → 0.0.7
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/dist/index.d.ts +70 -11
- package/dist/index.js +0 -21
- package/dist/lib/observability/index.d.ts +1 -0
- package/dist/lib/observability/index.js +2 -0
- package/package.json +17 -30
- package/.env.example +0 -4
- package/Dockerfile +0 -41
- package/dist/activities/index.d.ts +0 -2
- package/dist/activities/index.js +0 -19
- package/dist/chunk-AV4OEJXY.js +0 -132
- package/dist/chunk-CZTZBCNV.js +0 -133
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-X2Y2ZUQA.js +0 -297
- package/dist/index-CXmmtGo_.d.ts +0 -25
- package/dist/index-CsnpS83V.d.ts +0 -72
- package/dist/workflows/index.d.ts +0 -27
- package/dist/workflows/index.js +0 -13
- package/src/activities/index.ts +0 -224
- package/src/index.ts +0 -22
- package/src/lib/crypto.ts +0 -24
- package/src/lib/db.ts +0 -91
- package/src/lib/observability/index.ts +0 -2
- package/src/lib/observability/logger.ts +0 -44
- package/src/lib/observability/otel.ts +0 -53
- package/src/lib/registry.ts +0 -28
- package/src/types/index.ts +0 -95
- package/src/worker.ts +0 -105
- package/src/workflows/index.ts +0 -5
- package/src/workflows/payment.ts +0 -111
- package/src/workflows/webhook.ts +0 -64
- package/tsconfig.json +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
interface PaymentConfig {
|
|
2
|
+
merchantId: string;
|
|
3
|
+
processor: string;
|
|
4
|
+
testMode: boolean;
|
|
5
|
+
credentials: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
interface PaymentInput {
|
|
8
|
+
orderId: string;
|
|
9
|
+
merchantId: string;
|
|
10
|
+
amount: number;
|
|
11
|
+
currency: string;
|
|
12
|
+
processor: string;
|
|
13
|
+
returnUrl?: string;
|
|
14
|
+
cancelUrl?: string;
|
|
15
|
+
metadata?: Record<string, unknown>;
|
|
16
|
+
customer?: {
|
|
17
|
+
id?: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
};
|
|
21
|
+
paymentMethod?: {
|
|
22
|
+
type: 'card' | 'upi' | 'netbanking' | 'wallet';
|
|
23
|
+
token?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface PaymentResult {
|
|
27
|
+
success: boolean;
|
|
28
|
+
status: 'authorized' | 'captured' | 'failed' | 'pending' | 'requires_action';
|
|
29
|
+
processorOrderId?: string;
|
|
30
|
+
processorTransactionId?: string;
|
|
31
|
+
redirectUrl?: string;
|
|
32
|
+
errorCode?: string;
|
|
33
|
+
errorMessage?: string;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
interface RefundInput {
|
|
37
|
+
orderId: string;
|
|
38
|
+
transactionId: string;
|
|
39
|
+
amount: number;
|
|
40
|
+
reason?: string;
|
|
41
|
+
}
|
|
42
|
+
interface RefundResult {
|
|
43
|
+
success: boolean;
|
|
44
|
+
refundId?: string;
|
|
45
|
+
status: 'pending' | 'success' | 'failed';
|
|
46
|
+
errorCode?: string;
|
|
47
|
+
errorMessage?: string;
|
|
48
|
+
}
|
|
49
|
+
interface WebhookDeliveryInput {
|
|
50
|
+
webhookEventId: string;
|
|
51
|
+
merchantId: string;
|
|
52
|
+
webhookUrl: string;
|
|
53
|
+
webhookSecret?: string;
|
|
54
|
+
payload: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
interface WebhookDeliveryResult {
|
|
57
|
+
success: boolean;
|
|
58
|
+
statusCode?: number;
|
|
59
|
+
attempts: number;
|
|
60
|
+
deliveredAt?: Date;
|
|
61
|
+
errorMessage?: string;
|
|
62
|
+
}
|
|
63
|
+
interface PaymentProcessor {
|
|
64
|
+
name: string;
|
|
65
|
+
createPayment(input: PaymentInput, config: PaymentConfig): Promise<PaymentResult>;
|
|
66
|
+
capturePayment(processorOrderId: string, amount: number, config: PaymentConfig): Promise<PaymentResult>;
|
|
67
|
+
refundPayment(processorTransactionId: string, amount: number, config: PaymentConfig): Promise<RefundResult>;
|
|
68
|
+
getPaymentStatus(processorOrderId: string, config: PaymentConfig): Promise<PaymentResult>;
|
|
69
|
+
}
|
|
6
70
|
|
|
7
|
-
|
|
8
|
-
declare function getProcessor(name: string): PaymentProcessor;
|
|
9
|
-
declare function getRegisteredProcessors(): string[];
|
|
10
|
-
declare function hasProcessor(name: string): boolean;
|
|
11
|
-
|
|
12
|
-
export { PaymentProcessor, getProcessor, getRegisteredProcessors, hasProcessor, registerProcessor };
|
|
71
|
+
export type { PaymentConfig, PaymentInput, PaymentProcessor, PaymentResult, RefundInput, RefundResult, WebhookDeliveryInput, WebhookDeliveryResult };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
activities_exports,
|
|
3
|
-
getProcessor,
|
|
4
|
-
getRegisteredProcessors,
|
|
5
|
-
hasProcessor,
|
|
6
|
-
registerProcessor
|
|
7
|
-
} from "./chunk-X2Y2ZUQA.js";
|
|
8
|
-
import {
|
|
9
|
-
PaymentWorkflow,
|
|
10
|
-
WebhookDeliveryWorkflow
|
|
11
|
-
} from "./chunk-CZTZBCNV.js";
|
|
12
|
-
import "./chunk-MLKGABMK.js";
|
|
13
|
-
export {
|
|
14
|
-
PaymentWorkflow,
|
|
15
|
-
WebhookDeliveryWorkflow,
|
|
16
|
-
activities_exports as activities,
|
|
17
|
-
getProcessor,
|
|
18
|
-
getRegisteredProcessors,
|
|
19
|
-
hasProcessor,
|
|
20
|
-
registerProcessor
|
|
21
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@payloops/observability';
|
package/package.json
CHANGED
|
@@ -1,54 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloops/processor-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/payloops/processor-core"
|
|
8
|
+
},
|
|
5
9
|
"main": "dist/index.js",
|
|
6
10
|
"types": "dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
7
14
|
"exports": {
|
|
8
15
|
".": {
|
|
9
16
|
"import": "./dist/index.js",
|
|
10
17
|
"types": "./dist/index.d.ts"
|
|
11
18
|
},
|
|
12
|
-
"./
|
|
13
|
-
"import": "./dist/
|
|
14
|
-
"types": "./dist/
|
|
15
|
-
},
|
|
16
|
-
"./activities": {
|
|
17
|
-
"import": "./dist/activities/index.js",
|
|
18
|
-
"types": "./dist/activities/index.d.ts"
|
|
19
|
+
"./observability": {
|
|
20
|
+
"import": "./dist/lib/observability/index.js",
|
|
21
|
+
"types": "./dist/lib/observability/index.d.ts"
|
|
19
22
|
}
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"build": "tsup src/index.ts src/workflows/index.ts src/activities/index.ts --format esm --dts",
|
|
24
|
-
"start": "node dist/worker.js",
|
|
25
|
+
"build": "tsup src/index.ts src/lib/observability/index.ts --format esm --dts",
|
|
25
26
|
"lint": "eslint src/",
|
|
26
|
-
"typecheck": "tsc --noEmit"
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"release": "npm run build && npm run typecheck && npm version patch && git push && git push --tags",
|
|
29
|
+
"release:minor": "npm run build && npm run typecheck && npm version minor && git push && git push --tags",
|
|
30
|
+
"release:major": "npm run build && npm run typecheck && npm version major && git push && git push --tags"
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@opentelemetry/api": "^1.9.0",
|
|
31
|
-
"@opentelemetry/auto-instrumentations-node": "^0.53.0",
|
|
32
|
-
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.0",
|
|
33
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
|
|
34
|
-
"@opentelemetry/sdk-node": "^0.57.0",
|
|
35
|
-
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
36
|
-
"@temporalio/activity": "^1.11.7",
|
|
37
|
-
"@temporalio/client": "^1.11.7",
|
|
38
|
-
"@temporalio/worker": "^1.11.7",
|
|
39
|
-
"@temporalio/workflow": "^1.11.7",
|
|
40
|
-
"drizzle-orm": "^0.39.1",
|
|
41
|
-
"pg": "^8.13.1",
|
|
42
|
-
"pino": "^9.6.0",
|
|
43
|
-
"zod": "^3.24.1"
|
|
33
|
+
"@payloops/observability": "^0.0.1"
|
|
44
34
|
},
|
|
45
35
|
"devDependencies": {
|
|
46
36
|
"@types/node": "^22.0.0",
|
|
47
|
-
"pino-pretty": "^13.0.0",
|
|
48
|
-
"@types/pg": "^8.11.10",
|
|
49
37
|
"eslint": "^9.0.0",
|
|
50
38
|
"tsup": "^8.3.5",
|
|
51
|
-
"tsx": "^4.19.2",
|
|
52
39
|
"typescript": "^5.9.3"
|
|
53
40
|
}
|
|
54
41
|
}
|
package/.env.example
DELETED
package/Dockerfile
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Build stage
|
|
2
|
-
FROM node:22-alpine AS builder
|
|
3
|
-
|
|
4
|
-
WORKDIR /app
|
|
5
|
-
|
|
6
|
-
# Copy package files
|
|
7
|
-
COPY package.json package-lock.json ./
|
|
8
|
-
|
|
9
|
-
# Install dependencies
|
|
10
|
-
RUN npm ci
|
|
11
|
-
|
|
12
|
-
# Copy source
|
|
13
|
-
COPY src ./src
|
|
14
|
-
COPY tsconfig.json ./
|
|
15
|
-
|
|
16
|
-
# Build
|
|
17
|
-
RUN npm run build
|
|
18
|
-
|
|
19
|
-
# Production stage
|
|
20
|
-
FROM node:22-alpine AS runner
|
|
21
|
-
|
|
22
|
-
WORKDIR /app
|
|
23
|
-
|
|
24
|
-
# Copy package files
|
|
25
|
-
COPY package.json package-lock.json ./
|
|
26
|
-
|
|
27
|
-
# Install production dependencies only
|
|
28
|
-
RUN npm ci --omit=dev
|
|
29
|
-
|
|
30
|
-
# Copy built files
|
|
31
|
-
COPY --from=builder /app/dist ./dist
|
|
32
|
-
|
|
33
|
-
# Create non-root user
|
|
34
|
-
RUN addgroup --system --gid 1001 nodejs && \
|
|
35
|
-
adduser --system --uid 1001 loop
|
|
36
|
-
|
|
37
|
-
USER loop
|
|
38
|
-
|
|
39
|
-
ENV NODE_ENV=production
|
|
40
|
-
|
|
41
|
-
CMD ["node", "dist/worker.js"]
|
package/dist/activities/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
capturePayment,
|
|
3
|
-
deliverWebhook,
|
|
4
|
-
getMerchantWebhookUrl,
|
|
5
|
-
getProcessorConfig,
|
|
6
|
-
processPayment,
|
|
7
|
-
refundPayment,
|
|
8
|
-
updateOrderStatus
|
|
9
|
-
} from "../chunk-X2Y2ZUQA.js";
|
|
10
|
-
import "../chunk-MLKGABMK.js";
|
|
11
|
-
export {
|
|
12
|
-
capturePayment,
|
|
13
|
-
deliverWebhook,
|
|
14
|
-
getMerchantWebhookUrl,
|
|
15
|
-
getProcessorConfig,
|
|
16
|
-
processPayment,
|
|
17
|
-
refundPayment,
|
|
18
|
-
updateOrderStatus
|
|
19
|
-
};
|
package/dist/chunk-AV4OEJXY.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// src/workflows/payment.ts
|
|
2
|
-
import { proxyActivities, sleep, defineSignal, setHandler } from "@temporalio/workflow";
|
|
3
|
-
var { processPayment, updateOrderStatus, capturePayment } = proxyActivities({
|
|
4
|
-
startToCloseTimeout: "2 minutes",
|
|
5
|
-
retry: {
|
|
6
|
-
initialInterval: "1s",
|
|
7
|
-
maximumInterval: "1m",
|
|
8
|
-
backoffCoefficient: 2,
|
|
9
|
-
maximumAttempts: 5
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var completePaymentSignal = defineSignal(
|
|
13
|
-
"completePayment"
|
|
14
|
-
);
|
|
15
|
-
var cancelPaymentSignal = defineSignal("cancelPayment");
|
|
16
|
-
async function PaymentWorkflow(input) {
|
|
17
|
-
let paymentCompleted = false;
|
|
18
|
-
let paymentResult = null;
|
|
19
|
-
let cancelled = false;
|
|
20
|
-
setHandler(completePaymentSignal, (result) => {
|
|
21
|
-
paymentCompleted = true;
|
|
22
|
-
paymentResult = {
|
|
23
|
-
success: result.success,
|
|
24
|
-
status: result.success ? "captured" : "failed",
|
|
25
|
-
processorTransactionId: result.processorTransactionId
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
setHandler(cancelPaymentSignal, () => {
|
|
29
|
-
cancelled = true;
|
|
30
|
-
});
|
|
31
|
-
try {
|
|
32
|
-
const result = await processPayment({
|
|
33
|
-
orderId: input.orderId,
|
|
34
|
-
merchantId: input.merchantId,
|
|
35
|
-
amount: input.amount,
|
|
36
|
-
currency: input.currency,
|
|
37
|
-
processor: input.processor,
|
|
38
|
-
returnUrl: input.returnUrl
|
|
39
|
-
});
|
|
40
|
-
if (result.status === "requires_action") {
|
|
41
|
-
await updateOrderStatus(input.orderId, "requires_action", result.processorOrderId);
|
|
42
|
-
const timeout = 15 * 60 * 1e3;
|
|
43
|
-
const startTime = Date.now();
|
|
44
|
-
while (!paymentCompleted && !cancelled && Date.now() - startTime < timeout) {
|
|
45
|
-
await sleep("10 seconds");
|
|
46
|
-
}
|
|
47
|
-
if (cancelled) {
|
|
48
|
-
await updateOrderStatus(input.orderId, "cancelled");
|
|
49
|
-
return { success: false, status: "failed", errorCode: "cancelled", errorMessage: "Payment cancelled" };
|
|
50
|
-
}
|
|
51
|
-
if (!paymentCompleted) {
|
|
52
|
-
await updateOrderStatus(input.orderId, "failed");
|
|
53
|
-
return { success: false, status: "failed", errorCode: "timeout", errorMessage: "Payment timeout" };
|
|
54
|
-
}
|
|
55
|
-
if (paymentResult) {
|
|
56
|
-
await updateOrderStatus(
|
|
57
|
-
input.orderId,
|
|
58
|
-
paymentResult.status,
|
|
59
|
-
result.processorOrderId,
|
|
60
|
-
paymentResult.processorTransactionId
|
|
61
|
-
);
|
|
62
|
-
return paymentResult;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
await updateOrderStatus(input.orderId, result.status, result.processorOrderId, result.processorTransactionId);
|
|
66
|
-
return result;
|
|
67
|
-
} catch (error) {
|
|
68
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
69
|
-
await updateOrderStatus(input.orderId, "failed");
|
|
70
|
-
return {
|
|
71
|
-
success: false,
|
|
72
|
-
status: "failed",
|
|
73
|
-
errorCode: "workflow_error",
|
|
74
|
-
errorMessage
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/workflows/webhook.ts
|
|
80
|
-
import { proxyActivities as proxyActivities2, sleep as sleep2 } from "@temporalio/workflow";
|
|
81
|
-
var { deliverWebhook, getMerchantWebhookUrl } = proxyActivities2({
|
|
82
|
-
startToCloseTimeout: "1 minute",
|
|
83
|
-
retry: {
|
|
84
|
-
initialInterval: "1s",
|
|
85
|
-
maximumInterval: "30s",
|
|
86
|
-
backoffCoefficient: 2,
|
|
87
|
-
maximumAttempts: 3
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
var MAX_ATTEMPTS = 5;
|
|
91
|
-
var RETRY_DELAYS = [
|
|
92
|
-
60 * 1e3,
|
|
93
|
-
// 1 minute
|
|
94
|
-
5 * 60 * 1e3,
|
|
95
|
-
// 5 minutes
|
|
96
|
-
30 * 60 * 1e3,
|
|
97
|
-
// 30 minutes
|
|
98
|
-
2 * 60 * 60 * 1e3,
|
|
99
|
-
// 2 hours
|
|
100
|
-
24 * 60 * 60 * 1e3
|
|
101
|
-
// 24 hours
|
|
102
|
-
];
|
|
103
|
-
async function WebhookDeliveryWorkflow(input) {
|
|
104
|
-
const { secret } = await getMerchantWebhookUrl(input.merchantId);
|
|
105
|
-
let attempt = 0;
|
|
106
|
-
let lastResult = null;
|
|
107
|
-
while (attempt < MAX_ATTEMPTS) {
|
|
108
|
-
attempt++;
|
|
109
|
-
const result = await deliverWebhook(input.webhookEventId, input.webhookUrl, secret || void 0, input.payload);
|
|
110
|
-
lastResult = result;
|
|
111
|
-
if (result.success) {
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
if (attempt >= MAX_ATTEMPTS) {
|
|
115
|
-
return {
|
|
116
|
-
success: false,
|
|
117
|
-
attempts: attempt,
|
|
118
|
-
errorMessage: result.errorMessage || "Max attempts reached"
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
const delay = RETRY_DELAYS[attempt - 1] || RETRY_DELAYS[RETRY_DELAYS.length - 1];
|
|
122
|
-
await sleep2(delay);
|
|
123
|
-
}
|
|
124
|
-
return lastResult || { success: false, attempts: attempt, errorMessage: "Unknown error" };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
completePaymentSignal,
|
|
129
|
-
cancelPaymentSignal,
|
|
130
|
-
PaymentWorkflow,
|
|
131
|
-
WebhookDeliveryWorkflow
|
|
132
|
-
};
|
package/dist/chunk-CZTZBCNV.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// src/workflows/payment.ts
|
|
2
|
-
import { proxyActivities, sleep, defineSignal, setHandler } from "@temporalio/workflow";
|
|
3
|
-
var { processPayment, updateOrderStatus, capturePayment } = proxyActivities({
|
|
4
|
-
startToCloseTimeout: "2 minutes",
|
|
5
|
-
retry: {
|
|
6
|
-
initialInterval: "1s",
|
|
7
|
-
maximumInterval: "1m",
|
|
8
|
-
backoffCoefficient: 2,
|
|
9
|
-
maximumAttempts: 5
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var completePaymentSignal = defineSignal(
|
|
13
|
-
"completePayment"
|
|
14
|
-
);
|
|
15
|
-
var cancelPaymentSignal = defineSignal("cancelPayment");
|
|
16
|
-
async function PaymentWorkflow(input) {
|
|
17
|
-
let paymentCompleted = false;
|
|
18
|
-
let paymentResult = null;
|
|
19
|
-
let cancelled = false;
|
|
20
|
-
setHandler(completePaymentSignal, (result) => {
|
|
21
|
-
paymentCompleted = true;
|
|
22
|
-
paymentResult = {
|
|
23
|
-
success: result.success,
|
|
24
|
-
status: result.success ? "captured" : "failed",
|
|
25
|
-
processorTransactionId: result.processorTransactionId
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
setHandler(cancelPaymentSignal, () => {
|
|
29
|
-
cancelled = true;
|
|
30
|
-
});
|
|
31
|
-
try {
|
|
32
|
-
const result = await processPayment({
|
|
33
|
-
orderId: input.orderId,
|
|
34
|
-
merchantId: input.merchantId,
|
|
35
|
-
amount: input.amount,
|
|
36
|
-
currency: input.currency,
|
|
37
|
-
processor: input.processor,
|
|
38
|
-
returnUrl: input.returnUrl
|
|
39
|
-
});
|
|
40
|
-
if (result.status === "requires_action") {
|
|
41
|
-
await updateOrderStatus(input.orderId, "requires_action", result.processorOrderId);
|
|
42
|
-
const timeout = 15 * 60 * 1e3;
|
|
43
|
-
const startTime = Date.now();
|
|
44
|
-
while (!paymentCompleted && !cancelled && Date.now() - startTime < timeout) {
|
|
45
|
-
await sleep("10 seconds");
|
|
46
|
-
}
|
|
47
|
-
if (cancelled) {
|
|
48
|
-
await updateOrderStatus(input.orderId, "cancelled");
|
|
49
|
-
return { success: false, status: "failed", errorCode: "cancelled", errorMessage: "Payment cancelled" };
|
|
50
|
-
}
|
|
51
|
-
if (!paymentCompleted) {
|
|
52
|
-
await updateOrderStatus(input.orderId, "failed");
|
|
53
|
-
return { success: false, status: "failed", errorCode: "timeout", errorMessage: "Payment timeout" };
|
|
54
|
-
}
|
|
55
|
-
if (paymentResult !== null) {
|
|
56
|
-
const finalResult = paymentResult;
|
|
57
|
-
await updateOrderStatus(
|
|
58
|
-
input.orderId,
|
|
59
|
-
finalResult.status,
|
|
60
|
-
result.processorOrderId,
|
|
61
|
-
finalResult.processorTransactionId
|
|
62
|
-
);
|
|
63
|
-
return finalResult;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
await updateOrderStatus(input.orderId, result.status, result.processorOrderId, result.processorTransactionId);
|
|
67
|
-
return result;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
70
|
-
await updateOrderStatus(input.orderId, "failed");
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
status: "failed",
|
|
74
|
-
errorCode: "workflow_error",
|
|
75
|
-
errorMessage
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/workflows/webhook.ts
|
|
81
|
-
import { proxyActivities as proxyActivities2, sleep as sleep2 } from "@temporalio/workflow";
|
|
82
|
-
var { deliverWebhook, getMerchantWebhookUrl } = proxyActivities2({
|
|
83
|
-
startToCloseTimeout: "1 minute",
|
|
84
|
-
retry: {
|
|
85
|
-
initialInterval: "1s",
|
|
86
|
-
maximumInterval: "30s",
|
|
87
|
-
backoffCoefficient: 2,
|
|
88
|
-
maximumAttempts: 3
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
var MAX_ATTEMPTS = 5;
|
|
92
|
-
var RETRY_DELAYS = [
|
|
93
|
-
60 * 1e3,
|
|
94
|
-
// 1 minute
|
|
95
|
-
5 * 60 * 1e3,
|
|
96
|
-
// 5 minutes
|
|
97
|
-
30 * 60 * 1e3,
|
|
98
|
-
// 30 minutes
|
|
99
|
-
2 * 60 * 60 * 1e3,
|
|
100
|
-
// 2 hours
|
|
101
|
-
24 * 60 * 60 * 1e3
|
|
102
|
-
// 24 hours
|
|
103
|
-
];
|
|
104
|
-
async function WebhookDeliveryWorkflow(input) {
|
|
105
|
-
const { secret } = await getMerchantWebhookUrl(input.merchantId);
|
|
106
|
-
let attempt = 0;
|
|
107
|
-
let lastResult = null;
|
|
108
|
-
while (attempt < MAX_ATTEMPTS) {
|
|
109
|
-
attempt++;
|
|
110
|
-
const result = await deliverWebhook(input.webhookEventId, input.webhookUrl, secret || void 0, input.payload);
|
|
111
|
-
lastResult = result;
|
|
112
|
-
if (result.success) {
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
if (attempt >= MAX_ATTEMPTS) {
|
|
116
|
-
return {
|
|
117
|
-
success: false,
|
|
118
|
-
attempts: attempt,
|
|
119
|
-
errorMessage: result.errorMessage || "Max attempts reached"
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
const delay = RETRY_DELAYS[attempt - 1] || RETRY_DELAYS[RETRY_DELAYS.length - 1];
|
|
123
|
-
await sleep2(delay);
|
|
124
|
-
}
|
|
125
|
-
return lastResult || { success: false, attempts: attempt, errorMessage: "Unknown error" };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export {
|
|
129
|
-
completePaymentSignal,
|
|
130
|
-
cancelPaymentSignal,
|
|
131
|
-
PaymentWorkflow,
|
|
132
|
-
WebhookDeliveryWorkflow
|
|
133
|
-
};
|