Creating / Emailing Welcome Letters and Receipts to Customers
Summary
This article outlines how to create and email a welcome letter and/or receipt to your customers.
nVelocity Overview
Velocity is a Java-based template engine. It permits web page designers to reference methods defined in Java code. Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a well-designed site, and programmers can focus solely on writing top-notch code. Velocity separates Java code from the web pages, making the web site more maintainable over the long run and providing a viable alternative to Java Server Pages (JSPs) or PHP.
Velocity can be used to generate web pages, SQL, PostScript and other output from templates. It can be used either as a standalone utility for generating source code and reports, or as an integrated component of other systems. When complete, Velocity will provide template services for the Turbine web application framework. Velocity+Turbine will provide a template service that will allow web applications to be developed according to a true MVC model.
Configuring Welcome / Signup Document Template
The welcome/sign-up letters and receipts are designed using the Document Template system in EngageIP Billing.
There are three main components to this system: the new Document Templates which provide the layout of the final document, Workflow Engine Events which generate the documents at an appropriate time, and the new Rendered Documents report which lets the user view and email the rendered documents.
The document templates are simply NVelocity templates. These give us great flexibility in design and data-retrieval manipulation. They specify the layout of the HTML used to create the document, and display information pushed into the document, and can pull some information themselves.
The Workflow Engine Event is used to initiate the document rendering. In the case of the welcome letters and receipts, they are generated when a payment is updated, and that payment is disbursed. If the user has only one payment, then a welcome letter (aka Service Subscription Receipt) is produced. Otherwise a Transaction Receipt is produced. When a document is rendered, it is saved to the database. It could also email the document, but in the case of the welcome letters and receipts it isn't.
These generated documents are then available in the Rendered Documents report. Here the user can view a list of all generated documents, email them, and view them individually (whereupon they could print them to hard-copy).
Add Document Template named specifically 'Receipt' in this case because the work flow event is looking for that name for the document template.
Add Workflow Event
ViewPayment viewpayment = ViewPayment.GetByID(int.Parse(context["PaymentID"].ToString()));if (viewpayment.Disbursed) { DocumentTemplateQuery dtq = new DocumentTemplateQuery(); dtq.Name = "Receipt"; dtq.OwnerIDMin = User.GetByID(viewpayment.UserID).GetActingOwner().ID; dtq.OwnerIDMax = dtq.OwnerIDMin; DocumentTemplate dt = DocumentTemplate.GetCollection(ref dtq)[0];Dictionary<string, object> context2 = new Dictionary<string, object>(); context2.Add("ViewPayment", viewpayment); User user = User.GetByID(viewpayment.UserID); context2.Add("User", user); string docName = "Initial Welcome Letter (Payment " + context["PaymentID"].ToString() + ")"; if (user.GetPaymentCollection().Length == 1) { context2.Add("WelcomeLetter", 1); context2.Add("ServiceSubscribed", user.GetUserPackageCollection()[0].GetPackage().Name); } else { context2.Add("WelcomeLetter", 0); docName = "Service Subscription Receipt (Payment " + context["PaymentID"].ToString() + ")"; } Contact contact = Logisense.Boss.Logic.Core.User.GetUserBillingContact(user); context2.Add("Contact", contact); ContactPointAddress contactpointaddress = Logisense.Boss.Logic.Core.User.GetUserBillingContactAddress(user); context2.Add("ContactPointAddress", contactpointaddress);string bank = ""; try { bank = user.GetUserDefaultPaymentMethod().GetUserPaymentMethod().GetUserPaymentMethodCheck().Bank; } catch { } context2.Add("Bank", bank); Payment payment = Payment.GetByID(int.Parse(context["PaymentID"].ToString())); PaymentDisbursement[] disbursements = payment.GetPaymentDisbursementCollection(); context2.Add("PaymentDisbursements", disbursements); Logic.RenderDocument.RenderAndSave(dt.Template, context2, User.GetByID(viewpayment.UserID), docName); } return true;
Start the Event Manager Service on the web server
To test, add a payment to a user. If its the first payment on the user, it will create a welcome message, if there are existing payments, it will create the receipt. View the rendered documents report to see what was created
5. To send to the customer, either click on the name and print or check the letter / receipt and click 'Email'
Sample Template Code
Hello $customer.Name! #foreach( $mud in $mudsOnSpecial ) #if ( $customer.hasPurchased($mud) ) #end #end $flogger.getPromo( $mud ) |