6. Payments API

The related collection of entities associated with the "Payment":

  • Payment - the main entity that represents one of these financial transactions, depending on the "paymentType" field:
    • Payment (PaymentType=Payment) - this record indicates a payment by the customer against one or more outstanding invoices.
    • Refund (PaymentType=Payment) - this record indicates a transfer of funds back to the customer, usually linked with a previous payment.
    • House Credit (PaymentType=Credit) - Credit given to Customer without electronic or manual transfer of funds ( a negative amount indicates debit or increase in balance owed by customer whereas a positive number indicates a decrease in balance)
  • ProcessorResult - if the payment was processed electronically by BluSynergy systems, then this entity contains the transaction identifiers and approval codes from the payment processor and may be used for reconciliation and audit purposes. If the Payment has been processed electronically, but external to BluSynergy, then do not send the ProcessorResult object with the Payment.
  • InvoicePayment - this collection of associated objects indicate which payment(s) have been applied to which invoices and represent an many-to-many mapping between Invoice and Payment. For example if we have these 2 invoices that have been paid by a single payment #123 for $300:

                Invoice 1001, $100

                Invoice 1002, $200

    Then, in addition to the Payment object, we need 2 nested InvoicePayment entities with the following data:

                Payment Number=123, Invoice Number = 1001, Amount Applied = $100, Balance = $200

                Payment Number=123, Invoice Number = 1002, Amount Applied = $200, Balance = $0

Payment Fields

Field Name

Data Type

Required

(C = Conditional)

Notes

Payment Number

String(10)

Y

The unique payment number as assigned by the source system

CRM Payment ID

String (25)

N

This is the internal ID of the Payment  in the CRM system.

ERP Payment ID

String (25)

N

This is the internal ID of the Payment  in the ERP system.

Customer Account Number

String (50)

C

The unique customer account that is displayed on invoice. Any one of the 3 customer identifiers must be provided

CRM Customer ID

String (25)

C

This is the internal ID of the customer in the CRM system. Any one of the 3 customer identifiers must be provided

ERP Customer ID

String (25)

C

This is the internal ID of the customer in the ERP system. Any one of the 3 customer identifiers must be provided

Payment Custom Options

String (100)

N

Used for customization, leave blank unless instructed otherwise

Payment Type

Enum

Y

The status type of the payment must be one of these:

 

'Payment' - Money paid by Customer (positive amount)

 

 'Credit' - Credit given to Customer without electronic or manual transfer of funds ( -ve amount => debit or increase in balance owed by customer)

 

'Refund' - Money paid to Customer with actual transfer of funds (negative amount)

 

 

Amount

Money

Y

The total amount of the payment

Currency Code

String(3)

N

The 3 letter currency code. Defaults to ‘USD’

Status

Enum

Y

Must be one of:

 

‘Paid’ - This payment has been successfully booked (default),

 

‘Declined’ - The payment attempt resulted in a decline from the payment processor

 

'Voided' - Previously successful payment has been reversed or voided (eg: check bounced). This is only used when updating a previous payment record.

 

'Reversed' - If a previous payment entry is ‘Voided’, then also send a ‘Reversed’ record to perform a compensating (negative) transaction so that the net customer account balance is maintained.

 

‘Draft’ - Do not use, reserved for internal system.

 

Error - Do not use, reserved for internal system use to indicate that a payment attempt failed due to a system or network error

 

Effective Date

Date

Y

The posting date for the payment

Balance

Money

Y

Any unassigned balance left over after applying to the invoices against which this payment is booked. Will be 0.00 unless there is an overpayment.

Transaction Date

Date

Y

 

Is Processed By Billing Run

Boolean

N

Reserved for internal use

Is System Payment

Boolean

N

Set to true if this is an electronic payment (such as CC or ACH) that has been processed by eBill. For all payments that were transacted outside eBill, set this to “N” (false)

Linked Payment Number

Number

C

If the Status is ‘Reversed’ or ‘Voided” then indicates the previous payment number.

Original Payment Number

Number

C

Used if PaymentType is ‘Refund’. Indicates the original payment that has been refunded

Parent Id

Number

C

