Version: 23.04
Render Receipt Service
The Render Receipt Service is used to render a receipt PDF file.
This service is configured via the Form Version Services tab.
Service Invoke Parameters
Parameters are not nullable except where otherwise indicated.
Parameter | Description |
---|---|
svcDef | SvcDef A service definition value object. |
form | Form A form value object. |
txn | Txn A transaction record value object. |
request | HttpServletRequest Nullable. A HTTP servlet request. |
user | User Nullable. An authenticated user. |
Script Result
The script returns a byte[]
object. If the returned object is null
, an exception is thrown; otherwise, the returned byte[]
object is rendered to PDF.
Templates
Service
import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.vo.*
import javax.servlet.http.*
class FluentRenderReceiptService {
/*
* Perform render receipt service
*/
byte[] invoke(SvcDef svcDef, Form form, Txn txn, HttpServletRequest request, User user) {
//TODO: generate pdf data
byte[] data = "pdf".getBytes()
return data
}
}
Unit Test
import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.test.*
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 testRenderReceipt() throws Exception {
MockVoBuilder mob = new MockVoBuilder()
Form form = mob.createForm()
Txn txn = mob.createTxnSubmittedWithFormAndXml(form)
MockRequest request = new MockRequest()
Map params = [
"svcDef": svcDef,
"form": form,
"txn": txn,
"request": request,
"user": null
]
try {
byte[] result = (byte[]) new ServiceInvoker(svcDef).invoke(params)
assert result != null
} catch (Exception re) {
assert false : 'Test failed'
}
}
}