Skip to content

Commit 635ae32

Browse files
[SDK] Expose waitUntil parameter in settlePayment()
1 parent ce9220e commit 635ae32

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

.changeset/yellow-cameras-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Also expose waitUntil param in settlePayment()

packages/thirdweb/src/exports/x402.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ export {
77
export { wrapFetchWithPayment } from "../x402/fetchWithPayment.js";
88
export { settlePayment } from "../x402/settle-payment.js";
99
export type {
10+
ERC20TokenAmount,
1011
PaymentArgs,
12+
PaymentRequiredResult,
13+
SettlePaymentArgs,
1114
SettlePaymentResult,
15+
SupportedSignatureType,
1216
VerifyPaymentResult,
1317
} from "../x402/types.js";
1418
export { verifyPayment } from "../x402/verify-payment.js";

packages/thirdweb/src/x402/facilitator.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import type {
99
RequestedPaymentRequirements,
1010
} from "./schemas.js";
1111

12+
export type WaitUtil = "simulated" | "submitted" | "confirmed";
13+
1214
export type ThirdwebX402FacilitatorConfig = {
1315
client: ThirdwebClient;
1416
serverWalletAddress: string;
15-
waitUtil?: "simulated" | "submitted" | "confirmed";
17+
waitUtil?: WaitUtil;
1618
vaultAccessToken?: string;
1719
baseUrl?: string;
1820
};
@@ -37,6 +39,7 @@ export type ThirdwebX402Facilitator = {
3739
settle: (
3840
payload: RequestedPaymentPayload,
3941
paymentRequirements: RequestedPaymentRequirements,
42+
waitUtil?: WaitUtil,
4043
) => Promise<FacilitatorSettleResponse>;
4144
supported: (filters?: {
4245
chainId: number;
@@ -167,12 +170,14 @@ export function facilitator(
167170
async settle(
168171
payload: RequestedPaymentPayload,
169172
paymentRequirements: RequestedPaymentRequirements,
173+
waitUtil?: WaitUtil,
170174
): Promise<FacilitatorSettleResponse> {
171175
const url = config.baseUrl ?? DEFAULT_BASE_URL;
172176

173177
let headers = { "Content-Type": "application/json" };
174178
const authHeaders = await facilitator.createAuthHeaders();
175179
headers = { ...headers, ...authHeaders.settle };
180+
const waitUtilParam = waitUtil || config.waitUtil;
176181

177182
const res = await fetch(`${url}/settle`, {
178183
method: "POST",
@@ -181,7 +186,7 @@ export function facilitator(
181186
x402Version: payload.x402Version,
182187
paymentPayload: payload,
183188
paymentRequirements: paymentRequirements,
184-
...(config.waitUtil ? { waitUtil: config.waitUtil } : {}),
189+
...(waitUtilParam ? { waitUtil: waitUtilParam } : {}),
185190
}),
186191
});
187192

packages/thirdweb/src/x402/settle-payment.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { stringify } from "../utils/json.js";
22
import { decodePaymentRequest } from "./common.js";
33
import { safeBase64Encode } from "./encode.js";
44
import {
5-
type PaymentArgs,
5+
type SettlePaymentArgs,
66
type SettlePaymentResult,
77
x402Version,
88
} from "./types.js";
@@ -124,7 +124,7 @@ import {
124124
* @bridge x402
125125
*/
126126
export async function settlePayment(
127-
args: PaymentArgs,
127+
args: SettlePaymentArgs,
128128
): Promise<SettlePaymentResult> {
129129
const { routeConfig = {}, facilitator } = args;
130130
const { errorMessages } = routeConfig;
@@ -142,6 +142,7 @@ export async function settlePayment(
142142
const settlement = await facilitator.settle(
143143
decodedPayment,
144144
selectedPaymentRequirements,
145+
args.waitUntil,
145146
);
146147

147148
if (settlement.success) {

packages/thirdweb/src/x402/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type z from "zod";
33
import type { Chain } from "../chains/types.js";
44
import type { Address } from "../utils/address.js";
55
import type { Prettify } from "../utils/type-utils.js";
6-
import type { ThirdwebX402Facilitator } from "./facilitator.js";
6+
import type { ThirdwebX402Facilitator, WaitUtil } from "./facilitator.js";
77
import type {
88
FacilitatorNetwork,
99
FacilitatorSettleResponse,
@@ -39,6 +39,10 @@ export type PaymentArgs = {
3939
routeConfig?: PaymentMiddlewareConfig;
4040
};
4141

42+
export type SettlePaymentArgs = PaymentArgs & {
43+
waitUntil?: WaitUtil;
44+
};
45+
4246
export type PaymentRequiredResult = {
4347
/** HTTP 402 - Payment Required, verification or processing failed or payment missing */
4448
status: 402;

0 commit comments

Comments
 (0)