Used only for master-child payments. N/A for eBill

Payment Method Context

String(60)

N

 This field provides some loose identity about the payment instrument to enable traceability. It can be any identifying information, but do not use this to store sensitive information like credit card numbers, etc.

 

For eBill transacted payments, the following are used depending on the payment instrument.

 

CreditCard - card type, last 4 of CC# (e.g., “Visa 1234”)

 

 ACH - institution name, last 4 of account# (e.g., “Compass Bank 9876”)

Payment Method Type

Enum

Y

Indicates the payment method used for this transaction. Must be one of :

'CreditCard',

'ACH',

'Paypal',

'PaperCheck',

'Cash',

'HouseCredit'

'Token' - if tokenization was employed

Notes

String(100)

N

Any notes associated with the payment

Transaction Id

String(50)

N

The payment processor identifier for this transaction

Status Message

String(250)

N

Status message returned by the payment processor

Error Message

String(250)

N

Error message returned by the payment processor

Error Code

Integer

N

Numeric error code returned by the payment processor

ASV Code

String(30)

N

Status code returned by the payment processor for Address Validation Service

Cvv Code

String(30)

N

Status code returned by the payment processor for Card Verification Value (CVV)

Approval Code

String(30)

N

Approval code or secondary payment processor identifier for this transaction

Custom Field1

String (100)

N

Please contact support for custom fields.

Custom Field2

String (100)

N

Custom Field3

String (100)

N

Custom Field4

String (100)

N

Custom Field5

String (100)

N

Custom Field6

String (100)

N

Custom Field7

String (100)

N

Custom Field8

String (100)

N

Custom Field9

String (100)

N

Custom Field10

String (1000)

N

 



PaymentInvoice Fields

Field Name

Data Type

Required

(C = Conditional)

Notes

Record Type

String(3)

Y

Must be set to “PMI”

Update Mode

String(1)

N

U = Update

I = Insert (default)

Set to “U” to indicate this is a previously sent invoice that now needs to be updated (e.g., the invoice was adjusted or cancelled). If blank, defaults to “I’ indicating Insert.

Payment Number

String (10)

C

The unique payment number as assigned by the source system. Any one of the 3 payment identifiers must be provided

CRM Payment ID

String (25)

C

This is the internal ID of the payment in the CRM system. Any one of the 3 payment identifiers must be provided

ERP Payment ID

String (25)

C

This is the internal ID of the payment in the ERP system. Any one of the 3 payment identifiers must be provided

Invoice Number

String (10)

C

The unique invoice number. Any one of the 3 invoice identifiers must be provided

CRM Invoice ID

String (25)

C

This is the internal ID of the invoice  in the CRM system. Any one of the 3 invoice identifiers must be provided

ERP Invoice ID

String (25)

C

This is the internal ID of the invoice in the ERP system. Any one of the 3 invoice identifiers must be provided

Custom Options

String (100)

N

Used for customization, leave blank unless instructed otherwise

Amount Applied

Money

Y

The amount applied towards the indicated invoice

Balance Amount

Money

Y

The balance left over after the above amount was applied.

Custom Field1

String (100)

N

Please contact support for custom fields.

Custom Field2

String (100)

N

Custom Field3

String (100)

N

Custom Field4

String (100)

N

Custom Field5

String (100)

N

 

 

 


6.1. Retrieve Payment:

GetPayment - Returns a subset of data seen in the Payment Detail Screen:

  1. Parameters: Allow parameter to filter by PaymentType (Credit/Refund/Payment). Optional.
  2. Returns these domain objects: Payment (Transaction Detail panel), ProcessorResult (Authorization Record panel) and InvoicePayment (Linked Invoices panel).



GET /rest/payment/[id]?format=xml
GET /rest/credit/[id]? format=xml
GET /rest/refund/[id]?format=xml


Sample Output:


