【问题标题】:Trying to access data returned from Stripe API with Alamofire, but result is not valid JSON尝试使用 Alamofire 访问从 Stripe API 返回的数据,但结果不是有效的 JSON
【发布时间】:2020-09-17 12:21:17
【问题描述】:

我正在尝试使用 Alamofire 将 Swift 应用程序与 Stripe API 连接,但我在返回结果时遇到了问题。我期待有效的 JSON,但我得到以下信息:

Stripe\SetupIntent JSON: {
    "id": "seti_1Go**************g4qyJgp",
    "object": "setup_intent",
    "application": null,
    "cancellation_reason": null,
    "client_secret": "seti_1Go***************gp_secret_HM*******************ObpHy7Mk",
    "created": 1590784053,
    "customer": "cus_H*********Tna",
    "description": null,
    "last_setup_error": null,
    "livemode": false,
    "mandate": null,
    "metadata": [],
    "next_action": null,
    "on_behalf_of": null,
    "payment_method": null,
    "payment_method_options": {
        "card": {
            "request_three_d_secure": "automatic"
        }
    },
    "payment_method_types": [
        "card"
    ],
    "single_use_mandate": null,
    "status": "requires_payment_method",
    "usage": "off_session"
}

我正在使用以下 PHP 代码:

$customer = \Stripe\Customer::create();
$setupIntent = \Stripe\SetupIntent::create([
    'customer' => $customer->id
]);

$this->response($setupIntent, 200);

如何获取此对象内的 JSON?我尝试将其转换为 json,但我什么也没得到。 Alamofire 不像现在这样喜欢它。我是否需要以某种方式剥离“Stripe\SetupIntent JSON:”?

【问题讨论】:

    标签: php json swift stripe-payments


    【解决方案1】:

    您可以使用getLastResponse()访问从API返回的json对象body

    $setupIntent->getLastResponse()->body
    

    编辑。您也可以使用json_encode() 自己从对象生成 json:

    json_encode($setupIntent)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 2016-06-10
      • 2020-11-28
      • 2021-02-17
      相关资源
      最近更新 更多