Parse中的条带模块问题

时间:2015-04-14 16:59:11

标签: node.js parse-platform stripe-payments cloud-code

我正在开发一个集成了Stripe + Parse for iOS的项目。它通过节点js使用Web钩子和云代码。目前我需要实现一些功能:

  1. 使用标记atPeriodEnd取消用户订阅;
  2. 再次订阅取消的客户(通过Stripe文档命名多个订阅)。
  3. 至于第一个:我在Parse的API中发送如下请求 -

    Stripe.Customers.cancelSubscription(request.params.customerID, 1, null)
    

    但第二个参数,即atPeriodEnd在我收到Stripe的响应时仍为0,我的webhook立即收到取消用户的请求。此外,我已检查Stripe的信息中心,查看我通过的参数,并显示“没有查询参数'”。希望你能帮我解决这个问题。

    第二个:正如我之前提到的,用户需要能够在取消后再次订阅。这意味着我已经在Stripe保存了有效的客户,我只需要附加'给他一个新的订阅。 Stripe docs有一种方法:

    stripe.customers.createSubscription("cus_00000000000", { plan: "planName" }, function(err, subscription) {  
    });
    

    但我在Parse的API中找不到类似的东西。希望你能帮助解决这个问题。

    很抱歉,如果您有任何错误或误解 - 请随时提出,我会尽可能清楚地回答。谢谢!

1 个答案:

答案 0 :(得分:0)

这是#1的解决方法 - 使用Parse.Cloud.httpRequest直接对条带端点进行http调用。 (我同意Parse云模块中的Stripe.Customers.cancelSubscription似乎不起作用)

Parse.Cloud.define("cancel", function(request, response) {
    var user = request.user;
    var customerStripeId = user.get("stripeId");
    var key = "<stripe_api_key>"
    var url = "https://api.stripe.com/v1/customers/" + customerStripeId + "/subscription"

    Parse.Cloud.httpRequest({
        method: 'DELETE',
        params: { at_period_end: true, key: key },
        url: url,
        success: function() {
            response.success()
        },
        error: function(httpResponse) {
            console.error('Delete failed with response code ' + httpResponse.status);
            response.failure()
        }
    });

});