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

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

问题描述

我正在尝试在条带连接管理帐户上创建订阅计划。我需要一些帮助来解决这个问题。我在下面尝试了以下代码。

I am trying to create a subscription plan on a stripe connect managed account. I need some help in figuring this out. I tried the following code below.

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);
    }
});                 
});


推荐答案

我认为你应该做的不是执行直接http请求条带REST API,但使用strip node-js SDK,它将为您完成更多工作。

What i think you should do is not to execute a direct http request to stripe REST API but to use strip node-js SDK that will do it and more for you.

要在解析服务器中实现它,您需要执行以下步骤:

In order to achieve it in parse server you need to do the following steps:


  1. 在您的parse-server项目中输入以下命令




npm install stripe


这会将条带安装到你的解析中 - 服务器项目

this will install stripe into your parse-server project


  1. 在您的云代码中需要条带节点SDK

var stripe = require('stripe')(' your stripe API key ');


  1. 致电创建订阅功能,在您需要的条带对象下可用

    stripe.subscriptions.create({
      customer: "{YOUR_CUSTOMER_ID}",
      plan: "{PLAN_IDENTIFIER}"
    }, function(err, subscription) {
        // asynchronously called
      }
    );

然后,如果您需要对条带进行额外的服务调用,则可以采用相同的方式进行操作。

Then if you need additional service call to stripe you can do it in the same way.

您可以使用条带运行的所有服务都可以在这里

All the services that you can run with stripe can be found in here


当你可以使用SDK时总是更好,因为SDK让你的
生活更多很简单,在
场景后面为你处理所有的事情,通常由提供它们的公司维护(在
这种情况​​下它的条纹)

It's always better to use SDK's when you can because SDK's make your life much more easy, are handling all the things for you behind the scenes and usually are maintained by the company who provided them (in this case its stripe)

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

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