@envarai/envarpay 0.2.0-alpha.8 → 0.2.0-alpha.9
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/commerce/x402.d.ts +1 -0
- package/dist/commerce/x402.js +8 -1
- package/package.json +1 -1
package/dist/commerce/x402.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface X402GateOptions {
|
|
|
15
15
|
/** Read chain before broadcast, so a lost facilitator response remains recoverable. */
|
|
16
16
|
checkpoint?: (requirements: PaymentRequirements) => Promise<string>;
|
|
17
17
|
findOriginalReceipt?: (payload: PaymentPayload, requirements: PaymentRequirements, fromBlock: string) => Promise<SettleResponse | undefined>;
|
|
18
|
+
proveExpiredUnused?: (payload: PaymentPayload, requirements: PaymentRequirements) => Promise<boolean>;
|
|
18
19
|
}
|
|
19
20
|
export type GateResult = {
|
|
20
21
|
response: Response;
|
package/dist/commerce/x402.js
CHANGED
|
@@ -42,8 +42,13 @@ export class X402Gate {
|
|
|
42
42
|
if (!receipt?.transaction && saved.fromBlock && this.options.findOriginalReceipt) {
|
|
43
43
|
receipt = await this.options.findOriginalReceipt(saved.payload, saved.requirements, saved.fromBlock) ?? null;
|
|
44
44
|
}
|
|
45
|
-
if (!receipt?.transaction)
|
|
45
|
+
if (!receipt?.transaction) {
|
|
46
|
+
if (await this.options.proveExpiredUnused?.(saved.payload, saved.requirements)) {
|
|
47
|
+
this.options.store.recordSettlement(attempt.id, 'rejected', { errorReason: 'authorization_expired_unused' });
|
|
48
|
+
return { state: 'rejected', taskId: order.taskId };
|
|
49
|
+
}
|
|
46
50
|
return { state: 'unknown', taskId: order.taskId };
|
|
51
|
+
}
|
|
47
52
|
let proven = false;
|
|
48
53
|
try {
|
|
49
54
|
proven = await this.options.verifyReceipt(receipt, saved.payload, saved.requirements);
|
|
@@ -84,6 +89,8 @@ export class X402Gate {
|
|
|
84
89
|
const receipt = this.options.store.paymentForOrder(order.id).receipt;
|
|
85
90
|
return { headers: { 'PAYMENT-RESPONSE': encodePaymentResponseHeader(receipt) } };
|
|
86
91
|
}
|
|
92
|
+
if (recovered.state === 'rejected')
|
|
93
|
+
return { response: Response.json({ error: 'authorization_expired_unused', taskId: order.taskId }, { status: 409, headers: { 'Cache-Control': 'no-store' } }) };
|
|
87
94
|
return { response: Response.json({ error: 'payment_reconciliation_required', taskId: order.taskId }, { status: 503, headers: { 'Cache-Control': 'no-store' } }) };
|
|
88
95
|
}
|
|
89
96
|
if (Date.now() >= Date.parse(order.quote.expiresAt))
|