We are generating payment token against credit card for this we build a custom payment module which is working fine, now we want to enable the customer to save the card and choose saved card during the checkout to make the checkout process faster.

We wil not make any transacton when the customer will choose the saved card as the payment token will remain the same. we will just complete the order and update the credit card and token information afte the order will placed.

To accomplish this we will use Vault feature.can someone help in enabling vault in custom payment module.


1 Answer 1


You can do it in Event Observer. on sales_order_payment_save_before event, get all the order info.

 public function execute(EventObserver $observer) {
        $paymentOrder = $observer->getEvent()->getPayment();
        $order = $paymentOrder->getOrder(); }

Then use this data (credit card, expiry date, cvv) to create token. Then save it in sales_order_payment table.

 $inputParams = $this->_inputParamsResolver->resolve();        
        foreach ($inputParams as $inputParam) {
            if ($inputParam instanceof \Magento\Quote\Model\Quote\Payment) {
                $paymentData = $inputParam->getData('additional_data');
                    $cc_card_num =  $paymentData['cc_number'];
                    $paymentOrder->setAdditionalInformation('Expiration Month ', $paymentData['cc_exp_month']);
                    $paymentOrder->setAdditionalInformation('Expiration Year ', $paymentData['cc_exp_year']);
                    $paymentOrder->setAdditionalInformation('Name ', $paymentData['cc_owner']);
                    $paymentOrder->setAdditionalInformation('Ext. ', $paymentData['cc_ext']);
                    $paymentOrder->setAdditionalInformation('Phone', $paymentData['cc_phone']);        
                    $paymentOrder->setAdditionalInformation('order_placed', 1);        
                        $paymentOrder->setAdditionalInformation('CVV', $paymentData['cc_cid']);

In your Payment.php file, you can just define validate method, don't include the capture method.

 * Pay In Store payment method model
class PaymentMethod extends \Magento\Payment\Model\Method\Cc
{ }

Ask me, for further guidance.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.