通过Parse.com云代码取消条纹计划,查询问题

Cancelling Stripe Plan Through Parse.com Cloud Code, Query issue

本文关键字:计划 查询 问题 取消 Parse com 代码 通过      更新时间:2023-09-26

我一直试图通过解析云代码取消条纹计划,但收效甚微。我遇到的问题是CC查询获取用户Stripe ID,我将其保存在名为Payments的Parse类中。在Payments类中,我还有一个指向用户类的指针,该用户类的Parse对象化。

我对Java脚本、解析和云代码非常陌生。因此,这可能有一个非常简单的解决方案。但我花了几天时间在这方面,阅读了我能找到的每一篇帖子,但都没有成功。

这是我正在使用的代码:

Parse.Cloud.define("cancel", function(request, response) {
var user = request.user;
var payments = Parse.Object.extend("Payments");
var query = new Parse.Query(payments);
query.include("parent")
query.equalTo("parent", {
                "__type": "Pointer",
                "className": "_user",
                "objectId": user.id
                });
query.find({
    success: function(results) {
          for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var customerStripeId = object.get("stripeID");
          var key = 'sk_test_ONbnGBHHcsmOMFtSifV3JD2S';
          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 + "for" + user.id +" "+ customerStripeId);
                    response.failure()
                }}
            });
      },
    error: function(error) {
        alert("Error: " + error.code + " " + error.message);
      }
    });
});

我还尝试过使用以下代码获取查询,但没有成功:

Parse.Cloud.define("cancel", function(request, response) {
var user = request.user;
var payments = Parse.Object.extend("Payments");
var query = new Parse.Query(payments);
query.include("parent")
query.equalTo("parent", {
                "__type": "Pointer",
                "className": "_user",
                "objectId": user.id
                });
var customerStripeId = query.get("stripeID");
var key = 'sk_test_ONbnGBHHcsmOMFtSifV3JD2S';
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 + "for" + user.id +" "+ customerStripeId);
        response.error()
    }
});

});

同样,我的问题是设置customerStripeId变量。其余代码运行良好,我知道这一点,因为如果我手动在customerStripeId的代码中放入用户条带ID(并一起跳过查询)。功能正常。

如果能在这个问题上得到任何帮助,我将不胜感激。

提前感谢:)

对于其他有同样问题的人,我终于找到了答案。我相信问题出在指针上。我现在使用的是"query.equalTo("parent",user);",取消操作没有任何问题。