我正在建立一个市场(你可以想象它像一个易趣,那里有买家和卖家)。我想得到一个项目,购买客户(反之亦然与卖方)。
下面是我的结帐会话服务:
async charge(userId: number, dto: CreateChargeDto) {
//Get an item by id
const item = await this.prisma.item.findUnique({
where: {
id: dto.itemId,
},
});
if (!item) {
throw new BadRequestException('There is no item with this id');
}
// Search for user
const user = await this.prisma.user.findUnique({
where: {
id: userId,
},
});
//update customer
await this.updateCustomer(user.stripeCustomerId, dto);
const session = await this.stripe.checkout.sessions.create({
success_url: 'http://localhost:3000/success?message=Succesful+payment',
cancel_url: 'http://localhost:3000/404?message=Payment+canceled',
mode: 'payment',
currency: 'pln',
customer: user.stripeCustomerId,
customer_update: {
address: 'auto',
},
metadata: {
seller_id: item.userId, // here is where i save seller id
},
line_items: [
{
quantity: 1,
price_data: {
currency: 'pln',
unit_amount: item.price * 100,
product_data: {
name: item.name,
images: item.images,
metadata: {
id: item.id,
},
},
},
},
],
});
return session.id;
}
async getCheckoutList(userId: number) {
const user = await this.prisma.user.findUnique({
where: {
id: userId,
},
});
const checkouts = await this.stripe.
return checkouts.data;
}
现在我想筛选此会话 checkout ,这样我就可以显示在买方(或卖方)个人页面。
const checkouts = await this.stripe.checkout.sessions.list({
where: {
metadata: {
seller_id: // seller id
}
}
我该怎么做呢?
1条答案
按热度按时间hrirmatl1#
目前无法通过元数据过滤 checkout 会话。
其他一些选项包括:
checkout.session.completed
webhook事件,将数据保存到DB中,然后执行自己的过滤。有关处理webhook的更多信息,请参见https://stripe.com/docs/webhooks。要按客户筛选结帐会话,您可以使用https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-customer