DeveloperBreeze

Nmi Development Tutorials, Guides & Insights

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

Integrating and Using NMI Payment Gateway in Laravel

Tutorial August 14, 2024
php

Add the following method to the NMI class:

   public function processPaymentUsingVault($customerVaultId, $totalAmount)
   {
       $data = [
           'security_key' => $this->securityKey,
           'customer_vault_id' => $customerVaultId,
           'amount' => $totalAmount,
       ];

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

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

       if ($response === false) {
           return [
               'responsetext' => 'error',
               'error' => 'Payment processing failed',
           ];
       }

       \Log::info('NMI Payment Response: ' . $response);

       parse_str($response, $parsedResponse);

       return $parsedResponse;
   }