-
Notifications
You must be signed in to change notification settings - Fork 9
API Reference
Complete reference documentation for all JazzCash package methods and classes.
All methods are accessible via the Jazzcash facade:
use Jazzcash;$jazzcash = new JazzCash();Creates a new JazzCash instance with configuration loaded from config file.
Set the transaction amount.
$jazzcash->setAmount(float|int|string $amount): staticParameters:
-
$amount(float|int|string) - Transaction amount
Returns: static - Returns self for method chaining
Throws: InvalidArgumentException if amount is negative
Example:
$jazzcash->setAmount(1000.00);
$jazzcash->setAmount(1000);
$jazzcash->setAmount('1000.00');Get the transaction amount.
$jazzcash->getAmount(): float|intReturns: float|int - The transaction amount
Example:
$amount = $jazzcash->getAmount();Set the bill reference (order ID).
$jazzcash->setBillReference(string $billref): staticParameters:
-
$billref(string) - Bill reference number
Returns: static - Returns self for method chaining
Example:
$jazzcash->setBillReference('ORDER-12345');Get the bill reference.
$jazzcash->getBillReference(): stringReturns: string - Bill reference number
Note: This is the correctly spelled method. getBillRefernce() (with typo) also works for backward compatibility.
Example:
$billRef = $jazzcash->getBillReference();Get the bill reference (backward compatibility).
$jazzcash->getBillRefernce(): stringReturns: string - Bill reference number
Note: This method has a typo but is kept for backward compatibility. Use getBillReference() instead.
Set the product description.
$jazzcash->setProductDescription(string $description): staticParameters:
-
$description(string) - Product description
Returns: static - Returns self for method chaining
Example:
$jazzcash->setProductDescription('Product Purchase');Get the product description.
$jazzcash->getProductDescription(): stringReturns: string - Product description
Example:
$description = $jazzcash->getProductDescription();Send payment request to JazzCash.
$jazzcash->sendRequest(): \Illuminate\Http\ResponseReturns: \Illuminate\Http\Response - HTML form response
Throws:
-
InvalidArgumentExceptionif payment data is invalid -
RuntimeExceptionif configuration is missing
Example:
$response = $jazzcash->setAmount(1000)
->setBillReference('ORDER-123')
->setProductDescription('Product')
->sendRequest();
return $response;The Payment class provides base functionality. Most methods are inherited by JazzCash.
Set the API URL.
$payment->setApiUrl(string $apiUrl): staticParameters:
-
$apiUrl(string) - API URL
Returns: static - Returns self for method chaining
Get the API URL.
$payment->getApiUrl(): stringReturns: string - API URL
Set the refund API URL.
$payment->setRefundApiUrl(string $apiUrl): staticParameters:
-
$apiUrl(string) - Refund API URL
Returns: static - Returns self for method chaining
Get the refund API URL.
$payment->getRefundApiUrl(): stringReturns: string - Refund API URL
Generate secure hash for payment data.
$payment->HashArray(array $data): stringParameters:
-
$data(array) - Payment data array
Returns: string - Generated hash (SHA256)
Note: This is an internal method but can be used for hash verification.
use zfhassaan\JazzCash\Constants\JazzCashConstants;
JazzCashConstants::VERSION; // '2.0'
JazzCashConstants::LANGUAGE; // 'EN'
JazzCashConstants::CURRENCY; // 'PKR'
JazzCashConstants::IS_REGISTERED_CUSTOMER; // 'No'
JazzCashConstants::DEFAULT_EXPIRY_DAYS; // 1
JazzCashConstants::TIMEZONE; // 'Asia/Karachi'All setter methods support method chaining:
$response = (new JazzCash())
->setAmount(1000)
->setBillReference('ORDER-123')
->setProductDescription('Product')
->sendRequest();Thrown when:
- Amount is negative
- Required data is missing
try {
$jazzcash->setAmount(-100);
} catch (\InvalidArgumentException $e) {
echo $e->getMessage(); // "Amount must be positive"
}Thrown when:
- Configuration is missing
- API URL is not set
try {
$jazzcash = new JazzCash();
} catch (\RuntimeException $e) {
echo $e->getMessage(); // "JazzCash configuration missing: ..."
}The sendRequest() method returns an HTML form:
<div id="header">
<form id="jc-params" action="https://sandbox.jazzcash.com.pk/..." method="post">
<input type="hidden" name="pp_Version" value="2.0" />
<input type="hidden" name="pp_Amount" value="100000" />
<!-- ... more fields ... -->
<input type="hidden" name="pp_SecureHash" value="..." />
<input style="display:none;" type="submit" value="Submit" />
</form>
<script>
window.addEventListener("DOMContentLoaded", function() {
document.getElementById("jc-params").submit();
});
</script>
</div>- Always validate input before setting values
- Use method chaining for cleaner code
- Handle exceptions properly
- Verify hash on callback
- Store transaction references for tracking
- Payment Flow - Understand payment processing
- Understanding Hosted Checkout - Detailed checkout guide
- Troubleshooting - Common issues