Sunday, November 11, 2018

Create a partial Customer Payment in Web Services using C#.net

This code snippet shows how you can create a partial Customer Payment record via Web Services using C#. It is required that the Invoice record's status is not Paid In Full.

InitializeRecord ir = new InitializeRecord();
ir.type = InitializeType.customerPayment;
InitializeRef iref = new InitializeRef();
iref.typeSpecified=true;
iref.type=InitializeRefType.invoice;
iref.internalId = "1683"; // this is the Invoice Internal ID
ir.reference = iref;

ReadResponse getInitResp = _service.initialize(ir);
if (getInitResp.status.isSuccess)
 {
  Record rec = getInitResp.record;
  RecordRef payMethod = new RecordRef();
  payMethod.internalId = "1"; // Add Credit Card information
  ((CustomerPayment)rec).paymentMethod = payMethod;
  
  // specify the amount for the partial payment
  // the Apply index will depend on the number of pending invoices the customer has
  ((CustomerPayment)rec).applyList.apply[0].amount = 50;
  ((CustomerPayment)rec).applyList.apply[0].amountSpecified = true;
  
  WriteResponse writeRes = _service.add(rec);
 }

No comments:

Post a Comment