英文:
Connected accounts and creating a subscription as oppossed to one time payment
问题
我是一个小型市场。有推荐/关联账户(A)和用户(B)。
推荐可以带来新用户,而用户是支付某些服务费用的人。支付将被分成两部分:90%将归推荐人,他们带来了特定的用户,10%将作为市场费用。
对于用户有两个选项:一次性付款或创建订阅。我已经实现了前者,并且它运行良好,以下是代码的一部分:
//对于一次性付款-一切正常
if md == stripe.CheckoutSessionModePayment {
stripeParams.PaymentIntentData = &stripe.CheckoutSessionPaymentIntentDataParams{
ApplicationFeeAmount: stripe.Int64(appFeeInCents), // 价格的10%,以分为单位
TransferData: &stripe.CheckoutSessionPaymentIntentDataTransferDataParams{
Destination: stripe.String(stripeRefr.StripeAccountId), // 推荐人的Stripe关联账户ID,从数据库中获取
},
//重要!
OnBehalfOf: stripe.String(stripeRefr.StripeAccountId), // 推荐人的Stripe关联账户ID,从数据库中获取
}
} else {
//对于订阅-这样不起作用
//如何实现?
// stripeParams.SubscriptionData = &stripe.CheckoutSessionSubscriptionDataParams{
// // Items: []*stripe.SubscriptionItemsParams{
// // {
// // price: stripe.String("price_id_from_stripe_123"),
// // },
// // },
// // TransferData: &stripe.InvoiceTransferDataParams{
// // Destination: stripe.String(stripeRefr.StripeAccountId),
// // },
// // ApplicationFeePercent: stripe.Float64(cfg.Stripe.ApplicationFeePercent),
// ApplicationFeePercent: stripe.Float64(10),
// }
}
sess, err := session.New(stripeParams)
我想对订阅做同样的事情。如何实现?
这段代码是用Go语言编写的,但我也能理解其他语言的代码。
英文:
I'm a small market place. There're Referrals/Connected-accounts (A) and Users (B).
Referrals bring new users, and users are those who pay for some services. And a payment will get split: 90% will go to a Referral who's brought a particular User, and 10% to as a market place.
There're 2 options for a User: make a one time payment or create subscription. I've already implemented the former and it works fine, and here's a part of code:
//for one time payments - all is good
if md == stripe.CheckoutSessionModePayment {
stripeParams.PaymentIntentData = &stripe.CheckoutSessionPaymentIntentDataParams{
ApplicationFeeAmount: stripe.Int64(appFeeInCents), // 10% of a price, in cents
TransferData: &stripe.CheckoutSessionPaymentIntentDataTransferDataParams{
Destination: stripe.String(stripeRefr.StripeAccountId), //Stripe connected account id of a referral, retrieved from Db
},
//important!
OnBehalfOf: stripe.String(stripeRefr.StripeAccountId), //Stripe connected account id of a referral, retrieved from Db
}
} else {
//for subscriptions - this won't work
//how to implement it?
// stripeParams.SubscriptionData = &stripe.CheckoutSessionSubscriptionDataParams{
// // Items: []*stripe.SubscriptionItemsParams{
// // {
// // price: stripe.String("price_id_from_stripe_123"),
// // },
// // },
// // TransferData: &stripe.InvoiceTransferDataParams{
// // Destination: stripe.String(stripeRefr.StripeAccountId),
// // },
// // ApplicationFeePercent: stripe.Float64(cfg.Stripe.ApplicationFeePercent),
// ApplicationFeePercent: stripe.Float64(10),
// }
}
sess, err := session.New(stripeParams)
I want to do the same thing for subscriptions. How to do it?
This code is in Go lang, but I'll be able to understand code in other language too.
答案1
得分: 2
以下代码应该可以工作
params := &stripe.SubscriptionParams{
Customer: stripe.String("cus_..."),
Items: []*stripe.SubscriptionItemsParams{
{
Price: stripe.String("price_..."),
},
},
ApplicationFeePercent: stripe.Float64(10),
TransferData: &stripe.SubscriptionTransferDataParams{
Destination: stripe.String("acct_..."),
},
}
英文:
The below code should work
params := &stripe.SubscriptionParams{
Customer: stripe.String("cus_..."),
Items: []*stripe.SubscriptionItemsParams{
{
Price: stripe.String("price_..."),
},
},
ApplicationFeePercent: stripe.Float64(10),
TransferData: &stripe.SubscriptionTransferDataParams{
Destination: stripe.String("acct_..."),
},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论