Managing Entries
Update existing customer information and delete entries as needed.
All vault operations require the
customer_vault_id
to identify the specific customer record.
Updating Customer
The following is an example code snippet for updating an existing. Full parameter support can be seen in the API Reference under the "Update Customer" request.
Server-side Example
// Update customer in vault
router.post('/update-vault', async (req, res) => {
try {
const { customerVaultId, paymentToken, billingData, shippingData } = req.body;
const response = await axios.post('https://secure.networkmerchants.com/api/transact.php', {
security_key: '{user.privateApiKey}',
customer_vault: 'update_customer',
customer_vault_id: customerVaultId,
payment_token: paymentToken,
first_name: billingData.firstName,
last_name: billingData.lastName,
address1: billingData.address1,
city: billingData.city,
state: billingData.state,
zip: billingData.zip,
country: billingData.country,
phone: billingData.phone,
email: billingData.email,
company: billingData.company,
shipping_first_name: shippingData.firstName,
shipping_last_name: shippingData.lastName,
shipping_address1: shippingData.address1,
shipping_city: shippingData.city,
shipping_state: shippingData.state,
shipping_zip: shippingData.zip,
shipping_country: shippingData.country,
shipping_phone: shippingData.phone,
shipping_email: shippingData.email,
shipping_company: shippingData.company
});
if (response.data.response === '1') {
return res.json({ success: true });
} else {
return res.json({
success: false,
error: response.data.responsetext
});
}
} catch (error) {
console.error('Error updating vault:', error);
return res.status(500).json({
success: false,
error: 'An error occurred while updating vault'
});
}
});
# Update customer in vault
import requests
def update_vault_entry(vault_id, payment_token, billing_data, shipping_data):
try:
payload = {
'security_key': '{user.privateApiKey}',
'customer_vault': 'update_customer',
'customer_vault_id': vault_id,
'payment_token': payment_token,
'first_name': billing_data['firstName'],
'last_name': billing_data['lastName'],
'address1': billing_data['address1'],
'city': billing_data['city'],
'state': billing_data['state'],
'zip': billing_data['zip'],
'country': billing_data['country'],
'phone': billing_data['phone'],
'email': billing_data['email'],
'company': billing_data['company'],
'shipping_first_name': shipping_data['firstName'],
'shipping_last_name': shipping_data['lastName'],
'shipping_address1': shipping_data['address1'],
'shipping_city': shipping_data['city'],
'shipping_state': shipping_data['state'],
'shipping_zip': shipping_data['zip'],
'shipping_country': shipping_data['country'],
'shipping_phone': shipping_data['phone'],
'shipping_email': shipping_data['email'],
'shipping_company': shipping_data['company']
}
response = requests.post(
'https://secure.networkmerchants.com/api/transact.php',
data=payload
)
response_data = dict(x.split('=') for x in response.text.split('&'))
if response_data.get('response') == '1':
print('Customer updated in vault successfully')
return True
else:
raise Exception(response_data.get('responsetext', 'Failed to update customer'))
except Exception as error:
print(f'Error updating vault: {error}')
raise error
// Update customer in vault
@PostMapping("/update-vault")
public ResponseEntity<Map<String, Object>> updateVaultEntry(@RequestBody UpdateVaultRequest request) {
try {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("security_key", "{user.privateApiKey}");
params.add("customer_vault", "update_customer");
params.add("customer_vault_id", request.getCustomerVaultId());
params.add("payment_token", request.getPaymentToken());
params.add("first_name", request.getBillingData().getFirstName());
params.add("last_name", request.getBillingData().getLastName());
params.add("address1", request.getBillingData().getAddress1());
params.add("city", request.getBillingData().getCity());
params.add("state", request.getBillingData().getState());
params.add("zip", request.getBillingData().getZip());
params.add("country", request.getBillingData().getCountry());
params.add("phone", request.getBillingData().getPhone());
params.add("email", request.getBillingData().getEmail());
params.add("company", request.getBillingData().getCompany());
params.add("shipping_first_name", request.getShippingData().getFirstName());
params.add("shipping_last_name", request.getShippingData().getLastName());
params.add("shipping_address1", request.getShippingData().getAddress1());
params.add("shipping_city", request.getShippingData().getCity());
params.add("shipping_state", request.getShippingData().getState());
params.add("shipping_zip", request.getShippingData().getZip());
params.add("shipping_country", request.getShippingData().getCountry());
params.add("shipping_phone", request.getShippingData().getPhone());
params.add("shipping_email", request.getShippingData().getEmail());
params.add("shipping_company", request.getShippingData().getCompany());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.exchange(
"https://secure.networkmerchants.com/api/transact.php",
HttpMethod.POST,
entity,
String.class
);
Map<String, String> responseData = parseQueryString(response.getBody());
Map<String, Object> result = new HashMap<>();
if ("1".equals(responseData.get("response"))) {
result.put("success", true);
} else {
result.put("success", false);
result.put("error", responseData.getOrDefault("responsetext", "Failed to update customer"));
}
return ResponseEntity.ok(result);
} catch (Exception error) {
System.err.println("Error updating vault: " + error.getMessage());
Map<String, Object> errorResult = new HashMap<>();
errorResult.put("success", false);
errorResult.put("error", "An error occurred while updating vault");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
}
}
// Update customer in vault
[HttpPost("update-vault")]
public async Task<IActionResult> UpdateVaultEntry([FromBody] UpdateVaultRequest request)
{
try
{
var formData = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("security_key", "{user.privateApiKey}"),
new KeyValuePair<string, string>("customer_vault", "update_customer"),
new KeyValuePair<string, string>("customer_vault_id", request.CustomerVaultId),
new KeyValuePair<string, string>("payment_token", request.PaymentToken),
new KeyValuePair<string, string>("first_name", request.BillingData.FirstName),
new KeyValuePair<string, string>("last_name", request.BillingData.LastName),
new KeyValuePair<string, string>("address1", request.BillingData.Address1),
new KeyValuePair<string, string>("city", request.BillingData.City),
new KeyValuePair<string, string>("state", request.BillingData.State),
new KeyValuePair<string, string>("zip", request.BillingData.Zip),
new KeyValuePair<string, string>("country", request.BillingData.Country),
new KeyValuePair<string, string>("phone", request.BillingData.Phone),
new KeyValuePair<string, string>("email", request.BillingData.Email),
new KeyValuePair<string, string>("company", request.BillingData.Company),
new KeyValuePair<string, string>("shipping_first_name", request.ShippingData.FirstName),
new KeyValuePair<string, string>("shipping_last_name", request.ShippingData.LastName),
new KeyValuePair<string, string>("shipping_address1", request.ShippingData.Address1),
new KeyValuePair<string, string>("shipping_city", request.ShippingData.City),
new KeyValuePair<string, string>("shipping_state", request.ShippingData.State),
new KeyValuePair<string, string>("shipping_zip", request.ShippingData.Zip),
new KeyValuePair<string, string>("shipping_country", request.ShippingData.Country),
new KeyValuePair<string, string>("shipping_phone", request.ShippingData.Phone),
new KeyValuePair<string, string>("shipping_email", request.ShippingData.Email),
new KeyValuePair<string, string>("shipping_company", request.ShippingData.Company)
});
var response = await _httpClient.PostAsync(
"https://secure.networkmerchants.com/api/transact.php",
formData
);
var responseContent = await response.Content.ReadAsStringAsync();
var responseData = ParseQueryString(responseContent);
if (responseData.ContainsKey("response") && responseData["response"] == "1")
{
return Ok(new { success = true });
}
else
{
return BadRequest(new
{
success = false,
error = responseData.GetValueOrDefault("responsetext", "Failed to update customer")
});
}
}
catch (Exception ex)
{
return StatusCode(500, new
{
success = false,
error = "An error occurred while updating vault"
});
}
}
<?php
// Update customer in vault
function updateVaultEntry($vaultId, $paymentToken, $billingData, $shippingData) {
try {
$payload = [
'security_key' => '{user.privateApiKey}',
'customer_vault' => 'update_customer',
'customer_vault_id' => $vaultId,
'payment_token' => $paymentToken,
'first_name' => $billingData['firstName'],
'last_name' => $billingData['lastName'],
'address1' => $billingData['address1'],
'city' => $billingData['city'],
'state' => $billingData['state'],
'zip' => $billingData['zip'],
'country' => $billingData['country'],
'phone' => $billingData['phone'],
'email' => $billingData['email'],
'company' => $billingData['company'],
'shipping_first_name' => $shippingData['firstName'],
'shipping_last_name' => $shippingData['lastName'],
'shipping_address1' => $shippingData['address1'],
'shipping_city' => $shippingData['city'],
'shipping_state' => $shippingData['state'],
'shipping_zip' => $shippingData['zip'],
'shipping_country' => $shippingData['country'],
'shipping_phone' => $shippingData['phone'],
'shipping_email' => $shippingData['email'],
'shipping_company' => $shippingData['company']
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://secure.networkmerchants.com/api/transact.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
throw new Exception('cURL error occurred');
}
// Parse the response (NMI returns form-encoded data)
parse_str($response, $responseData);
if ($responseData['response'] === '1') {
return ['success' => true];
} else {
return [
'success' => false,
'error' => $responseData['responsetext'] ?? 'Failed to update customer'
];
}
} catch (Exception $error) {
error_log('Error updating vault: ' . $error->getMessage());
return [
'success' => false,
'error' => 'An error occurred while updating vault'
];
}
}
// Example usage
function handleUpdateVault() {
$billingData = [
'firstName' => 'John',
'lastName' => 'Doe',
'address1' => '123 Main St',
'city' => 'Anytown',
'state' => 'CA',
'zip' => '12345',
'country' => 'US',
'phone' => '555-123-4567',
'email' => '[email protected]',
'company' => 'Acme Corp'
];
$shippingData = [
'firstName' => 'John',
'lastName' => 'Doe',
'address1' => '456 Oak Ave',
'city' => 'Somewhere',
'state' => 'CA',
'zip' => '54321',
'country' => 'US',
'phone' => '555-987-6543',
'email' => '[email protected]',
'company' => 'Acme Corp'
];
$result = updateVaultEntry('cust_12345', $paymentToken, $billingData, $shippingData);
if ($result['success']) {
echo 'Customer updated in vault successfully';
} else {
echo 'Error: ' . $result['error'];
}
}
// REST API endpoint example
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['REQUEST_URI'] === '/update-vault') {
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
if (!$input) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Invalid JSON input']);
exit;
}
$result = updateVaultEntry(
$input['customerVaultId'],
$input['paymentToken'],
$input['billingData'],
$input['shippingData']
);
if ($result['success']) {
http_response_code(200);
} else {
http_response_code(500);
}
echo json_encode($result);
}
?>
<?php
// app/Http/Controllers/CustomerVaultController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CustomerVaultController extends Controller
{
/**
* Update customer in vault
*/
public function updateVault(Request $request): JsonResponse
{
$request->validate([
'customerVaultId' => 'required|string',
'paymentToken' => 'required|string',
'billingData' => 'required|array',
'billingData.firstName' => 'required|string',
'billingData.lastName' => 'required|string',
'billingData.address1' => 'required|string',
'billingData.city' => 'required|string',
'billingData.state' => 'required|string',
'billingData.zip' => 'required|string',
'billingData.country' => 'required|string',
'billingData.phone' => 'required|string',
'billingData.email' => 'required|email',
'billingData.company' => 'nullable|string',
'shippingData' => 'required|array',
'shippingData.firstName' => 'required|string',
'shippingData.lastName' => 'required|string',
'shippingData.address1' => 'required|string',
'shippingData.city' => 'required|string',
'shippingData.state' => 'required|string',
'shippingData.zip' => 'required|string',
'shippingData.country' => 'required|string',
'shippingData.phone' => 'required|string',
'shippingData.email' => 'required|email',
'shippingData.company' => 'nullable|string'
]);
try {
$response = Http::asForm()->post('https://secure.networkmerchants.com/api/transact.php', [
'security_key' => '{user.privateApiKey}',
'customer_vault' => 'update_customer',
'customer_vault_id' => $request->customerVaultId,
'payment_token' => $request->paymentToken,
'first_name' => $request->billingData['firstName'],
'last_name' => $request->billingData['lastName'],
'address1' => $request->billingData['address1'],
'city' => $request->billingData['city'],
'state' => $request->billingData['state'],
'zip' => $request->billingData['zip'],
'country' => $request->billingData['country'],
'phone' => $request->billingData['phone'],
'email' => $request->billingData['email'],
'company' => $request->billingData['company'] ?? '',
'shipping_first_name' => $request->shippingData['firstName'],
'shipping_last_name' => $request->shippingData['lastName'],
'shipping_address1' => $request->shippingData['address1'],
'shipping_city' => $request->shippingData['city'],
'shipping_state' => $request->shippingData['state'],
'shipping_zip' => $request->shippingData['zip'],
'shipping_country' => $request->shippingData['country'],
'shipping_phone' => $request->shippingData['phone'],
'shipping_email' => $request->shippingData['email'],
'shipping_company' => $request->shippingData['company'] ?? ''
]);
$responseData = $this->parseNmiResponse($response->body());
if ($responseData['response'] === '1') {
return response()->json(['success' => true]);
} else {
return response()->json([
'success' => false,
'error' => $responseData['responsetext'] ?? 'Failed to update customer'
], 400);
}
} catch (\Exception $e) {
Log::error('Error updating vault: ' . $e->getMessage());
return response()->json([
'success' => false,
'error' => 'An error occurred while updating vault'
], 500);
}
}
/**
* Parse NMI's form-encoded response
*/
private function parseNmiResponse(string $response): array
{
parse_str($response, $data);
return $data;
}
}
Deleting Customer
The following example shows all required parameters for deleting a customer from the vault. For additional reference, see the "Delete Customer" in our API documentation.
Server-side Example
// Delete customer from vault
router.post('/delete-vault', async (req, res) => {
try {
const { customerVaultId } = req.body;
const response = await axios.post('https://secure.networkmerchants.com/api/transact.php', {
security_key: '3u7CzetHVcAb6CZ4DUuNJeK425RUE8E4',
customer_vault: 'delete_customer',
customer_vault_id: customerVaultId
});
if (response.data.response === '1') {
return res.json({ success: true });
} else {
return res.json({
success: false,
error: response.data.responsetext
});
}
} catch (error) {
console.error('Error deleting from vault:', error);
return res.status(500).json({
success: false,
error: 'An error occurred while deleting from vault'
});
}
});
# Delete customer from vault
import requests
def delete_vault_entry(vault_id):
try:
payload = {
'security_key': '3u7CzetHVcAb6CZ4DUuNJeK425RUE8E4',
'customer_vault': 'delete_customer',
'customer_vault_id': vault_id
}
response = requests.post(
'https://secure.networkmerchants.com/api/transact.php',
data=payload
)
response_data = dict(x.split('=') for x in response.text.split('&'))
if response_data.get('response') == '1':
print('Customer deleted from vault successfully')
return True
else:
raise Exception(response_data.get('responsetext', 'Failed to delete customer'))
except Exception as error:
print(f'Error deleting from vault: {error}')
raise error
// Delete customer from vault
@PostMapping("/delete-vault")
public ResponseEntity<Map<String, Object>> deleteVaultEntry(@RequestBody DeleteVaultRequest request) {
try {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("security_key", "3u7CzetHVcAb6CZ4DUuNJeK425RUE8E4");
params.add("customer_vault", "delete_customer");
params.add("customer_vault_id", request.getCustomerVaultId());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.exchange(
"https://secure.networkmerchants.com/api/transact.php",
HttpMethod.POST,
entity,
String.class
);
Map<String, String> responseData = parseQueryString(response.getBody());
Map<String, Object> result = new HashMap<>();
if ("1".equals(responseData.get("response"))) {
result.put("success", true);
} else {
result.put("success", false);
result.put("error", responseData.getOrDefault("responsetext", "Failed to delete customer"));
}
return ResponseEntity.ok(result);
} catch (Exception error) {
System.err.println("Error deleting from vault: " + error.getMessage());
Map<String, Object> errorResult = new HashMap<>();
errorResult.put("success", false);
errorResult.put("error", "An error occurred while deleting from vault");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
}
}
// Delete customer from vault
@PostMapping("/delete-vault")
public ResponseEntity<Map<String, Object>> deleteVaultEntry(@RequestBody DeleteVaultRequest request) {
try {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("security_key", "3u7CzetHVcAb6CZ4DUuNJeK425RUE8E4");
params.add("customer_vault", "delete_customer");
params.add("customer_vault_id", request.getCustomerVaultId());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.exchange(
"https://secure.networkmerchants.com/api/transact.php",
HttpMethod.POST,
entity,
String.class
);
Map<String, String> responseData = parseQueryString(response.getBody());
Map<String, Object> result = new HashMap<>();
if ("1".equals(responseData.get("response"))) {
result.put("success", true);
} else {
result.put("success", false);
result.put("error", responseData.getOrDefault("responsetext", "Failed to delete customer"));
}
return ResponseEntity.ok(result);
} catch (Exception error) {
System.err.println("Error deleting from vault: " + error.getMessage());
Map<String, Object> errorResult = new HashMap<>();
errorResult.put("success", false);
errorResult.put("error", "An error occurred while deleting from vault");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
}
}
<?php
// Delete customer from vault
function deleteVaultEntry($vaultId) {
try {
$payload = [
'security_key' => '3u7CzetHVcAb6CZ4DUuNJeK425RUE8E4',
'customer_vault' => 'delete_customer',
'customer_vault_id' => $vaultId
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://secure.networkmerchants.com/api/transact.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
throw new Exception('cURL error occurred');
}
// Parse the response (NMI returns form-encoded data)
parse_str($response, $responseData);
if ($responseData['response'] === '1') {
return ['success' => true];
} else {
return [
'success' => false,
'error' => $responseData['responsetext'] ?? 'Failed to delete customer'
];
}
} catch (Exception $error) {
error_log('Error deleting from vault: ' . $error->getMessage());
return [
'success' => false,
'error' => 'An error occurred while deleting from vault'
];
}
}
// Example usage
function handleDeleteVault() {
$result = deleteVaultEntry('cust_12345');
if ($result['success']) {
echo 'Customer deleted from vault successfully';
} else {
echo 'Error: ' . $result['error'];
}
}
// REST API endpoint example
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['REQUEST_URI'] === '/delete-vault') {
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
if (!$input || !isset($input['customerVaultId'])) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Invalid JSON input or missing customerVaultId']);
exit;
}
$result = deleteVaultEntry($input['customerVaultId']);
if ($result['success']) {
http_response_code(200);
} else {
http_response_code(500);
}
echo json_encode($result);
}
?>
<?php
// app/Http/Controllers/CustomerVaultController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CustomerVaultController extends Controller
{
/**
* Delete customer from vault
*/
public function deleteVault(Request $request): JsonResponse
{
$request->validate([
'customerVaultId' => 'required|string'
]);
try {
$response = Http::asForm()->post('https://secure.networkmerchants.com/api/transact.php', [
'security_key' => config('services.nmi.security_key'),
'customer_vault' => 'delete_customer',
'customer_vault_id' => $request->customerVaultId
]);
$responseData = $this->parseNmiResponse($response->body());
if ($responseData['response'] === '1') {
return response()->json(['success' => true]);
} else {
return response()->json([
'success' => false,
'error' => $responseData['responsetext'] ?? 'Failed to delete customer'
], 400);
}
} catch (\Exception $e) {
Log::error('Error deleting from vault: ' . $e->getMessage());
return response()->json([
'success' => false,
'error' => 'An error occurred while deleting from vault'
], 500);
}
}
/**
* Parse NMI's form-encoded response
*/
private function parseNmiResponse(string $response): array
{
parse_str($response, $data);
return $data;
}
}
Updated 17 days ago