如何将此 cURL 请求从 Stripe API 转换为来自 Parse javascript API 的 httpRequest

How to convert this cURL request from the Stripe API to an httpRequest from the Parse javascript API

一如既往,提前致谢。你们真棒,就为了读到这里。

我使用 Parse 作为我的后端,并使用 Stripe 作为我的支付 API。 Parse 有一些条带集成,但不是完整的 API,因此要访问未内置到 Parse 中的 API 部分,您必须使用 http 请求。

我正在为我的应用程序添加优惠券功能,因此,有时需要直接向我的 Stripe 管理账户生成转账,因为客户支付的金额可能少于收款人需要收到的金额。这是 cURL 代码,找到 in Stripe's API documentation,我需要将其转换为 http 请求:

    curl https://api.stripe.com/v1/transfers \
   -u [secret api key]: \
   -d amount=400 \
   -d destination=[account id] 

"Transfer to test@example.com"

这是我在代码中使用的 Parse.Cloud.httpRequest:

Parse.Cloud.httpRequest
(
    {
        method:"POST",
        url: "https://" + STRIPE_SECRET_KEY + ':@' + STRIPE_API_BASE_URL + "/transfers?amount=" + amountOwedProvider.toString() + "&destination=" + recipient_id
    }
);

STRIPE_API_BASE_URL 是 'api.stripe.com/v1'

amountOwedProvider 是我仍然需要发送给提供者的数字,以美分为单位

recipient_id 是格式正确的条带收件人 ID。我也在生成初始费用时使用它。

当我发出此请求时,我的 Stripe 日志中出现以下错误:

"Unrecognized request URL (POST: /v1/transfers)

我尝试过同时使用 transfer 和 transfers,尽管文档要求 transfers。我也尝试过使用 transfers/?amount... 而不是 transfers?amount,但收到同样的错误。

关于如何正确创建此 http 请求的任何提示?我真的很感激任何指导。

谢谢, 杰克

我是个白痴。我从此处找到的 cURL 请求开始:https://stripe.com/docs/connect/special-case-transfers

您可能会注意到它没有在我在问题中发布的 api 文档 link 的实际代码中找到的货币参数。事实证明,这是一个必需的参数。我认为,因为它不在我首先发现的 link 中,所以它是一个可选参数,如果未指定,将使用默认货币。错误的。我只需要在我的请求中添加 currency=usd url。我的最终请求如下所示:

Parse.Cloud.httpRequest
(
    {
        method:"POST",
        url: "https://" + STRIPE_SECRET_KEY + ':@' + STRIPE_API_BASE_URL + "/transfers?currency=usd&amount=" + amountOwedProvider.toString() + "&destination=" + recipient_id
    }
);