@agentspend/sdk 0.3.3 → 0.3.4
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.js +14 -4
- package/package.json +1 -1
- package/src/index.ts +17 -4
package/dist/index.js
CHANGED
|
@@ -217,8 +217,15 @@ function createAgentSpend(options) {
|
|
|
217
217
|
catch {
|
|
218
218
|
return c.json({ error: "Invalid payment payload encoding" }, 400);
|
|
219
219
|
}
|
|
220
|
-
//
|
|
221
|
-
|
|
220
|
+
// Extract payTo from the payment payload's accepted requirements
|
|
221
|
+
// rather than generating a new deposit address.
|
|
222
|
+
// resolvePayToAddress() creates a fresh Stripe PaymentIntent each
|
|
223
|
+
// time, which would return a *different* address than the one in the
|
|
224
|
+
// 402 response the client signed against → facilitator verification
|
|
225
|
+
// would fail.
|
|
226
|
+
const acceptedPayTo = paymentPayload
|
|
227
|
+
.accepted?.payTo;
|
|
228
|
+
const payTo = acceptedPayTo ?? await resolvePayToAddress();
|
|
222
229
|
// Build the payment requirements that the payment should satisfy
|
|
223
230
|
const paymentRequirements = {
|
|
224
231
|
scheme: "exact",
|
|
@@ -299,8 +306,11 @@ function createAgentSpend(options) {
|
|
|
299
306
|
} : {})
|
|
300
307
|
}, 402);
|
|
301
308
|
}
|
|
302
|
-
catch {
|
|
303
|
-
//
|
|
309
|
+
catch (error) {
|
|
310
|
+
// Log clearly so service developers can diagnose why crypto is unavailable
|
|
311
|
+
console.error("[agentspend] Failed to resolve crypto payTo address — returning card-only 402:", error instanceof Error ? error.message : error);
|
|
312
|
+
// Return card-only 402 (no Payment-Required header → crypto clients
|
|
313
|
+
// will see "Invalid payment required response")
|
|
304
314
|
return c.json({
|
|
305
315
|
error: "Payment required",
|
|
306
316
|
amount_cents: amountCents,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -399,8 +399,15 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
|
|
|
399
399
|
return c.json({ error: "Invalid payment payload encoding" }, 400);
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
//
|
|
403
|
-
|
|
402
|
+
// Extract payTo from the payment payload's accepted requirements
|
|
403
|
+
// rather than generating a new deposit address.
|
|
404
|
+
// resolvePayToAddress() creates a fresh Stripe PaymentIntent each
|
|
405
|
+
// time, which would return a *different* address than the one in the
|
|
406
|
+
// 402 response the client signed against → facilitator verification
|
|
407
|
+
// would fail.
|
|
408
|
+
const acceptedPayTo = (paymentPayload as unknown as { accepted?: { payTo?: string } })
|
|
409
|
+
.accepted?.payTo;
|
|
410
|
+
const payTo: string = acceptedPayTo ?? await resolvePayToAddress();
|
|
404
411
|
|
|
405
412
|
// Build the payment requirements that the payment should satisfy
|
|
406
413
|
const paymentRequirements: PaymentRequirements = {
|
|
@@ -514,8 +521,14 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
|
|
|
514
521
|
}
|
|
515
522
|
} : {})
|
|
516
523
|
}, 402);
|
|
517
|
-
} catch {
|
|
518
|
-
//
|
|
524
|
+
} catch (error) {
|
|
525
|
+
// Log clearly so service developers can diagnose why crypto is unavailable
|
|
526
|
+
console.error(
|
|
527
|
+
"[agentspend] Failed to resolve crypto payTo address — returning card-only 402:",
|
|
528
|
+
error instanceof Error ? error.message : error
|
|
529
|
+
);
|
|
530
|
+
// Return card-only 402 (no Payment-Required header → crypto clients
|
|
531
|
+
// will see "Invalid payment required response")
|
|
519
532
|
return c.json(
|
|
520
533
|
{
|
|
521
534
|
error: "Payment required",
|