-
Notifications
You must be signed in to change notification settings - Fork 9
Payment Flow
Hassaan Ali edited this page Dec 7, 2025
·
1 revision
This document explains the complete payment flow for JazzCash hosted checkout.
┌─────────────────────────────────────────────────────────────┐
│ Customer Initiates Payment │
│ (On Your Website) │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Your Application Collects Data │
│ - Amount │
│ - Bill Reference │
│ - Product Description │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Create JazzCash Instance │
│ $jazzcash = new JazzCash(); │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Set Payment Details │
│ $jazzcash->setAmount() │
│ $jazzcash->setBillReference() │
│ $jazzcash->setProductDescription() │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Validate Payment Data │
│ - Amount > 0 │
│ - Bill Reference not empty │
│ - Product Description not empty │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Build Payment Parameters │
│ - Generate transaction reference │
│ - Set transaction date/time │
│ - Set expiry date/time │
│ - Calculate amount in paisa │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Generate Secure Hash │
│ - Build hash array │
│ - Generate SHA256 HMAC hash │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Generate HTML Form │
│ - Create form with all parameters │
│ - Add auto-submit JavaScript │
│ - Escape HTML for security │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Return HTML Form │
│ - Form auto-submits to JazzCash │
│ - Customer redirected to JazzCash │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Customer on JazzCash Page │
│ - Enter payment details │
│ - Complete payment │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ JazzCash Processes Payment │
│ - Validates payment │
│ - Processes transaction │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Redirect to Callback URL │
│ - With response parameters │
│ - With secure hash │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Your Application Handles Callback │
│ - Verify hash │
│ - Check response code │
│ - Update order status │
│ - Send confirmation │
└─────────────────────────────────────────────────────────────┘
Customer clicks "Pay with JazzCash" button on your website.
$amount = 1000.00;
$billReference = 'ORDER-' . time();
$productDescription = 'Product Purchase';$jazzcash = new JazzCash();$jazzcash->setAmount($amount)
->setBillReference($billReference)
->setProductDescription($productDescription);return $jazzcash->sendRequest();This internally:
- Validates payment data
- Builds payment parameters
- Generates secure hash
- Creates HTML form
- Returns response
The returned HTML form automatically submits to JazzCash payment gateway.
Customer enters payment details on JazzCash secure page.
JazzCash validates and processes the payment.
JazzCash redirects to your callback URL with response data.
public function handleCallback(Request $request)
{
// Verify hash
if (!$this->verifyHash($request->all())) {
return view('payment.error');
}
// Check response code
if ($request->input('pp_ResponseCode') === '000') {
// Payment successful
// Update order, send email, etc.
} else {
// Payment failed
}
}- Payment initiated
- Data collected
- Form generated
- Customer on JazzCash page
- Payment being processed
- Payment successful (code: 000)
- Order updated
- Confirmation sent
- Payment failed (code: 001)
- Order marked as failed
- Customer notified
- Payment cancelled (code: 002)
- Order marked as cancelled
Transaction references are automatically generated:
Format: TR + YYYYMMDDHHMMSS + Random(10-100)
Example: TR20250115120000123
- Maximum 20 alphanumeric characters
- Unique per transaction
- Used for tracking
Amounts are converted to paisa (smallest currency unit):
1000.00 PKR → 100000 (paisa)
Last two digits represent decimal places.
The secure hash is generated using:
- Build hash array in specific order
- Filter out empty/null values
- Concatenate with hash key
- Generate SHA256 HMAC hash
$hash = hash_hmac('sha256', $sortedArray, $hashKey);| Code | Status | Action |
|---|---|---|
000 |
Success | Update order as paid |
001 |
Failed | Mark order as failed |
002 |
Cancelled | Mark order as cancelled |
003 |
Pending | Wait for confirmation |
- Hash Generation: Secure hash generated before sending
- HTTPS: All communication over HTTPS
- Hash Verification: Hash verified on callback
- Input Validation: All inputs validated
- HTML Escaping: All output escaped
Payment Request
↓
Validation
↓
[Invalid] → Return Error
↓
[Valid]
↓
Build Parameters
↓
Generate Hash
↓
Create Form
↓
Return Response
- Generate unique bill references - Use UUIDs or order IDs
- Store transaction references - For tracking and reconciliation
- Verify hash on callback - Never trust unverified callbacks
- Handle all response codes - Not just success
- Log all transactions - For audit trail
- Set appropriate expiry - Default is 1 day
- Use HTTPS - Always use HTTPS for callbacks
- Understanding Hosted Checkout - Detailed implementation
- API Reference - Method documentation
- Troubleshooting - Common issues