簡體   English   中英

在php中檢索多個條帶費用

[英]Retrieve a multiple stripe charges in php

我只是想知道是否有辦法用條帶中的倍數charge_id檢索費用。

例如,在文檔中顯示如何獲得一次充電。 但我們需要多次收費。 所以,我們不想對條帶方法進行多次調用檢索,這樣做會很慢。 我們不想這樣做:

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\\Charge::all(["limit" => 3]) call [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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM