Fix: Correct Display of last 4 digits of credit card
This commit is contained in:
@@ -170,6 +170,7 @@ class StripePaymentDriver implements
|
||||
reference: $paymentIntent->id,
|
||||
amount: $amount,
|
||||
raw: $paymentIntent->toArray(),
|
||||
meta: $this->cardMetaFromIntent($paymentIntent),
|
||||
);
|
||||
|
||||
$paymentIntent->status === PaymentIntent::STATUS_SUCCEEDED
|
||||
@@ -340,6 +341,7 @@ class StripePaymentDriver implements
|
||||
amount: $amount,
|
||||
failureReason: $paymentIntent->last_payment_error->message ?? null,
|
||||
raw: $paymentIntent->toArray(),
|
||||
meta: $status === PaymentResultStatus::Pending ? [] : $this->cardMetaFromIntent($paymentIntent),
|
||||
continuation: $continuation,
|
||||
);
|
||||
|
||||
@@ -362,6 +364,40 @@ class StripePaymentDriver implements
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* card_type/last_four for Modules\Core\Order\Services\
|
||||
* TransactionRecorder to map onto Transaction (see PaymentResult::
|
||||
* $meta's own docblock) — same fields, same source
|
||||
* (payment_method_details on the underlying Charge) as lunarphp/
|
||||
* stripe's own StoreCharges, just reached via latest_charge instead of
|
||||
* an order-level charge list, since this driver has no Order/Cart to
|
||||
* enumerate charges from.
|
||||
*
|
||||
* @return array{card_type?: string, last_four?: string}
|
||||
*/
|
||||
private function cardMetaFromIntent(PaymentIntent $paymentIntent): array
|
||||
{
|
||||
$chargeId = $paymentIntent->latest_charge;
|
||||
|
||||
if (blank($chargeId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$charge = Stripe::getCharge(is_string($chargeId) ? $chargeId : $chargeId->id);
|
||||
|
||||
$paymentType = collect($charge->payment_method_details)->keys()->first();
|
||||
$details = collect($charge->payment_method_details)->first();
|
||||
|
||||
if (blank($details)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_filter([
|
||||
'card_type' => $details['brand'] ?? $paymentType,
|
||||
'last_four' => $details['last4'] ?? null,
|
||||
], fn ($value) => filled($value));
|
||||
}
|
||||
|
||||
private function declined(string $type, Price $amount, ApiErrorException $e, array $context, bool $authorizing): PaymentResult
|
||||
{
|
||||
$result = $this->failure($amount, $e);
|
||||
|
||||
Reference in New Issue
Block a user