【问题标题】:Stripe module issues at ParseParse 中的 Stripe 模块问题
【发布时间】:2015-06-20 09:50:55
【问题描述】:

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

  1. 使用标记 atPeriodEnd 取消用户订阅;
  2. 再次订阅取消的客户(通过 Stripe 文档命名为多个订阅)。

至于第一个:我在 Parse 的 API 中发送如下请求 -

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

但是当我收到 Stripe 的响应并且我的 webhook 捕获立即取消用户的请求时,第二个参数,即 atPeriodEnd 保持为 0。我还检查了 Stripe 的仪表板以查看我传递的参数,并显示“无查询参数”。希望你能帮我解决这个问题。

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    这是 #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()
            }
        });
    
    });
    

    【讨论】:

      猜你喜欢
      • 2015-12-08
      • 2015-01-27
      • 2015-06-14
      • 2023-03-13
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      相关资源
      最近更新 更多