Skip to content
3 min read

Applying Payments to Invoices Using the SOAP API

Featured Image

The SOAP API is a web service protocol that enables developers to interact with NetSuite programmatically, allowing them to integrate NetSuite with other business applications and customize the software to meet their specific needs. 

In this article, we will explore how to apply payments to invoices in NetSuite using the SOAP API and provide some code examples in Java to help you get started.

Step 1: Authentication

Before you can start interacting with the NetSuite SOAP API, you need to authenticate your application using a set of credentials. To do this, you need to create a new instance of the NetSuiteService class, passing in your account ID, email address, and password as parameters.

NetSuiteService service = new NetSuiteService();

service.setAccount("ACCOUNT_ID");

service.setEmail("EMAIL_ADDRESS");

service.setPassword("PASSWORD");

StEp 2: Retrieve the Invoice Record

To apply a payment to an invoice in NetSuite, you first need to retrieve the invoice record using its internal ID. You can do this by calling the getRecord method of the NetSuiteService class, passing in the internal ID of the invoice record and specifying the type of record you want to retrieve (in this case, invoice).

RecordRef recordRef = new RecordRef();

recordRef.setInternalId("INVOICE_INTERNAL_ID");

recordRef.setType(RecordType.invoice);

ReadResponse response = service.get(recordRef);

if (response.getStatus().isIsSuccess()) {

    Invoice invoice = (Invoice) response.getRecord();

} else {

    System.out.println(response.getStatus().getStatusDetail()[0].getMessage());

}

Step 3: Create the Payment Record

Once you have retrieved the invoice record, you can create a new payment record using the Payment class. You will need to set the internal ID of the customer who made the payment, the payment amount, and the payment date.

Payment payment = new Payment();

payment.setCustomer(new RecordRef(null, "CUSTOMER_INTERNAL_ID"));

payment.setPayment(new RecordRef(null, "CURRENCY_INTERNAL_ID"));

payment.setDepositDate(new DateTime("PAYMENT_DATE"));

payment.setPaymentAmount(new Double("PAYMENT_AMOUNT"));

Step 4: Apply the Payment to the Invoice

To apply the payment to the invoice, create a new Apply object and add it to the payment record. The Apply object will contain the internal ID of the invoice, the amount of the payment to be applied, and the date of the payment.

Apply apply = new Apply();

apply.setApply(true);

apply.setDoc(new RecordRef(null, "INVOICE_INTERNAL_ID"));

apply.setAmount(new Double("PAYMENT_AMOUNT"));

apply.setApplyDate(new DateTime("PAYMENT_DATE"));

payment.setApplyList(new Apply[] { apply });

Step 5: Save the Payment Record

Finally, you can save the payment record using the add method of the NetSuiteService class. This will add the payment to NetSuite and apply it to the specified invoice.

WriteResponse response = service.add(payment);

if (response.getStatus().isIsSuccess()) {

    System.out.println("Payment applied successfully.");

} else {

    System.out.println(response.getStatus().getStatusDetail()[0].getMessage());

}

By following these instructions, developers can efficiently manage their invoices in NetSuite and streamline their payment processes. Learn more about Payference and how we help NetSuite users streamline their collections and cash management processes by checking out our website: www.payference.com.