You are here: API Foundations > Use Cases > Creating and Applying Payments to an Invoice

Creating and Applying Payments to an Invoice

In this use case, you are using several objects to create and apply a payment to an invoice.

To create and apply an electronic payment to an invoice,

  1. Query for Invoice by Account ID:
  2. select ID from Invoice where AccountId = 'someAccountId'

  3. Create a new Payment with the following fields set as follows:
  4. Create a new InvoicePayment with the following fields set as follows:
  5. Update the Payment with Status = Processed.

Sample Code

Payment payment = new Payment();
payment.setAccountId(accountId);
payment.setPaymentMethodId(paymentMethodId);
payment.setType("Electronic");
payment.setAmount(amount);
payment.setEffectiveDate(Calendar.getInstance());
payment.setStatus("Draft");
ID paymentId = create(payment);
InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPaymentId(payment.getId());>
invoicePayment.setInvoiceId(invoiceId);
invoicePayment.setAmount(50);
create(invoicePayment);
payment = new Payment();
payment.setId(paymentId);
payment.setStatus("Processed");
update(payment);

Copyright © 2008-2009 Zuora, Inc.