如何通过API在Stripe关联账户中创建商品和价格?
在Stripe关联账户中创建商品和价格的解决方案
你需要在创建商品和价格时,同样指定StripeAccount参数,让操作作用于关联账户而非主账户。具体修改如下:
修改后的商品创建代码
var options = new ProductCreateOptions { Id = ProductId.ToString(), Name = "Product_name", DefaultPriceData = new ProductDefaultPriceDataOptions { UnitAmount = price, Currency = "pln" }, Expand = new List<string> { "default_price" }, }; // 指定操作的关联账户 var requestOptions = new RequestOptions { StripeAccount = "{{CONNECTED_ACCOUNT_ID}}", // 替换为实际的关联账户ID }; var createdProduct = _productService.Create(options, requestOptions); // 获取关联账户下生成的价格ID,用于后续创建支付会话 string connectedPriceId = createdProduct.DefaultPrice.Id;
核心注意点
- 因为你创建支付会话时指定了关联账户,所以该会话只能使用该账户下的资源,主账户的商品/价格无法直接复用。
- 无论创建商品、价格还是支付会话,只要操作目标是关联账户,都需要在
RequestOptions中传入对应的StripeAccount参数。 - 如果需要单独创建价格(不通过商品的默认价格),在调用
PriceService.Create时,同样要传入带StripeAccount的RequestOptions。
内容的提问来源于stack exchange,提问作者patriczi
相关产品推荐
相关产品推荐

