@agentspend/sdk 0.3.3 → 0.3.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/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
- // Resolve the payTo address for verification context
221
- const payTo = await resolvePayToAddress();
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",
@@ -227,7 +234,7 @@ function createAgentSpend(options) {
227
234
  asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
228
235
  payTo,
229
236
  maxTimeoutSeconds: 300,
230
- extra: {}
237
+ extra: { name: "USD Coin", version: "2" }
231
238
  };
232
239
  // Verify payment via facilitator
233
240
  const verifyResult = await facilitator.verify(paymentPayload, paymentRequirements);
@@ -271,7 +278,7 @@ function createAgentSpend(options) {
271
278
  asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
272
279
  payTo,
273
280
  maxTimeoutSeconds: 300,
274
- extra: {}
281
+ extra: { name: "USD Coin", version: "2" }
275
282
  };
276
283
  // Build x402 v2 PaymentRequired response
277
284
  const paymentRequired = {
@@ -299,8 +306,11 @@ function createAgentSpend(options) {
299
306
  } : {})
300
307
  }, 402);
301
308
  }
302
- catch {
303
- // If we can't resolve a payTo address, return a plain 402
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentspend/sdk",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {
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
- // Resolve the payTo address for verification context
403
- const payTo = await resolvePayToAddress();
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 = {
@@ -410,7 +417,7 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
410
417
  asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
411
418
  payTo,
412
419
  maxTimeoutSeconds: 300,
413
- extra: {}
420
+ extra: { name: "USD Coin", version: "2" }
414
421
  };
415
422
 
416
423
  // Verify payment via facilitator
@@ -482,7 +489,7 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
482
489
  asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
483
490
  payTo,
484
491
  maxTimeoutSeconds: 300,
485
- extra: {}
492
+ extra: { name: "USD Coin", version: "2" }
486
493
  };
487
494
 
488
495
  // Build x402 v2 PaymentRequired response
@@ -514,8 +521,14 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
514
521
  }
515
522
  } : {})
516
523
  }, 402);
517
- } catch {
518
- // If we can't resolve a payTo address, return a plain 402
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",