Fix: Correct Display of last 4 digits of credit card
This commit is contained in:
@@ -49,6 +49,8 @@ class TransactionRecorder
|
|||||||
'reference' => $result->reference,
|
'reference' => $result->reference,
|
||||||
'status' => $result->status->name,
|
'status' => $result->status->name,
|
||||||
'notes' => $result->failureReason,
|
'notes' => $result->failureReason,
|
||||||
|
'card_type' => $result->meta['card_type'] ?? null,
|
||||||
|
'last_four' => $result->meta['last_four'] ?? null,
|
||||||
'meta' => $result->meta,
|
'meta' => $result->meta,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class StripePaymentDriver implements
|
|||||||
reference: $paymentIntent->id,
|
reference: $paymentIntent->id,
|
||||||
amount: $amount,
|
amount: $amount,
|
||||||
raw: $paymentIntent->toArray(),
|
raw: $paymentIntent->toArray(),
|
||||||
|
meta: $this->cardMetaFromIntent($paymentIntent),
|
||||||
);
|
);
|
||||||
|
|
||||||
$paymentIntent->status === PaymentIntent::STATUS_SUCCEEDED
|
$paymentIntent->status === PaymentIntent::STATUS_SUCCEEDED
|
||||||
@@ -340,6 +341,7 @@ class StripePaymentDriver implements
|
|||||||
amount: $amount,
|
amount: $amount,
|
||||||
failureReason: $paymentIntent->last_payment_error->message ?? null,
|
failureReason: $paymentIntent->last_payment_error->message ?? null,
|
||||||
raw: $paymentIntent->toArray(),
|
raw: $paymentIntent->toArray(),
|
||||||
|
meta: $status === PaymentResultStatus::Pending ? [] : $this->cardMetaFromIntent($paymentIntent),
|
||||||
continuation: $continuation,
|
continuation: $continuation,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -362,6 +364,40 @@ class StripePaymentDriver implements
|
|||||||
return $result;
|
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
|
private function declined(string $type, Price $amount, ApiErrorException $e, array $context, bool $authorizing): PaymentResult
|
||||||
{
|
{
|
||||||
$result = $this->failure($amount, $e);
|
$result = $this->failure($amount, $e);
|
||||||
|
|||||||
Reference in New Issue
Block a user