Skip to content

Commit bf7baa8

Browse files
committed
Add Stripe inbound transfer endpoint and createStripeInboundTransfer method
1 parent 350f10c commit bf7baa8

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { stripeV2Fetch } from "./stripe-v2-client";
2+
3+
export interface CreateStripeInboundTransferParams {
4+
amount: number;
5+
}
6+
7+
export async function createStripeInboundTransfer({
8+
amount,
9+
}: CreateStripeInboundTransferParams) {
10+
const financialAccountId = process.env.STRIPE_FINANCIAL_ACCOUNT_ID;
11+
12+
if (!financialAccountId) {
13+
throw new Error(
14+
"STRIPE_FINANCIAL_ACCOUNT_ID is not configured and no financial account was provided.",
15+
);
16+
}
17+
18+
const { data, error } = await stripeV2Fetch(
19+
"/v2/money_management/inbound_transfers",
20+
{
21+
body: {
22+
amount: {
23+
value: amount,
24+
currency: "usd",
25+
},
26+
from: {
27+
payment_method: "pm_1QZ992FZ9999999999999999", // TODO: replace with actual payment method ID
28+
},
29+
to: {
30+
financial_account: financialAccountId,
31+
currency: "usd",
32+
},
33+
},
34+
},
35+
);
36+
37+
if (error) {
38+
throw new Error(error.message);
39+
}
40+
41+
return data;
42+
}

apps/web/lib/stripe/stripe-v2-client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { prettyPrint } from "@dub/utils";
33
import {
44
createAccountLinkInputSchema,
55
createAccountLinkOutputSchema,
6+
createInboundTransferInputSchema,
67
createOutboundPaymentInputSchema,
78
createRecipientAccountInputSchema,
89
createRecipientAccountOutputSchema,
10+
inboundTransferSchema,
911
listPayoutMethodsOutputSchema,
1012
listPayoutMethodsQuerySchema,
1113
outboundPaymentSchema,
@@ -38,6 +40,11 @@ export const stripeV2Fetch = createFetch({
3840
input: createAccountLinkInputSchema,
3941
output: createAccountLinkOutputSchema,
4042
},
43+
"/v2/money_management/inbound_transfers": {
44+
method: "post",
45+
input: createInboundTransferInputSchema,
46+
output: inboundTransferSchema,
47+
},
4148
"/v2/money_management/outbound_payments": {
4249
method: "post",
4350
input: createOutboundPaymentInputSchema,

apps/web/lib/stripe/stripe-v2-schemas.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ export const createAccountLinkOutputSchema = z.object({
5353
expires_at: z.union([z.number(), z.string()]),
5454
});
5555

56+
export const createInboundTransferInputSchema = z.object({
57+
amount: z.object({
58+
currency: z.string(),
59+
value: z.number(),
60+
}),
61+
from: z.object({
62+
payment_method: z.string(),
63+
currency: z.string().optional(),
64+
}),
65+
to: z.object({
66+
currency: z.string(),
67+
financial_account: z.string(),
68+
}),
69+
description: z.string().optional(),
70+
});
71+
72+
export const inboundTransferSchema = z.object({
73+
id: z.string(),
74+
});
75+
5676
export const createOutboundPaymentInputSchema = z.object({
5777
amount: z.object({
5878
currency: z.string(),

0 commit comments

Comments
 (0)