PreAuthorization Class
The PreAuthorization class processes the IPCPreAuthorization method. It allows merchants to authorize a payment amount on a customer’s card without immediately capturing the funds.
This is useful for hotel bookings, rental services, or security deposits, where the final charge might vary or occur later.
Class Overview
- Namespace:
Mypos\IPC - Located at:
PreAuthorization.php - Extends:
Mypos\IPC\Base - Purpose: Initiates a pre-authorization transaction, holds funds on the customer’s card, and allows later capture or cancellation.
Method Summary
| Method | Return Type | Description |
|---|---|---|
__construct(Config $cnf) | - | Initializes the object with IPC configuration. |
setOrderID(string $orderID) | PreAuthorization | Sets a unique order ID for this pre-auth. |
getOrderID() | string | Retrieves the order ID. |
setItemName(string $itemName) | PreAuthorization | Optional: name of the item/service. |
getItemName() | string | Returns the item name. |
setAmount(float $amount) | PreAuthorization | Total amount to be authorized (not captured). |
getAmount() | float | Retrieves the amount. |
setCurrency(string $currency) | PreAuthorization | Sets ISO 4217 currency code (e.g., EUR). |
getCurrency() | string | Gets the currency used. |
setNote(string $note) | PreAuthorization | Optional note or description for the transaction. |
getNote() | string | Returns the note. |
setUrlOk(string $url) | PreAuthorization | URL to redirect after successful authorization. |
getUrlOk() | string | Gets success redirect URL. |
setUrlCancel(string $url) | PreAuthorization | URL to redirect if customer cancels or fails authorization. |
getUrlCancel() | string | Gets cancellation URL. |
setUrlNotify(string $url) | PreAuthorization | Webhook for server-to-server notifications. |
getUrlNotify() | string | Gets notify URL. |
validate() | bool | Validates that all required parameters are set. |
process() | bool | Sends the API request and initiates the pre-auth. |
Inherited from Base
Includes all core communication tools:
_addPostParam()*_processPost(), _processHtmlPost()getCnf(), setCnf()getOutputFormat(), setOutputFormat()isValidSignature()
Example Usage
use Mypos\IPC\Config;
use Mypos\IPC\PreAuthorization;
$config = new Config();
// Set SID, wallet, API keys, etc.
$preAuth = new PreAuthorization($config);
$preAuth->setOrderID('AUTH-20250410-XYZ')
->setAmount(150.00)
->setCurrency('EUR')
->setItemName('Hotel Booking')
->setNote('Reservation for April 20-22')
->setUrlOk('https://merchant.com/success')
->setUrlCancel('https://merchant.com/cancel')
->setUrlNotify('https://merchant.com/notify');
if ($preAuth->validate()) {
$preAuth->process(); // Customer redirected to myPOS pre-auth page
} else {
echo "Validation failed. Please check required fields.";
}
Use Cases
Use the PreAuthorization class when you:
- Need to reserve funds without charging the customer immediately
- Want to capture payment later after service is confirmed
- Provide physical goods, bookings, rentals, or event holds
- Require PCI-DSS compliant handling via redirect-based flow