我只是想知道是否有办法检索 strip 中多个 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\Charge::all(["limit"=> 3])
调用 [0] 会返回多次费用,直到参数中指定的限制[1].
在对上述请求的响应中,您将收到一组收费对象 [2],每个对象都有一个作为收费 ID 的 id
字段 [3]。
希望对您有所帮助!如果您有任何问题,请告诉我。
干杯,
健康
[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
关于php - 在 php 中检索多个 strip 费用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53308243/