@faremeter/payment-solana 0.21.0 → 0.22.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upto-handler.d.ts","sourceRoot":"","sources":["../../../../src/flex/hono/upto-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"upto-handler.d.ts","sourceRoot":"","sources":["../../../../src/flex/hono/upto-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,MAAM,CAAC;AAe7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAE7E,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAsFtE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { handleMiddlewareRequest, resolveSupportedVersions, deriveCapabilities, deriveResourceInfo, acceptsToPricing, relaxedRequirementsToV2, } from "@faremeter/middleware/common";
|
|
1
|
+
import { handleMiddlewareRequest, resolveSupportedVersions, deriveCapabilities, deriveSchemes, deriveResourceInfo, acceptsToPricing, relaxedRequirementsToV2, } from "@faremeter/middleware/common";
|
|
2
2
|
import { createHTTPFacilitatorHandler } from "@faremeter/middleware";
|
|
3
3
|
export function createUptoHandler(opts) {
|
|
4
4
|
const supportedVersions = resolveSupportedVersions({
|
|
@@ -10,8 +10,10 @@ export function createUptoHandler(opts) {
|
|
|
10
10
|
maxAmountRequired: amount,
|
|
11
11
|
}));
|
|
12
12
|
const capabilities = deriveCapabilities(middlewareAccepts);
|
|
13
|
+
const schemes = deriveSchemes(middlewareAccepts);
|
|
13
14
|
const handler = createHTTPFacilitatorHandler(opts.facilitatorURL, {
|
|
14
15
|
capabilities,
|
|
16
|
+
schemes,
|
|
15
17
|
acceptsOverride: middlewareAccepts.map(relaxedRequirementsToV2),
|
|
16
18
|
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
17
19
|
});
|
|
@@ -39,9 +41,9 @@ export function createUptoHandler(opts) {
|
|
|
39
41
|
if (ctx.protocolVersion !== 2) {
|
|
40
42
|
return c.json({ error: "upto requires x402 v2" }, 400);
|
|
41
43
|
}
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
return
|
|
44
|
+
const authorizeResult = await ctx.authorize();
|
|
45
|
+
if (!authorizeResult.success)
|
|
46
|
+
return authorizeResult.errorResponse;
|
|
45
47
|
const body = await c.req.json();
|
|
46
48
|
const ceiling = await opts.authorize(body);
|
|
47
49
|
let settled = false;
|
|
@@ -56,13 +58,13 @@ export function createUptoHandler(opts) {
|
|
|
56
58
|
throw new Error(`Settle amount ${amount} exceeds authorized ceiling ${ceiling}`);
|
|
57
59
|
}
|
|
58
60
|
settled = true;
|
|
59
|
-
// XXX - Mutate in place: ctx.
|
|
61
|
+
// XXX - Mutate in place: ctx.capture() closes over the original object reference
|
|
60
62
|
ctx.paymentRequirements.amount = amount.toString();
|
|
61
|
-
const result = await ctx.
|
|
63
|
+
const result = await ctx.capture();
|
|
62
64
|
if (!result.success) {
|
|
63
65
|
throw new Error(`Settlement failed for amount ${amount} (ceiling ${ceiling})`);
|
|
64
66
|
}
|
|
65
|
-
return result.
|
|
67
|
+
return result.response;
|
|
66
68
|
};
|
|
67
69
|
return opts.handle(body, settle);
|
|
68
70
|
},
|