Tutorial: Digital Receipt Setup & WhatsApp Receipt Integration for Healthcare Facility Operational Efficiency
Learn step-by-step how to set up digital receipts and integrate receipt delivery via WhatsApp to improve the operational efficiency of healthcare facilities. This article covers technical implementation, code examples, and industry-standard best practices.
In today's digital era, healthcare facilities (fasyankes) such as hospitals and clinics are faced with increasingly high demands for operational efficiency while maintaining patient satisfaction. One area that often causes friction and hidden costs is the manual management of patient transaction receipts. Printing physical receipts requires paper, printer ink, and time, which if accumulated can reach millions of rupiah per month for healthcare facilities with high transaction volumes. For example, a hospital with an average of 500 transactions per day could spend more than Rp 3-5 million per month just for thermal paper and toner costs, not including printer maintenance costs and staff time. Not to mention the risk of receipts being lost, damaged, or unreadable, which could potentially cause patient complaints and hinder administrative processes. The transformation toward digital receipts has become a necessity, no longer an option, to address this challenge.
This article will guide hospital IT managers, clinic owners, operations managers, and decision-makers through an in-depth tutorial on how to set up digital receipts and integrate them with the WhatsApp Business API. We will discuss basic concepts, technical architecture, code examples that you can apply directly, error handling, and best practices to ensure a successful, secure, and standards-compliant implementation. Our focus is on concrete solutions, mentioning specific tool and library versions, and providing references to relevant official standards, so that you can improve operational efficiency and provide a more modern and comfortable patient experience.
Basic Concepts of Digital Receipts and WhatsApp Business API
A digital receipt is an electronic representation of proof of transaction or payment that is usually printed on paper. In the context of healthcare facilities, this can be proof of payment for medical services, purchase of medicines at the hospital pharmacy, or other administrative fees. The main benefits of adopting digital receipts are very significant. First, operational cost savings. Reducing paper and printer ink usage drastically can save millions of rupiah every month. A clinic serving 150 patients per day, for example, can save up to Rp 1.5 million per month from paper and ink costs alone. Second, time efficiency. The receipt delivery process becomes instant, reducing queues at the cashier and speeding up patient flow. Third, environmentally friendly, supporting green hospital initiatives. Fourth, ease of access and storage for patients, because receipts are stored securely on their devices and easily accessible at any time. Fifth, ease of analyzing transaction data for audit or financial reporting purposes.
For efficient digital receipt delivery, the WhatsApp Business API (WABA) is the most relevant choice in Indonesia, given the dominance of WhatsApp users. It is important to understand that WABA is different from the regular WhatsApp Business app. WABA is an official application programming interface provided by Meta, designed specifically for medium to large-scale businesses. It enables direct integration with your business backend systems, such as SIMRS (Hospital Management Information System) or Clinic SIM, to send messages automatically, in a structured manner, and in high volumes. WABA supports sending various types of messages, including text messages, images, and documents (PDF), which are very suitable for digital receipts. Its main features include the use of message templates approved by Meta for transactional notifications, the ability to manage thousands of conversations simultaneously, as well as higher data security and privacy features compared to personal WhatsApp.
The integration flow generally begins when a patient transaction has finished being processed in SIMRS or Clinic SIM. The system then automatically triggers the creation of a digital receipt (usually in PDF format). This PDF file is then sent via the WhatsApp Business API to the patient's registered mobile number. This process is asynchronous, ensuring the performance of the core system is not disrupted. In the context of data compliance, the use of WABA is crucial. The WhatsApp Business API complies with global security standards, and as data controllers, healthcare facilities must ensure compliance with patient data privacy regulations such as Minister of Health Regulation (PMK) No. 269/2008 on Medical Records and the Electronic Information and Transactions Law (UU ITE) in Indonesia. The use of message templates already approved by Meta also helps maintain patient trust and ensures that the messages sent are relevant and not spam.
Implementation Architecture and Technology Choices
Implementing digital receipts via WhatsApp requires a well-planned system architecture to guarantee scalability, security, and reliability. Broadly speaking, the recommended architecture consists of three main components: the Management Information System (SIMRS/Clinic SIM) as the main backend, the Digital Receipt Generation Service, and the WhatsApp Integration Service. Your SIMRS/Clinic SIM, which may be built with frameworks such as Laravel 11.x, Node.js 20 LTS (using Express.js), or Java Spring Boot 3.x, will be the main trigger. The commonly used database is PostgreSQL 16, known for its stability and ability to handle complex relational data.
For the Digital Receipt Generation Service, you have several technology options. If your backend system is PHP-based (such as Laravel), libraries like Dompdf (version 2.0.x) or FPDF are very effective for converting HTML to PDF. Dompdf, in particular, is very popular due to its ease of use for rendering HTML/CSS to PDF. For a Node.js environment, Puppeteer can be used to control a headless browser (such as Chromium) to print web pages to PDF, providing high flexibility in design. Another alternative is to use wkhtmltopdf, a command-line tool that can be integrated with various programming languages for high-quality HTML to PDF conversion. Choosing the PDF format is highly recommended because the receipt will look consistent across various devices and is easy to archive.
The WhatsApp Integration Service functions as a bridge between your system and the WhatsApp Business API. It can be implemented as a separate microservice or as a module within an existing backend application. If using PHP, the Guzzle HTTP client is the standard choice for making API calls to WABA. For Node.js, the Axios library (version 1.6.x) or the native fetch API is a solid choice. Meanwhile, in Java, OkHttp or Spring WebClient are very suitable. You can choose to use Meta for WhatsApp Business Platform (Cloud API) which is hosted by Meta, or the On-Premises API which is hosted on your own infrastructure. Cloud API is generally easier to set up and manage, while On-Premises API provides greater control over data and infrastructure, but with higher management complexity. Make sure you use the latest API version, for example WABA API v18.0, to get the latest features and security.
The security aspect is a top priority. All communication between your system and WABA must go through HTTPS. Authentication to WABA generally uses a Bearer Token (API Key) that must be kept confidential. Consider implementing OAuth 2.0 if you have a broader application ecosystem. Sensitive patient data must be encrypted when stored (at rest) and when in transit (in transit). For example, a transaction in a Laravel 11.x-based SIMRS with PostgreSQL 16 will trigger a process. A job queue (for example, using Redis) will pick up the task of generating the PDF receipt and sending the WhatsApp message. This job will call the Receipt Generation Service (for example, PHP Dompdf) to create the PDF, store it in secure cloud storage (such as AWS S3 or Google Cloud Storage), then call the WhatsApp Integration Service (for example, Node.js with Axios) to send the PDF link via WABA. This architecture ensures that the core SIMRS system remains responsive and the receipt delivery process runs asynchronously and reliably.
Code Example: PDF Receipt Generation and Delivery via WhatsApp
To implement a digital receipt, the first step is to create a PDF file from the transaction data. In this example, we will use PHP with the Laravel framework and the Dompdf library (version 2.0.x) for PDF generation. Make sure you have installed Dompdf in your Laravel project with composer require dompdf/dompdf. The code example below shows how a controller in Laravel can generate a PDF receipt from a Blade view and save it.
<?phpnamespace App\'Http\Controllers;use Illuminate\Http\Request;use Dompdf\Dompdf;use Dompdf\Options;use Illuminate\Support\Facades\Storage;class ReceiptController extends Controller{ public function generateAndSendReceipt(Request $request) { // 1. Get transaction data from request or database $transactionData = [ 'id' => 'TRX0012345', 'patient_name' => 'Budi Santoso', 'service_name' => 'General Examination', 'amount' => 150000, 'date' => '2023-10-26', 'clinic_name' => 'Always Healthy Clinic', 'address' => 'Jl. Kesehatan No. 10', 'phone_number' => '+6281234567890' // Patient's WhatsApp number ]; // 2. Render Blade view to HTML $html = view('receipts.transaction', compact('transactionData'))->render(); // 3. Configure Dompdf $options = new Options(); $options->set('isHtml5ParserEnabled', true); $options->set('isRemoteEnabled', true); // Important for external images/CSS $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->setPaper('A7', 'portrait'); // A7 paper size or as needed $dompdf->render(); // 4. Save PDF to storage $filename = 'receipt_' . $transactionData['id'] . '.pdf'; $pdfContent = $dompdf->output(); Storage::disk('public')->put('receipts/' . $filename, $pdfContent); $pdfUrl = Storage::disk('public')->url('receipts/' . $filename); // 5. Send PDF URL to WhatsApp (call another service or directly here) // Example: dispatch job to queue for WhatsApp sending // dispatch(new SendWhatsAppReceipt($transactionData['phone_number'], $pdfUrl)); // For demonstration, we will call the WhatsApp sending function directly $this->sendWhatsAppDocument($transactionData['phone_number'], $pdfUrl, $transactionData['patient_name']); return response()->json(['message' => 'Receipt successfully created and sent via WhatsApp.', 'pdf_url' => $pdfUrl]); } private function sendWhatsAppDocument(string $phoneNumber, string $documentUrl, string $patientName) { $token = env('WHATSAPP_BUSINESS_API_TOKEN'); $phoneId = env('WHATSAPP_BUSINESS_PHONE_ID'); $url = 'https://graph.facebook.com/v18.0/' . $phoneId . '/messages'; $payload = [ 'messaging_product' => 'whatsapp', 'recipient_type' => 'individual', 'to' => $phoneNumber, 'type' => 'template', 'template' => [ 'name' => 'receipt_notification', // Template name approved by Meta 'language' => ['code' => 'id'], 'components' => [ [ 'type' => 'header', 'parameters' => [ [ 'type' => 'document', 'document' => [ 'link' => $documentUrl, 'filename' => 'Struk_Transaksi.pdf' ] ] ] ], [ 'type' => 'body', 'parameters' => [ [ 'type' => 'text', 'text' => $patientName ], [ 'type' => 'text', 'text' => 'Klinik Sehat Selalu' ] ] ] ] ] ]; $client = new \GuzzleHttp\Client(); try { $response = $client->post($url, [ 'headers' => [ 'Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json' ], 'json' => $payload ]); return json_decode($response->getBody()->getContents(), true); } catch (\GuzzleHttp\Exception\RequestException $e) { // Log error or send notification Log::error('Failed to send WhatsApp: ' . $e->getMessage()); if ($e->hasResponse()) { Log::error('WhatsApp API Response: ' . $e->getResponse()->getBody()->getContents()); } return false; } }}The code above uses Guzzle HTTP Client (guzzlehttp/guzzle version 7.x) to make calls to the WhatsApp Business API. Make sure you install Guzzle with composer require guzzlehttp/guzzle. Environment variables such as WHATSAPP_BUSINESS_API_TOKEN and WHATSAPP_BUSINESS_PHONE_ID must be configured in your .env file. The WhatsApp message template named receipt_notification must have been approved by Meta and have a header component of type document as well as a body component for text parameters. This is an example of sending a PDF document directly via a publicly accessible URL. It is important to ensure that the generated PDF URL is accessible by the WhatsApp server.
As an alternative, if you use Node.js for the WhatsApp sending service, here is an example function you can use. Make sure you have installed Axios (npm install axios@1.6.x). This function will send a template message containing a PDF document link.
const axios = require('axios');const WHATSAPP_BUSINESS_API_TOKEN = process.env.WHATSAPP_BUSINESS_API_TOKEN;const WHATSAPP_BUSINESS_PHONE_ID = process.env.WHATSAPP_BUSINESS_PHONE_ID;async function sendWhatsAppDocument(phoneNumber, documentUrl, patientName) { const url = `https://graph.facebook.com/v18.0/${WHATSAPP_BUSINESS_PHONE_ID}/messages`; const payload = { messaging_product: 'whatsapp', recipient_type: 'individual', to: phoneNumber, type: 'template', template: { name: 'receipt_notification', // Template name that has been approved by Meta language: { code: 'id' }, components: [ { type: 'header', parameters: [ { type: 'document', document: { link: documentUrl, filename: 'Struk_Transaksi.pdf' } } ] }, { type: 'body', parameters: [ { type: 'text', text: patientName }, { type: 'text', text: 'Klinik Sehat Selalu' } ] } ] } }; try { const response = await axios.post(url, payload, { headers: { 'Authorization': `Bearer ${WHATSAPP_BUSINESS_API_TOKEN}`, 'Content-Type': 'application/json' } }); console.log('WhatsApp send successful:', response.data); return response.data; } catch (error) { console.error('Failed to send WhatsApp:', error.response ? error.response.data : error.message); return null; }}// Usage example (inside another async function or at the top level with an IIFE)/*(async () => { const patientPhoneNumber = '+6281234567890'; const pdfLink = 'https://example.com/receipts/receipt_TRX0012345.pdf'; // Replace with your PDF URL const patientName = 'Budi Santoso'; await sendWhatsAppDocument(patientPhoneNumber, pdfLink, patientName);})();*/These two code examples demonstrate the basics of PDF generation and sending via the WhatsApp Business API. For production, you need to add more validation, more comprehensive error handling, and possibly use a message queue (such as Redis Queue in Laravel or Kafka/RabbitMQ) to process sending asynchronously, so that it does not block the application's main flow and improves scalability. Make sure the PDF URL you send is public and secure, and has an appropriate validity period if using presigned URLs from cloud storage.
Error Handling and Example Payload
In complex system integrations such as sending digital receipts via WhatsApp, robust error handling is crucial. Delivery failures can occur for various reasons, ranging from network issues, incorrect payload formats, to problems on the WhatsApp Business API side itself. Understanding the correct payload structure and how to respond to error codes will greatly help in building a reliable system.
The following is an example of a realistic JSON payload for sending a PDF document via WhatsApp Business API v18.0, using an approved message template:
{ "messaging_product": "whatsapp", "to": "6281234567890", "type": "document", "document": { "link": "https://example.com/receipts/receipt_TRX0012345.pdf", "caption": "Your digital receipt for your visit at Klinik Sehat Selalu. Thank you.", "filename": "struk_TRX0012345.pdf" }}Common error codes that appear include 131047 (message template does not match), 131026 (invalid number or number not registered on WhatsApp), and 470 (temporary service issue). For each failure, save the API response to a log and perform a retry with exponential backoff for temporary errors. If the error is caused by an invalid number, flag the patient so they are not sent to again and recommend number verification through another channel.
Practical Implementation Tips in Healthcare Facilities
Before going into production, make sure you already have a message template approved by the WhatsApp Business API. This template must contain clear variables, for example patient name, transaction number, and receipt link. Submit the template well in advance because the approval process can take time. In addition, use a presigned URL with a limited validity period (for example 24 hours) to access the receipt PDF, so that medical and financial data is not permanently exposed. Store the receipt file in object storage such as AWS S3 or Google Cloud Storage, then generate a secure URL when it is about to be sent.
From an operational perspective, implement a queue for sending receipts. When a patient completes a transaction, the system only needs to add a job to the queue, then a worker will process the sending asynchronously. That way, the cashier or registration staff do not need to wait for the sending process to finish. Also monitor the delivery status from the WhatsApp webhook: the statuses sent, delivered, and read can be indicators of success. If within 24 hours the status is still sent, resend or notify staff for follow-up.
Don't forget the aspects of compliance and data security. Encrypt the PDF receipts, restrict access to files only to authorized parties, and ensure patient phone numbers are obtained with consent. For healthcare facilities serving many branches, centralize API configuration and templates in one place for consistency. Conduct gradual trials: start with internal numbers, then to a few volunteer patients, before rolling out to all patients. This way, you can catch bugs early without disrupting core services.
FAQ
Is a digital receipt via WhatsApp valid as proof of payment?
In general, a digital receipt can be valid proof of payment as long as it contains complete and verifiable transaction information, such as transaction number, date, amount, and the identity of the healthcare facility. However, for certain legal purposes, you still need to provide a printed version or a certified electronic signature. Consult with your healthcare facility's legal team to ensure compliance.
What if the patient does not have WhatsApp or the number is inactive?
Provide alternative channels, for example sending the receipt via email, an SMS containing a link, or printing a physical receipt at the counter. The system can detect WhatsApp delivery failures and automatically switch to a backup channel. Ensure patients can choose their preferred channel during registration or at the time of transaction.
Is it necessary to store receipt delivery history?
Very necessary. Store delivery logs that include send time, status, and API response. This history is useful for audits, handling patient complaints, and analyzing delivery success rates. Ensure log storage complies with personal data protection regulations, for example by not storing message contents excessively.
How much does it cost to integrate the WhatsApp Business API?
Costs vary depending on the service provider (BSP) and message volume. Generally there is a per-24-hour conversation fee and a monthly platform fee. For healthcare facilities with small volumes, costs can be reduced by choosing a suitable package. Calculate ROI by comparing savings on paper, ink, and staff time against subscription costs.
Conclusion
Integrating digital receipts with the WhatsApp Business API offers significant operational efficiency for healthcare facilities: reducing paper usage, speeding up receipt distribution, and improving the patient experience. With careful planning—from PDF generation, asynchronous delivery, error handling, to data compliance—you can build a reliable and scalable system. Don't hesitate to start with a small scope, then expand as needed.
If you want to accelerate implementation or need technical assistance, our team is ready to help. Consult about your healthcare facility's digital receipt and WhatsApp API integration needs now and get a solution tailored to your institution's workflow and budget. Contact us through the contact page or schedule a free demo session to see firsthand how this system works.
This article is part of the knowledge base of Nugroho Setiawan, an IT consultant in Jogja (Yogyakarta). Related solutions: SIMRS (Hospital Information System) Clinic Management System BPJS & SatuSehat Integration. Need a free consultation?
Komentar
Belum ada komentar. Jadilah yang pertama!
Saya membantu konsultasi IT, pengembangan aplikasi, dan visualisasi data untuk rumah sakit, klinik, dan bisnis di Yogyakarta (DIY), Magelang, dan sekitarnya.