Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need to store only last 4 digits of credit card

I am using Braintree for payment gateway.
I have a requirement where I need to store only last 4 digits of credit card, expiry date (As per PCI Complaince).
I have implemented front-end code in javascript and on sending data to server, credit card information is encrypted.
Is there anyway I can get last four digits, expiry date and card type at backend or can I decrypt it?

<form name="paymentForm" action="/createtransaction" method="post" id="braintree-payment-form">
   <p>
     <label style="color:white">Card Number</label>
     <input type="text" size="20" ng-model="userDetails.number" autocomplete="off" data-encrypted-name="number" />
   </p>
   <p>
     <label style="color:white">CVV</label>
     <input type="text" size="4" ng-model="userDetails.cvv" autocomplete="off" data-encrypted-name="cvv" />
   </p>
   <p>
     <label style="color:white">Expiration (MM/YYYY)</label>
     <input type="text" size="2" ng-model="userDetails.month" data-encrypted-name="month" /> / <input type="text" size="4" ng-model="userDetails.year" data-encrypted-name="year" />
   </p>
   <input type="submit" id="submit" />

like image 556
Abhishek Avatar asked Jan 17 '26 22:01

Abhishek


1 Answers

(Disclosure, I work for Braintree)

Since you're using client-side encryption you won't be able to get the information as it is encrypted before the transaction is created. However, once you've made the transaction, the result object will contain the first six / last four digits of the cards number and the expiration date. You can then store those values in your database.

It would look something like:

Result<Transaction> result = gateway.transaction().sale(
  ...
);
Transaction transaction = result.getTarget();
CreditCard creditCart = transaction.getCreditCard();
String last4 = creditCard.getLast4();
String expiration = creditCard.getExpirationDate();
like image 63
John Downey Avatar answered Jan 20 '26 11:01

John Downey