<payment id="7">
  <isSystemPayment>true</isSystemPayment>
  <customer id="5" />
  <paymentMethodType>Token</paymentMethodType>
  <currency id="USD" />
  <amount>194.25</amount>
  <balance>0.00</balance>
  <effectiveDate>2010-08-06</effectiveDate>
  <status>Paid</status>
  <paymentType>Payment</paymentType>
  <lastUpdated>2010-08-06</lastUpdated>
  <isProcessedByBillingRun>false</isProcessedByBillingRun>
  <processorResult id="10">
    <errorMessage />
    <transactionId>390.72665051790136</transactionId>
    <batchIndicator />
    <isSuccess>true</isSuccess>
    <customer id="5" />
    <statusCode />
    <amount>194.25</amount>
    <avsCode />
    <isError>false</isError>
    <currencyCode>USD</currencyCode>
    <otherMsg3 />
    <processorRequestType>authorize_api_call</processorRequestType>
    <otherMsg2 />
    <otherMsg1 />
    <responseTimeMilliSec>2</responseTimeMilliSec>
    <lastUpdated>2010-08-08</lastUpdated>
    <approvalCode>XYZ776.0854564137724</approvalCode>
    <statusMessage>authorized o</statusMessage>
    <cvvCode />
    <errorCode>0</errorCode>
    <dateCreated>2010-08-06</dateCreated>
    <secondaryAmount />
    <paymentProcessor id="6" />
  </processorResult>
  <paymentMethodContext>Visa - *****1111</paymentMethodContext>
  <dateCreated>2010-08-06</dateCreated>
  <paymentProcessor id="6">
    <name>Test Processor</name>
  </paymentProcessor>
  <invoicePayments>
    <invoicePayment id="1">
      <payment id="7" />
      <amountApplied>194.25</amountApplied>
      <invoice id="1" />
      <lastUpdated>2010-08-06</lastUpdated>
      <dateCreated>2010-08-06</dateCreated>
      <balanceRemaining>0.00</balanceRemaining>
      <customer id="5" />
    </invoicePayment>
  </invoicePayments>
  <notes />
  <paymentMethod id="3" />
</payment>


6.2. Retrieve Payment List:

Returns a paged list of Payments/Credits/Refunds. The transactions are sorted in descending order by effectiveDate Defaults used if the query string parameters are missing:
   offset=0
   max=50
   status = ignored if not provided
   amount = ignored if not provided
   customerId = ignored if not provided (i.e, returns a list of all customers)


GET /rest/payments?format=xml&offset=[n]&max=[m]&status=[status] &amount=[value]&customerId=[id]
GET /rest/credits?format=xml&offset=[n]&max=[m]&status= [status]&amount=[value]&customerId=[id]
GET /rest/refunds?format=xml&offset=[n]&max=[m] &status=[status]&amount=[value]&customerId=[id]

Sample Output:
<list>
  <payment id="7">
  ...
  <payment id="8">
</list>



6.3. Create a new Payment:

In general,Payments, Refunds and Credits are represented internally as a "Payment" entity, and differentiated by a "paymentType" property which could be either "Payment", "Refund" or "Credit".

Note that the "amount" property will be negative for Refunds.

There are two approaches to making a payment, either by passing in a PaymentMethod (such as a credit card, ACH, Check, etc.) or by using a pre-existing stored auto-pay PaymentMethod (added to the Customer previously via a POST /rest/customer/[id]/autopay)

The returned output from all these calls is a payment instance, i.e., same return as a /rest/payment/[id]?format=xml


POST /rest/payments?format=xml
POST /rest/refunds? format=xml
POST /rest/credits?format=xml
POST /rest/payments/autopay?format=xml
POST /rest/refunds/autopay?format=xml


POST /rest/payments?format=xml&extCustomerRef=[code]

In the following XML, note that:

  1. action could be one of "processPayment", "processCredit" or "processRefund".
  2. The <paymentMethodDTO> is a generic data transfer object that holds the actual payment method used for remittance (as indicated by the "type" attribute). Inside the we could have one of creditCardPaymentMethod, achPaymentMethod, checkPaymentMethod, or cashPaymentMethod. The element must be set to the appropriate value.
  3. If the <generateInvoice> XML element value is set to "true", then the billing run for this customer is initiated, and on completion, the resulting unpaid invoices are target for this payment.
  4. The Invoice ID indicates which invoices the payment is to be applied against.
  5. As before, if you wish to reference the customer by your external reference value (rather than the BluBilling assigned numeric customer id), then use the "extCustomerRef=[code]" querystring parameter.
