如何在Stripe中的已连接帐户上创建订阅计划? [英] How can i create a subscription plan on a connected account in Stripe?

查看:163
本文介绍了如何在Stripe中的已连接帐户上创建订阅计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在带区连接托管帐户上创建订阅计划.我尝试了以下代码:

I am trying to create a subscription plan on a stripe connect managed account. I tried the following code:

Parse.Cloud.define("createSubscription", function (request, response) {
 Parse.Cloud.httpRequest({
    method:"POST",
    url: "https://" + "sk_test_****************" + ':@' + "api.stripe.com/v1" + "/accounts/" + 'acct_**********' + "/plans/",  
    headers: {
    'Authorization': 'Basic ********************'
  },
  body: {
    'amount': 2000,
    'interval': 'month',
    'name': 'JPGB Plan',
    'currency': 'usd',
    'id':'first Plan',
  },
        success: function(httpResponse) {
        response.success(httpResponse.text);
        },
        error: function(httpResponse) {
        response.error('Request failed with response code' + httpResponse.status);
        }
    });                 
});

但这失败并显示404(请求的资源不存在)错误.

But this failed with a 404 (the requested resource doesn't exist) error.

这就是我的方法.

  Parse.Cloud.define("createAccountPlan", function (request, response) {
 Parse.Cloud.httpRequest({
    method:"POST",
    url: "https://" + "sk_test_****************" + ':@' + "api.stripe.com/v1/plans",  
    headers: {
    'Stripe-Account': request.params.accountId
    },
    body: {
        'amount': request.params.amount,
        'interval': 'day',
        'interval_count':request.params.intervalCount,
        'name': request.params.planName,
        'currency': 'usd',
        'id':request.params.planId,
    },
    success: function(httpResponse) {
    response.success(httpResponse.text);
    },
    error: function(httpResponse) {
    response.error('Request failed with response code' + httpResponse.status);
    }
});                 
});

推荐答案

来自 Stripe连接文档:

首选的第一个身份验证选项是使用您(平台帐户)的秘密密钥,并传递一个Stripe-Account标头,该标头标识正在为其发出请求的连接帐户.

The first, preferred, authentication option is to use your—the platform account’s—secret key and pass a Stripe-Account header identifying the connected account for which the request is being made.

(展示客户的演示)

Stripe的所有库均基于每个请求支持这种身份验证方式

这里的条带化文档有些微妙,但这意味着您可以使用相同的技术为关联帐户上的客户进行订购.您也可以使用它来为该关联帐户制作产品和计划.以及您想代表关联客户执行的其他任何操作:

Stripe docs are a little subtle here, but this means you can use the same technique to make a subscription for a customer on a connected account. You can also use it to make the products and plans for that connected account too. and anything else you want to do on behalf of the connected customer:

(async function(){
  let subscription = await stripe.subscriptions.create({
    customer: "someCustomerID",
    plan: "planID"
  },{
    stripe_account: "connectedStripeAccountID"
  });
})();

这篇关于如何在Stripe中的已连接帐户上创建订阅计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