go - 连接帐户并创建订阅而不是一次性付款

标签 go stripe-payments

我是一个小市场。有推荐/连接帐户 (A) 和用户 (B)。 推荐带来了新用户,而用户就是那些为某些服务付费的人。付款将被分割:90% 将支付给带来特定用户的推荐人,10% 将支付给市场。

用户有 2 个选项:一次性付款或创建订阅。我已经实现了前者并且运行良好,这是代码的一部分:

    //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)

我想对订阅做同样的事情。怎么做?

此代码是用 Go 语言编写的,但我也能够理解其他语言的代码。

最佳答案

下面的代码应该可以工作

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_..."),
  },
}

关于go - 连接帐户并创建订阅而不是一次性付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68790477/

相关文章:

javascript - 如何为 Meteor 1.3 安装 Stripe?

go - 使用GO导航时如何使用Context?

unit-testing - 尝试在 TCP 监听器上提供服务时,由于超时,Go 测试模棱两可地失败

go - 如何使用 interface{} 作为通配符类型?

python google app engine strip 集成

javascript - Stripe 连接: What's the difference between Customers and Accounts?

ios - paymentRequestWithMerchantIdentifier NSInvalidArgumentException 错误

reactjs - 如何在 React 测试中加载 Stripe?

database - 查询Postgresql时偶尔会出现 "connection timed out"错误

go - 修改 vendor 文件中的结构类型