Skip to main content

Version: 22.04

Receipt Number

The Receipt Number service is used to generate receipt or reference numbers for form submission transactions. These receipt numbers are included in the PDF receipt document, and can also be used as a general reference number for the transaction.

info

By default the transaction's tracking code is displayed as the transact reference number in associated transaction pages and emails.

This service is configured via the Form Details tab.

Service Invoke Parameters

Parameters are not nullable except where otherwise indicated.

ParameterDescription
svcDefSvcDef
A service definition value object.
formForm
A form value object.
txnTxn
A transaction record value object.
requestHttpServletRequest
Nullable. A HTTP servlet request.
userUser
Nullable. An authenticated user.

Script Result

The script returns a transaction receipt number.

Error Handling

If the service returns null or a blank value or throws an exception, the FluentReceiptNumberService generates a default value to be used based on the form code and the submission ID; for example, CSA-2948. This is to ensure the end user has a receipt number that they can reference.

Any Exception thrown by the Groovy script is logged against the submission record in the Journey Manager database, and is also logged in the server log file. This error handling is to ensure the user's submission transaction is not rolled back and lost because of some error in the Groovy script.

Templates

Service

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.vo.*
import javax.servlet.http.*

class FluentReceiptNumberService {

/*
* Perform a transaction receipt number generation
*
* return: a transaction receipt number, values longer than 100 characters will be trimmed
*/
String invoke(SvcDef svcDef, Form form, Txn txn, HttpServletRequest request, User user) {

return form.formCode + "-" + txn.id
}
}

Unit Test

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.test.*
import com.avoka.tm.util.*
import com.avoka.tm.vo.*
import org.junit.Test

class UnitTest extends AbstractJUnitTest {

/*
* Perform service unit test
*
* throws exception if unit test fails
*/
@Test
void testReceiptNumber() throws Exception {

String formXml = testParams['Test XML Data']
MockVoBuilder mob = new MockVoBuilder()
Form form = mob.createForm()
Txn txn = mob.createTxnSubmittedWithFormAndXml(form, formXml)
MockRequest request = new MockRequest()

Map params = [
"svcDef": svcDef,
"form": form,
"txn": txn,
"request": request,
"user": null
]

String receiptNumber = (String) new ServiceInvoker(svcDef).invoke(params)

logger.info "Receipt Number: " + receiptNumber

// Test any business logic performed
assert receiptNumber == (form.formCode + "-" + txn.id)
}
}