POST /rest/payments? format=xml


<processPayment>
  <customer id="11"/>
  <amount>3430.95</amount>
  <currencyCode>USD</currencyCode>
  <generateInvoice>false</generateInvoice>
  <effectiveDate>2010-12-31</effectiveDate>
  <invoiceText/>
  <purchaseDescription/>
  <internalNotes/>
  <invoices>
    <invoice id="34" />
  </invoices>
  <paymentMethodDTO type="CreditCard">
    <creditCardPaymentMethod>
      <autopayPreference>1</autopayPreference> <!-- Set this to 1, 2, or 3 to save this as        the preferred auto-pay for this customer -->
      <cardNumber>...</cardNumber>
      <expiry>...</expiry>
      <cardType>Visa</cardType>
      ...
    </creditCardPaymentMethod>
  </paymentMethodDTO>
</processPayment>


A sample response is shown below. The <status> element will be "Paid" on success with the <amount> element representing the amount that was actually transacted.



<payment id="213">
  <isSystemPayment>true</isSystemPayment>
  <customer id="11" />
  <paymentMethodType>CreditCard</paymentMethodType>
  <currency id="USD" />
  <amount>3430.95</amount>
  <balance>0.00</balance>
  <effectiveDate>2011-09-06</effectiveDate>
  <status>Paid</status>
  <paymentType>Payment</paymentType>
  <lastUpdated>2011-09-07</lastUpdated>
  <isProcessedByBillingRun>false</isProcessedByBillingRun>
  <baseUser id="351">
    <username>jdoe</username>
    <firstName>Jane</firstName>
    <lastName>Doe</lastName>
  </baseUser>

  <processorResult id="192">
    <errorMessage />
    <transactionId>2162704713</transactionId>
    <batchIndicator />
    <isSuccess>true</isSuccess>
    <customer id="11" />
    <statusCode>1</statusCode>
    <amount>3430.95</amount>
    <avsCode>Y</avsCode>
    <isError>false</isError>
    <currencyCode>USD</currencyCode>
    <payment id="213" />
    <processorRequestType>AUTH_CAPTURE</processorRequestType>
    <responseTimeMilliSec>3741</responseTimeMilliSec>
    <lastUpdated>2011-09-07</lastUpdated>
    <approvalCode>0S33CM</approvalCode>
    <statusMessage>RRC_1_1 : This transaction has been approved.</statusMessage>
    <cvvCode>X</cvvCode>
    <errorCode />
    <dateCreated>2011-09-07</dateCreated>
    <secondaryAmount>0.00</secondaryAmount>
  </processorResult>
  <paymentMethodContext>Visa: 1111</paymentMethodContext>
  <dateCreated>2011-09-07</dateCreated>
  <paymentProcessor id="6">
    <name>Authorize.NET V1</name>
  </paymentProcessor>
  <invoicePayments>
    <invoicePayment id="171">
      <payment id="213" />
      <amountApplied>60.50</amountApplied>
      <invoice id="34" />
      <balanceRemaining>0.00</balanceRemaining>
      <customer id="11" />
    </invoicePayment>
  </invoicePayments>
</payment>




On the other hand, if a transaction with an autopay is required, then we'd use one of the calls below. The Invoice ID indicates which invoices the payment is to be applied against.


POST /rest/payments/autopay

POST /rest/payments/autopay&extCustomerRef=[code]


<processPaymentWithAutopay>
  <customer id="377" /> <!-- not required if extCustomerRef is supplied in querystring -->
  <currencyCode>USD</currencyCode>
  <amount>199.00</amount>
  <effectiveDate>2011-09-28</effectiveDate>
  <invoiceText></invoiceText> 
  <purchaseDescription></purchaseDescription>
  <internalNotes></internalNotes>
  <invoices>
    <invoice id='2492' />
  </invoices>
  <autopayPreference>1</autopayPreference> <!-- defaults to 1 if not supplied -->
</processPaymentWithAutopay>

Comments