@gravito/satellite-payment 0.1.4 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @gravito/satellite-payment
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @gravito/core@1.6.1
9
+ - @gravito/enterprise@1.0.4
10
+ - @gravito/stasis@3.1.1
11
+
3
12
  ## 0.1.4
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -63,12 +63,17 @@ var ProcessPayment = class extends UseCase {
63
63
  this.manager = manager;
64
64
  }
65
65
  async execute(input) {
66
- const transaction = Transaction.create(crypto.randomUUID(), {
66
+ const id = crypto.randomUUID();
67
+ const transaction = Transaction.create(id, {
67
68
  orderId: input.orderId,
68
69
  amount: input.amount,
69
70
  currency: input.currency,
70
71
  gateway: input.gateway || "default"
71
72
  });
73
+ if (input.metadata) {
74
+ ;
75
+ transaction.props.metadata = { ...input.metadata };
76
+ }
72
77
  const gateway = this.manager.driver(input.gateway);
73
78
  const intent = await gateway.createIntent(transaction);
74
79
  transaction.authorize(intent.gatewayTransactionId);
@@ -108,7 +113,9 @@ var StripeGateway = class {
108
113
  currency: rawProps.currency.toLowerCase(),
109
114
  metadata: {
110
115
  orderId: transaction.orderId,
111
- transactionId: transaction.id
116
+ transactionId: transaction.id,
117
+ // 包含自定義 metadata(如 lockId)
118
+ ...rawProps.metadata
112
119
  },
113
120
  automatic_payment_methods: {
114
121
  enabled: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/satellite-payment",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -8,7 +8,9 @@
8
8
  "scripts": {
9
9
  "build": "tsup src/index.ts --format esm --dts --clean --external @gravito/atlas --external @gravito/enterprise --external @gravito/stasis --external @gravito/core --external stripe",
10
10
  "test": "bun test",
11
- "typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck"
11
+ "typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
12
+ "test:unit": "bun test",
13
+ "test:integration": "bun test"
12
14
  },
13
15
  "dependencies": {
14
16
  "@gravito/atlas": "workspace:*",
@@ -8,6 +8,7 @@ export interface ProcessPaymentInput {
8
8
  amount: number
9
9
  currency: string
10
10
  gateway?: string // 現在可以動態指定
11
+ metadata?: Record<string, string> // 自定義 metadata(如 lockId)
11
12
  }
12
13
 
13
14
  export class ProcessPayment extends UseCase<ProcessPaymentInput, PaymentIntent> {
@@ -16,13 +17,19 @@ export class ProcessPayment extends UseCase<ProcessPaymentInput, PaymentIntent>
16
17
  }
17
18
 
18
19
  async execute(input: ProcessPaymentInput): Promise<PaymentIntent> {
19
- const transaction = Transaction.create(crypto.randomUUID(), {
20
+ const id = crypto.randomUUID()
21
+ const transaction = Transaction.create(id, {
20
22
  orderId: input.orderId,
21
23
  amount: input.amount,
22
24
  currency: input.currency,
23
25
  gateway: input.gateway || 'default',
24
26
  })
25
27
 
28
+ // 設置自定義 metadata(如果提供)
29
+ if (input.metadata) {
30
+ ;(transaction as any).props.metadata = { ...input.metadata }
31
+ }
32
+
26
33
  // 從 Manager 取得指定的金流驅動器
27
34
  const gateway = this.manager.driver(input.gateway)
28
35
  const intent = await gateway.createIntent(transaction)
@@ -7,7 +7,7 @@ export class StripeGateway implements IPaymentGateway {
7
7
 
8
8
  constructor(apiKey: string) {
9
9
  this.stripe = new Stripe(apiKey, {
10
- apiVersion: '2025-01-27' as any,
10
+ apiVersion: '2025-01-27' as never,
11
11
  })
12
12
  }
13
13
 
@@ -16,8 +16,10 @@ export class StripeGateway implements IPaymentGateway {
16
16
  }
17
17
 
18
18
  async createIntent(transaction: Transaction): Promise<PaymentIntent> {
19
- // 透過 any 訪問私有屬性以解決跨包訪問問題
20
- const rawProps = (transaction as any).props
19
+ // 透過類型斷言訪問私有屬性以解決跨包訪問問題
20
+ const rawProps = (
21
+ transaction as unknown as { props: { currency: string; metadata?: Record<string, unknown> } }
22
+ ).props
21
23
 
22
24
  const intent = await this.stripe.paymentIntents.create({
23
25
  amount: Math.round(transaction.amount * 100),
@@ -25,6 +27,8 @@ export class StripeGateway implements IPaymentGateway {
25
27
  metadata: {
26
28
  orderId: transaction.orderId,
27
29
  transactionId: transaction.id,
30
+ // 包含自定義 metadata(如 lockId)
31
+ ...rawProps.metadata,
28
32
  },
29
33
  automatic_payment_methods: {
30
34
  enabled: true,
package/src/manifest.json CHANGED
@@ -3,13 +3,7 @@
3
3
  "id": "payment",
4
4
  "version": "0.1.0",
5
5
  "description": "A Gravito Satellite",
6
- "capabilities": [
7
- "create-payment"
8
- ],
9
- "requirements": [
10
- "cache"
11
- ],
12
- "hooks": [
13
- "payment:created"
14
- ]
15
- }
6
+ "capabilities": ["create-payment"],
7
+ "requirements": ["cache"],
8
+ "hooks": ["payment:created"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,26 +1,14 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "baseUrl": ".",
6
- "paths": {
7
- "@gravito/core": [
8
- "../../packages/core/src/index.ts"
9
- ],
10
- "@gravito/*": [
11
- "../../packages/*/src/index.ts"
12
- ]
13
- },
14
- "types": [
15
- "bun-types"
16
- ]
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "baseUrl": ".",
6
+ "paths": {
7
+ "@gravito/core": ["../../packages/core/src/index.ts"],
8
+ "@gravito/*": ["../../packages/*/src/index.ts"]
17
9
  },
18
- "include": [
19
- "src/**/*"
20
- ],
21
- "exclude": [
22
- "node_modules",
23
- "dist",
24
- "**/*.test.ts"
25
- ]
26
- }
10
+ "types": ["bun-types"]
11
+ },
12
+ "include": ["src/**/*"],
13
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
14
+ }