在php中检索多个条带费用

时间:2018-11-14 20:26:56

标签: php stripe-payments

我只想知道是否有办法检索带区中具有charges_id倍数的费用。

例如docs中的示例显示了如何收取费用。但是我们需要收取多项费用。因此,我们不想对stripe方法的检索进行多次调用,这很慢。我们不想这样做:

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。

感谢您的帮助。

谢谢,我很抱歉我的英语水平。

1 个答案:

答案 0 :(得分:2)

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

您是正确的,因为df['Date']=['05.01.2017','05.01.2017']调用[0]将向您返回多项费用,最高为参数[1]中指定的限制。

在响应上述请求时,您将收到一组收费对象[2],每个收费对象都有一个df1= pd.to_datetime(df['Date'])字段[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