DeveloperBreeze

Laravel Programming Tutorials, Guides & Best Practices

Explore 51+ expertly crafted laravel tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Tutorial
php

Integrating and Using NMI Payment Gateway in Laravel

   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;
   }

This method uses the customer’s vault ID to process a payment for the specified amount. It handles test mode and logs the payment response using Laravel’s info logging.

Aug 14, 2024
Read More