I am creating payment integration in Laravel. In there I want to save the last 4 digits of the card to the database. Here is the array I used to save the data to the database.
$return_code = Payment::where('id', $transactionId)->update([
'return_code' => $status,
'return_message' => $status == 'success'? 'Successfully Captured': 'Payment Failed - ' .$errorMessage,
'tx_ref' => $transactionReference,
'transaction_amount' => !empty($amount) ? $amount : 0.00,
'brand' => $cardType,
'last4' => str_pad(substr($maskedPAN, -4), strlen(4), '*', STR_PAD_LEFT),
'holder' => $cardholderName,
'expiry' => $expiry,
'payment_gateway' => 3,
]);
return $status == 'success'?true : false;
From this code, it saves the last four digits to the database, only if the last four digits start without zero. It means if the card number is as 4111 1111 1111 1111 it saves to the database as 1111.
But, if the last four digits of the card starts with zero, it saves only 111 to the database. It means if the card number is as 4000 4000 0000 0111 it saves only 111 to the database.
Please help me to save the last four digits of the card even if the last four digits start with zero as 4000 4000 0000 0111.
Thank you.