【问题标题】:Retrieve a multiple stripe charges in php在php中检索多个条带费用
【发布时间】:2019-04-17 21:27:27
【问题描述】:

我只是想知道是否有办法在条带中检索多个charges_id 的费用。

例如在docs 中展示如何收取一次费用。但我们需要多次收费。所以,我们不想多次调用stripe方法retrieve,这样会很慢。我们不想这样做:

foreach ($result as $p_key => $payment) {
     $charge = $this->CI->stripe_lib->retrieve_charge('ch_......', 'secret_key');
     if (isset($charge['charge'])) {
         $amount_charged = (float)$charge['charge']->amount / 100;

         // echo "<pre>";
         // print_r($amount_charged );
         // echo "</pre>";

     }
}

这是在 Codeigniter 中。这是图书馆的功能:

public function retrieve_charge($charge_id, $secret_key) {

    $errors = array();
    try {

        \Stripe\Stripe::setApiKey($secret_key);
        $charge = \Stripe\Charge::retrieve($charge_id);
        return array('charge' => $charge);

    } catch(Stripe_CardError $e) {
        $errors = array('error' => false, 'message' => 'Card was declined.', 'e' => $e);
    } catch (Stripe_InvalidRequestError $e) {
        $errors = array('error' => false, 'message' => 'Invalid parameters were supplied to Stripe\'s API', 'e' => $e);
    } catch (Stripe_AuthenticationError $e) {
        $errors = array('error' => false, 'message' => 'Authentication with Stripe\'s API failed!', 'e' => $e);
    } catch (Stripe_ApiConnectionError $e) {
        $errors = array('error' => false, 'message' => 'Network communication with Stripe failed', 'e' => $e);
    } catch (Stripe_Error $e) {
        $errors = array('error' => false, 'message' => 'Stripe error. Something wrong just happened!', 'e' => $e);
    } catch (Exception $e) {
        if (isset($e->jsonBody['error']['type']) && $e->jsonBody['error']['type'] == 'idempotency_error') {
            $errors = array('error' => false, 'message' => $e->getMessage(), 'e' => $e, 'type' => 'idempotency_error');
        } else {
            $errors = array('error' => false, 'message' => 'An error has occurred getting customer info.', 'e' => $e);
        }
    }

    return $errors;
}

使用此代码:\Stripe\Charge::all(["limit" => 3]);返回所有费用,但在文档中我没有看到此方法是否也返回了多个费用 ID。

感谢您的帮助。

谢谢,对不起我的英语。

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    感谢您的提问。看来您已经确定了使用 PHP 库检索多个费用的正确方法!

    您是正确的,\Stripe\Charge::all(["limit" =&gt; 3]) 调用 [0] 将向您返回多个费用,直至参数 [1] 中指定的限制。

    在对上述请求的响应中,您将收到一个收费对象数组 [2],每个对象都有一个 id 字段 [3],这将是收费 ID。

    希望对您有所帮助!如果您有任何问题,请告诉我。

    干杯,

    希思

    [0]https://stripe.com/docs/api/charges/list?lang=php

    [1]https://stripe.com/docs/api/charges/list?lang=php#list_charges-limit

    [2]https://stripe.com/docs/api/charges/object?lang=php

    [3]https://stripe.com/docs/api/charges/object?lang=php#charge_object-id

    【讨论】:

    • 非常感谢@hmunoz 的回答,但这需要打一个电话来收取所有费用(可能是数百或数千)。我们想要的是获取某些费用的详细信息,例如:ch_1、ch_2、ch_3、ch_50、ch_80、ch_83 等,而不会遍历所有费用。
    • 嗨@Anibal,不幸的是,目前没有办法通过指定您要查找的所有charge_ids 的数组来检索费用。我建议您使用上面的Charge::all() 函数列出所有费用,并通过指定特定日期范围或特定客户来缩小您感兴趣的费用(支持参数的完整列表 [0])。一旦你有了这个费用数组,你就可以查找你想要详细信息的charge_id。 [0]stripe.com/docs/api/charges/list?lang=php
    • 需要注意的是,Charge:All() 每次通话最多只会返回 100 笔费用 [0]。您必须使用自动分页 [1] 或使用 ending_beforestarting_after 参数 [2] 的基于光标的分页,以在前 100 个之后获取更多费用。 [0] stripe.com/docs/api/charges/list?lang=php#list_charges-limit [1] stripe.com/docs/api/pagination/auto?lang=php [2] stripe.com/docs/api/pagination?lang=php
    • 嗨@hmunoz 非常感谢您的回答。我很感激你给我的所有信息。我认为我需要评估这种情况并解决这个限制
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 2021-10-02
    • 2021-12-14
    相关资源
    最近更新 更多