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