The FinanceOrder class extends PKPass to create Apple Wallet Orders for financial transactions. It inherits all functionality from PKPass but generates orders with the .order extension and uses SHA-256 hashing instead of SHA-1.
- Overview
- Constructor
- Inherited Methods
- Constants
- Key Differences from PKPass
- Usage Example
- Error Handling
The FinanceOrder class is designed for creating Apple Wallet Orders, which are used for financial transactions like purchases, invoices, and receipts. Orders differ from passes in that they use:
- SHA-256 hashing algorithm (instead of SHA-1)
order.jsonas the payload file (instead ofpass.json).orderfile extension (instead of.pkpass)application/vnd.apple.finance.orderMIME type
Creates a new FinanceOrder instance. Same parameters as PKPass.
Parameters:
$certificatePath(string|bool, optional): Path to the P12 certificate file$certificatePassword(string|bool, optional): Password for the certificate
Example:
use PKPass\FinanceOrder;
// Create with certificate
$order = new FinanceOrder('/path/to/certificate.p12', 'password');
// Create without certificate (set later)
$order = new FinanceOrder();The FinanceOrder class inherits all public methods from PKPass:
setCertificatePath($path)- Sets the path to the certificate filesetCertificatePassword($password)- Sets the certificate passwordsetWwdrCertificatePath($path)- Sets the path to the WWDR certificatesetTempPath($path)- Sets the temporary directory path
setData($data)- Sets the order data (JSON content)setName($name)- Sets the filename for the generated ordergetName()- Gets the filename for the generated order
addFile($path, $name = null)- Adds a file to the order packageaddRemoteFile($url, $name = null)- Adds a file from a URLaddFileContent($content, $name)- Adds file content directly as a string
addLocaleStrings($language, $strings = [])- Adds localized stringsaddLocaleFile($language, $path, $name = null)- Adds a localized fileaddLocaleRemoteFile($language, $url, $name = null)- Adds a localized file from URLaddLocaleFileContent($language, $content, $name)- Adds localized file content
create($output = false)- Creates the actual.orderfile
FILE_TYPE- 'order' - The type identifier for ordersFILE_EXT- 'order' - The file extension for ordersMIME_TYPE- 'application/vnd.apple.finance.order' - The MIME type for ordersPAYLOAD_FILE- 'order.json' - The main payload file nameHASH_ALGO- 'sha256' - The hashing algorithm used
Example:
echo FinanceOrder::MIME_TYPE; // 'application/vnd.apple.finance.order'
echo FinanceOrder::HASH_ALGO; // 'sha256'- File Extension: Orders use
.orderinstead of.pkpass - MIME Type:
application/vnd.apple.finance.orderinstead ofapplication/vnd.apple.pkpass - Payload File:
order.jsoninstead ofpass.json - Hash Algorithm: SHA-256 instead of SHA-1 for better security
- Locale Files: Uses
order.stringsinstead ofpass.stringsfor localization
use PKPass\FinanceOrder;
try {
// Create order
$order = new FinanceOrder('/path/to/certificate.p12', 'password');
// Set order data
$orderData = [
'schemaVersion' => '1.0',
'orderTypeIdentifier' => 'order.com.mycompany.myorder',
'orderIdentifier' => 'ORDER12345',
'webServiceURL' => 'https://example.com/orders/',
'authenticationToken' => 'vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc',
'merchant' => [
'merchantIdentifier' => 'merchant.com.mycompany',
'displayName' => 'My Company Store'
],
'orderNumber' => 'ORD001',
'createdAt' => '2024-01-01T12:00:00Z',
'orderState' => 'open',
'payment' => [
'summaryItems' => [
[
'label' => 'Subtotal',
'amount' => '10.00'
],
[
'label' => 'Tax',
'amount' => '0.80'
],
[
'label' => 'Total',
'amount' => '10.80'
]
]
]
];
$order->setData($orderData);
// Add required files
$order->addFile('/path/to/icon.png');
$order->addFile('/path/to/logo.png');
// Add localization
$order->addLocaleStrings('en', [
'ORDER_TOTAL' => 'Total',
'ORDER_DATE' => 'Order Date'
]);
// Create and save the order
$orderContent = $order->create(false);
file_put_contents('myorder.order', $orderContent);
// Or output directly to browser
// $order->create(true);
} catch (PKPassException $e) {
echo 'Error creating order: ' . $e->getMessage();
}FinanceOrder inherits the same error handling as PKPass. All methods that can fail will throw a PKPassException. Always wrap critical operations in try-catch blocks:
try {
$order->setData($orderData);
$order->addFile('/path/to/icon.png');
$orderContent = $order->create(false);
} catch (PKPassException $e) {
echo 'Error: ' . $e->getMessage();
}- Missing certificate: Ensure certificate path and password are correct
- Invalid order data: Order data must be valid JSON or array
- Missing icon.png: Orders require an icon.png file
- File not found: Check that all file paths exist before adding them
- Invalid localization: Locale strings must be a non-empty array
Like passes, every order must include an icon.png file. The class will throw a PKPassException if this file is missing.
Recommended files:
icon.png(required) - 29×29 pointsicon@2x.png- 58×58 pointsicon@3x.png- 87×87 pointslogo.png- 160×50 points (max)logo@2x.png- 320×100 points (max)logo@3x.png- 480×150 points (max)