DeveloperBreeze

Payment Processing Development Tutorials, Guides & Insights

Unlock 1+ expert-curated payment processing tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your payment processing skills on DeveloperBreeze.

Integrating and Using NMI Payment Gateway in Laravel

Tutorial August 14, 2024
php

Inside the NMI class, add the following method:

   public function addCustomerVault($creditCard)
   {
       $data = [
           'ccnumber' => $creditCard['cc_number'],
           'ccexp' => $creditCard['exp_date'],
           'cvv' => $creditCard['cvv'],
           'customer_vault' => 'add_customer',
           'security_key' => $this->securityKey,
       ];

       if ($this->production === false) {
           $data['test_mode'] = 'enabled';
       }

       $createVaultCurl = curl_init();
       curl_setopt_array($createVaultCurl, [
           CURLOPT_URL => $this->url,
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_POST => true,
           CURLOPT_POSTFIELDS => http_build_query($data),
           CURLOPT_SSL_VERIFYHOST => false,
           CURLOPT_SSL_VERIFYPEER => false,
       ]);
       $createVaultResponse = curl_exec($createVaultCurl);
       curl_close($createVaultCurl);

       \Log::info('NMI Vault Response: ' . $createVaultResponse);

       if ($createVaultResponse === false) {
           return [
               'responsetext' => 'error',
               'error' => 'Customer vault creation failed',
           ];
       }

       parse_str($createVaultResponse, $vaultResponseArray);
       return isset($vaultResponseArray['customer_vault_id']) ? $vaultResponseArray['customer_vault_id'] : null;
   }