Oct 19, 2015
0
Level 1
Catch errors in Cashier's one off charge?
Is there a way to handle failed one off charges? In Cashier's StripeGateway, any one off charge failure returns false, seen here:
public function charge($amount, array $options = [])
{
$options = array_merge([
'currency' => $this->getCurrency(),
], $options);
$options['amount'] = $amount;
if (! array_key_exists('source', $options) && $this->billable->hasStripeId()) {
$options['customer'] = $this->billable->getStripeId();
}
if (! array_key_exists('source', $options) && ! array_key_exists('customer', $options)) {
throw new InvalidArgumentException('No payment source provided.');
}
try {
$response = StripeCharge::create($options);
} catch (StripeErrorCard $e) {
return false;
}
return $response;
}
However, a lot of useful information comes from Stripe when a charge fails (e.g. card declined) so it would be great to grab that. Is there a way to get this information another way?
Please or to participate in this conversation.