How to Set Up Payment Processing APIs That Comply With PIPEDA
March 15, 2026 · Claire Whitfield

From the team at Formisoft, the HIPAA-ready platform for patient intake, scheduling, and payments. Learn more →
Building payment processing APIs for Canadian healthcare clinics means threading two needles at once: you need secure payment flows that comply with PCI DSS, and you need patient data handling that satisfies PIPEDA (Personal Information Protection and Electronic Documents Act). Miss either one and you expose your practice to financial and regulatory risk.
Most payment gateway documentation treats healthcare data like any other customer information. It's not. When your payment processing APIs intersect with protected health information, you're dealing with a specific set of technical requirements that go beyond standard e-commerce patterns.
What PIPEDA Actually Requires for Payment APIs
PIPEDA's ten privacy principles apply to any personal information you collect, use, or disclose during a commercial transaction. That includes payment data. For healthcare practices, three principles matter most when building payment integrations:
Consent: You must obtain meaningful consent before collecting payment information. This means your API workflow needs to capture explicit patient agreement before processing cards. A checkbox buried in your intake form doesn't cut it. You need a dedicated consent step tied to payment collection.
Limiting Collection: Collect only what you need. If you're charging a copay, you don't need the patient's full medical history in the payment payload. Your API should strip PHI from payment requests unless there's a documented clinical or administrative reason to include it.
Safeguards: PIPEDA requires "security appropriate to the sensitivity of the information." For payment APIs handling health data, that means TLS 1.3 minimum, tokenization instead of storing card numbers, and role-based access controls on who can trigger payment requests or view transaction history.
Unlike HIPAA, PIPEDA doesn't prescribe specific technical standards. It puts the onus on you to implement "appropriate safeguards" based on your risk assessment. That ambiguity is both a challenge and an opportunity: you can build payment flows that make sense for your practice, but you need to document why your approach satisfies the law.
Authentication and Authorization Patterns
Your payment API needs two layers of authentication: one for the API consumer (your application) and one for the patient authorizing the charge.
For API-level auth, use OAuth 2.0 with client credentials flow. This gives you machine-to-machine authentication without exposing API keys in client-side code. Your backend service requests an access token, which expires after a defined period (usually 1 hour). This token authorizes your application to call the payment gateway on behalf of your practice.
Const getAccessToken = async () => {
const response = await fetch('https://api.paymentgateway.com/oauth/token', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.PAYMENT_CLIENT_ID,
client_secret: process.env.PAYMENT_CLIENT_SECRET
})
});
return response.json();
};
Patient-level authorization is trickier. You need proof that the patient consented to the specific charge. In Formisoft's online payments workflow, we capture consent as a separate form field with a timestamp and IP address. When the API processes the payment, it includes a consent reference ID in the metadata. If you ever face an audit or patient complaint, you can trace the charge back to documented consent.
Handling PHI in Payment Payloads
Here's where most integrations get it wrong: they dump the entire patient record into the payment API call. You end up with diagnosis codes, treatment notes, and medical history sitting in payment gateway logs that were never designed to protect health information.
PIPEDA's principle of limiting collection means you should send the minimum data required to process the payment. For a typical clinic copay or service fee, that's:
- Patient ID (internal reference, not health card number)
- Transaction amount
- Payment method token
- Invoice or appointment reference
- Consent timestamp
Anything beyond that needs justification. If you're processing workers' comp claims or third-party liability payments, you might need additional context in the metadata. Document why you're including it.
One pattern that works: separate your patient data API from your payment API. When a payment is triggered, your backend fetches the patient's payment method from your secure patient database, generates a one-time token, and sends only that token to the payment gateway. The gateway never sees the patient's name, contact info, or health data. It processes the token and returns a transaction ID. Your backend then records that ID against the patient's account.
Const processPayment = async (patientId, amount, invoiceId) => {
// Fetch tokenized payment method (no PHI)
const paymentMethod = await getPatientPaymentToken(patientId);
// Minimal payload to payment gateway
const payload = {
amount: amount,
currency: 'CAD',
payment_method: paymentMethod.token,
metadata: {
internal_ref: invoiceId,
consent_id: paymentMethod.consentId
}
};
const result = await callPaymentGateway(payload);
// Store transaction ID in your database
await recordTransaction(patientId, result.transaction_id, amount);
};
Audit Logging and Data Retention
PIPEDA requires you to provide patients with access to their personal information. For payment APIs, that means maintaining audit logs of every transaction: who initiated it, when, what data was sent, and what the result was.
Your API integration should log:
- Timestamp of payment request
- User or system that triggered it
- Patient ID (internal reference)
- Amount and currency
- Payment gateway response (success/failure)
- Any error messages
Don't log full card numbers or CVV codes. You shouldn't have access to those in the first place if you're using proper tokenization. Log the last four digits and card type for patient-facing receipts, but nothing more.
Retention is where practices make expensive mistakes. PIPEDA doesn't specify retention periods, but provincial health information acts do. In Ontario (PHIPA), you must retain health records for ten years after the last patient contact. That includes payment records tied to clinical services. Your API needs a retention policy that prevents automatic deletion of transaction logs before that window closes.
Webhook Security for Payment Events
If your payment gateway sends webhooks to notify you of payment events (successful charge, refund, dispute), you need to verify those requests come from the actual gateway and not an attacker spoofing payment confirmations.
Most gateways use HMAC signatures to authenticate webhooks. The gateway includes a signature in the webhook header, computed from the payload and a shared secret. Your endpoint recomputes the signature and compares it before processing the event.
Const verifyWebhook = (payload, signature, secret) => {
const hmac = crypto.createHmac('sha256', secret);
const computed = hmac.update(JSON.stringify(payload)).digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(computed)
);
};
App.post('/webhooks/payment', (req, res) => {
const signature = req.headers['x-payment-signature'];
if (!verifyWebhook(req.body, signature, process.env.WEBHOOK_SECRET)) {
return res.status(401).send('Invalid signature');
}
// Process payment event
processPaymentEvent(req.body);
res.status(200).send('OK');
});
This prevents an attacker from sending fake payment confirmations that could trigger downstream workflows like appointment confirmations or prescription releases.
Testing and Compliance Documentation
You can't prove PIPEDA compliance without documentation. For payment APIs, maintain:
- Data flow diagrams showing where payment data moves
- Risk assessments for each integration point
- Consent capture mechanisms and audit trails
- Encryption standards (TLS versions, cipher suites)
- Access control policies for API credentials
- Incident response procedures for payment data breaches
Test your integration against PIPEDA's principles before going live. Can you demonstrate consent for every payment? Can you produce a patient's complete payment history on request? Can you delete or correct payment records if a patient requests it? If the answer to any of these is "not easily," your API design needs work.