### Install PKPass Library with Composer Source: https://github.com/tschoffelen/php-pkpass/blob/master/README.md Install the PKPass library using Composer by running this command in your project's root directory. Alternatively, add the dependency to your composer.json file. ```bash composer require pkpass/pkpass ``` ```json "pkpass/pkpass": "^2.0.0" ``` -------------------------------- ### Configure Push Notifications for Wallet Passes Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/Push.md Initialize the Push class with your APNs credentials and pass type identifier. This setup is required before sending any push notifications. ```php use PKPass\Push; $push = new Push([ 'teamId' => 'ABCD1234XY', // Apple Developer Team ID 'keyId' => 'XYZ9876543', // Key ID from Apple Developer portal 'authKey' => '/path/AuthKey.p8', // Path to the AuthKey file 'bundleId' => 'pass.com.example.demo' // Your Pass Type Identifier ]); ``` -------------------------------- ### Get Pass Filename Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Retrieves the filename for the generated pass, including the extension. ```php $filename = $pass->getName(); // Returns 'my-store-card.pkpass' ``` -------------------------------- ### Configuration Methods Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md These methods are used to set up the necessary certificate paths and password for generating finance orders. ```APIDOC ## setCertificatePath ### Description Sets the path to the certificate file required for signing the order. ### Method `setCertificatePath(string $path)` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the certificate. ## setCertificatePassword ### Description Sets the password for the certificate file. ### Method `setCertificatePassword(string $password)` ### Parameters #### Path Parameters - **password** (string) - Required - The password for the certificate. ## setWwdrCertificatePath ### Description Sets the path to the WWDR (Apple Worldwide Developer Relations) certificate file. ### Method `setWwdrCertificatePath(string $path)` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the WWDR certificate. ## setTempPath ### Description Sets the path to the temporary directory used for intermediate files during order creation. ### Method `setTempPath(string $path)` ### Parameters #### Path Parameters - **path** (string) - Required - The path to the temporary directory. ``` -------------------------------- ### Constructor Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Creates a new PKPassBundle instance. This is the entry point for creating a bundle of passes. ```APIDOC ## __construct() ### Description Creates a new PKPassBundle instance. ### Method `__construct()` ### Example ```php use PKPass\PKPassBundle; $bundle = new PKPassBundle(); ``` ``` -------------------------------- ### create($output = false) Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Creates the actual .pkpass file. This method can either return the pass content as a binary string or output it directly to the browser. ```APIDOC ## `create($output = false)` ### Description Creates the actual `.pkpass` file. This method can either return the pass content as a binary string or output it directly to the browser. ### Method Signature `create(bool $output = false): string` ### Parameters #### Optional Parameters - `$output` (bool): Whether to output directly to browser (true) or return as string (false). Defaults to false. ### Returns `string` - The pass content as binary string (if $output is false). ### Throws `PKPassException` - if pass creation fails. ### Example ```php // Save to file $passContent = $pass->create(false); file_put_contents('mypass.pkpass', $passContent); // Output directly to browser $pass->create(true); ``` ``` -------------------------------- ### Instantiate PKPass with Certificate Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Create a new PKPass instance, providing the path to your P12 certificate and its password. ```php use PKPass\PKPass; // Create with certificate $pass = new PKPass('/path/to/certificate.p12', 'password'); ``` -------------------------------- ### Create FinanceOrder Instance Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Instantiate FinanceOrder with or without certificate details. The certificate is used for signing the order. ```php use PKPass\FinanceOrder; // Create with certificate $order = new FinanceOrder('/path/to/certificate.p12', 'password'); // Create without certificate (set later) $order = new FinanceOrder(); ``` -------------------------------- ### Create a new PKPassBundle instance Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Instantiate the PKPassBundle class to begin creating a bundle of passes. ```php use PKPass\PKPassBundle; $bundle = new PKPassBundle(); ``` -------------------------------- ### PKPass Constructor Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Initializes a new PKPass instance. You can provide the certificate path and password directly or set them later using configuration methods. ```APIDOC ## `__construct($certificatePath = null, $certificatePassword = null)` Creates a new PKPass instance. ### Parameters - `$certificatePath` (string|bool, optional): Path to the P12 certificate file - `$certificatePassword` (string|bool, optional): Password for the certificate ### Example ```php use PKPass\PKPass; // Create with certificate $pass = new PKPass('/path/to/certificate.p12', 'password'); // Create without certificate (set later) $pass = new PKPass(); ``` ``` -------------------------------- ### Create PKPass File Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Use the `create` method to generate the `.pkpass` file. Set `$output` to `false` to return the content as a string for saving, or `true` to output directly to the browser. ```php // Save to file $passContent = $pass->create(false); file_put_contents('mypass.pkpass', $passContent); ``` ```php // Output directly to browser $pass->create(true); ``` -------------------------------- ### __construct Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Creates a new FinanceOrder instance. This constructor accepts the same parameters as the PKPass constructor for certificate configuration. ```APIDOC ## __construct ### Description Creates a new FinanceOrder instance. Same parameters as PKPass. ### Method __construct($certificatePath = null, $certificatePassword = null) ### Parameters #### Path Parameters - **certificatePath** (string|bool) - Optional - Path to the P12 certificate file - **certificatePassword** (string|bool) - Optional - Password for the certificate ### Request Example ```php use PKPass\FinanceOrder; // Create with certificate $order = new FinanceOrder('/path/to/certificate.p12', 'password'); // Create without certificate (set later) $order = new FinanceOrder(); ``` ``` -------------------------------- ### Output Methods Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Methods for saving the pass bundle to a file or outputting it directly for download. ```APIDOC ## save($path) ### Description Saves the bundle as a `.pkpasses` file to the filesystem. ### Method `save($path)` ### Parameters #### Path Parameters - **path** (string) - Required - File path where the bundle should be saved ### Throws - `RuntimeException` if the file cannot be written ### Example ```php $bundle->save('/path/to/my-passes.pkpasses'); ``` ``` ```APIDOC ## output() ### Description Outputs the bundle as a `.pkpasses` file directly to the browser for download. This method sets appropriate HTTP headers and streams the file content directly to the browser, then terminates the script with `exit`. ### Method `output()` ### Headers set - `Content-Type: application/vnd.apple.pkpasses` - `Content-Disposition: attachment; filename="passes.pkpasses"` - `Cache-Control: no-cache, no-store, must-revalidate` - `Pragma: no-cache` ### Throws - `RuntimeException` if the stream cannot be created ### Example ```php // This will trigger a download in the browser $bundle->output(); // Script execution stops here ``` ``` -------------------------------- ### Order Creation Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Method to create the final .order file. ```APIDOC ## create ### Description Creates the actual `.order` file package using the configured data and files. ### Method `create(bool $output = false): string|bool` ### Parameters #### Path Parameters - **output** (bool) - Optional - If true, the method returns the content of the generated file; otherwise, it returns the path to the generated file. Defaults to false. ### Response #### Success Response (200) - **result** (string|bool) - Returns the path to the generated `.order` file if `$output` is false, or the file content as a string if `$output` is true. ``` -------------------------------- ### Create and Save a Finance Order Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md This snippet demonstrates how to create a finance order object, set its data, add associated files and localization strings, and then save it to a file. It includes error handling for potential exceptions during the process. ```php 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(); } ``` -------------------------------- ### Save PKPassBundle to a file Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Persist the PKPassBundle to the filesystem as a .pkpasses file. Ensure the specified path is writable. ```php $bundle->save('/path/to/my-passes.pkpasses'); ``` -------------------------------- ### Output PKPassBundle for browser download Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Stream the PKPassBundle directly to the browser as a .pkpasses file for download. This method terminates script execution. ```php // This will trigger a download in the browser $bundle->output(); // Script execution stops here ``` -------------------------------- ### Set Certificate Path Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Configure the PKPass instance by specifying the file path to the P12 certificate. ```php $pass->setCertificatePath('/path/to/certificate.p12'); ``` -------------------------------- ### Handle PKPass Creation Errors Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Wrap critical PKPass operations, such as setting data, adding files, and creating the pass, within a `try-catch` block to handle potential `PKPassException` errors gracefully. ```php try { $pass->setData($passData); $pass->addFile('/path/to/icon.png'); $passContent = $pass->create(false); } catch (PKPassException $e) { echo 'Error: ' . $e->getMessage(); } ``` -------------------------------- ### Create PKPass Bundle with Multiple Passes Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md This snippet shows how to create a PKPass bundle containing both a boarding pass and an event ticket. It includes setting up individual passes with their data and files, then adding them to a bundle before saving. ```php use PKPass\PKPass; use PKPass\PKPassBundle; try { // Create first pass (boarding pass) $boardingPass = new PKPass('/path/to/certificate.p12', 'password'); $boardingPass->setData([ 'description' => 'Flight Ticket', 'formatVersion' => 1, 'organizationName' => 'Airline Inc', 'passTypeIdentifier' => 'pass.com.airline.boarding', 'serialNumber' => 'FLIGHT001', 'teamIdentifier' => 'TEAM123', 'boardingPass' => [ 'primaryFields' => [ [ 'key' => 'destination', 'label' => 'TO', 'value' => 'SFO' ] ] ] ]); $boardingPass->addFile('/path/to/flight-icon.png', 'icon.png'); // Create second pass (event ticket) $eventPass = new PKPass('/path/to/certificate.p12', 'password'); $eventPass->setData([ 'description' => 'Concert Ticket', 'formatVersion' => 1, 'organizationName' => 'Music Venue', 'passTypeIdentifier' => 'pass.com.venue.event', 'serialNumber' => 'EVENT001', 'teamIdentifier' => 'TEAM123', 'eventTicket' => [ 'primaryFields' => [ [ 'key' => 'event', 'label' => 'EVENT', 'value' => 'Rock Concert' ] ] ] ]); $eventPass->addFile('/path/to/concert-icon.png', 'icon.png'); // Create bundle and add passes $bundle = new PKPassBundle(); $bundle->add($boardingPass); $bundle->add($eventPass); // Save to file $bundle->save('/path/to/travel-bundle.pkpasses'); // Or output directly to browser // $bundle->output(); } catch (Exception $e) { echo 'Error creating bundle: ' . $e->getMessage(); } ``` -------------------------------- ### Localization Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Methods for adding localized strings and files to the order. ```APIDOC ## addLocaleStrings ### Description Adds localized strings for a specific language. ### Method `addLocaleStrings(string $language, array $strings = [])` ### Parameters #### Path Parameters - **language** (string) - Required - The language code (e.g., 'en', 'fr'). - **strings** (array) - Optional - An associative array of strings to localize. ## addLocaleFile ### Description Adds a localized file from a local path. ### Method `addLocaleFile(string $language, string $path, ?string $name = null)` ### Parameters #### Path Parameters - **language** (string) - Required - The language code. - **path** (string) - Required - The file path to the local file. - **name** (string) - Optional - The name to use for the file within the package. ## addLocaleRemoteFile ### Description Adds a localized file from a remote URL. ### Method `addLocaleRemoteFile(string $language, string $url, ?string $name = null)` ### Parameters #### Path Parameters - **language** (string) - Required - The language code. - **url** (string) - Required - The URL of the remote file. - **name** (string) - Optional - The name to use for the file within the package. ## addLocaleFileContent ### Description Adds localized file content directly as a string. ### Method `addLocaleFileContent(string $language, string $content, string $name)` ### Parameters #### Path Parameters - **language** (string) - Required - The language code. - **content** (string) - Required - The content of the file as a string. - **name** (string) - Required - The name to use for the file within the package. ``` -------------------------------- ### Instantiate PKPass without Certificate Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Create a new PKPass instance without an initial certificate. The certificate can be set later using configuration methods. ```php use PKPass\PKPass; // Create without certificate (set later) $pass = new PKPass(); ``` -------------------------------- ### Accessing FinanceOrder Class Constants Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Demonstrates how to access the MIME_TYPE and HASH_ALGO constants defined within the FinanceOrder class. ```php echo FinanceOrder::MIME_TYPE; // 'application/vnd.apple.finance.order' echo FinanceOrder::HASH_ALGO; // 'sha256' ``` -------------------------------- ### Set Certificate from String Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Configure the PKPass instance by providing the P12 certificate content directly as a string. This method overrides any previously set certificate path. ```php $pass->setCertificateString($p12_string); ``` -------------------------------- ### Add PKPass objects to a bundle Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Add individual PKPass instances to the PKPassBundle. Ensure each PKPass is properly configured before adding. ```php use PKPass\PKPass; use PKPass\PKPassBundle; // Create individual passes $pass1 = new PKPass('/path/to/certificate.p12', 'password'); $pass1->setData($passData1); $pass1->addFile('/path/to/icon1.png'); $pass2 = new PKPass('/path/to/certificate.p12', 'password'); $pass2->setData($passData2); $pass2->addFile('/path/to/icon2.png'); // Create bundle and add passes $bundle = new PKPassBundle(); $bundle->add($pass1); $bundle->add($pass2); ``` -------------------------------- ### File Management Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Methods for adding various types of files to the order package. ```APIDOC ## addFile ### Description Adds a local file to the order package. ### Method `addFile(string $path, ?string $name = null)` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the local file. - **name** (string) - Optional - The name to use for the file within the package. If null, the original filename is used. ## addRemoteFile ### Description Adds a file from a remote URL to the order package. ### Method `addRemoteFile(string $url, ?string $name = null)` ### Parameters #### Path Parameters - **url** (string) - Required - The URL of the remote file. - **name** (string) - Optional - The name to use for the file within the package. If null, the filename from the URL is used. ## addFileContent ### Description Adds file content directly as a string to the order package. ### Method `addFileContent(string $content, string $name)` ### Parameters #### Path Parameters - **content** (string) - Required - The content of the file as a string. - **name** (string) - Required - The name to use for the file within the package. ``` -------------------------------- ### Add File to Pass Package Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a file from the local filesystem to the pass package. If no name is provided, the basename of the path is used. Throws PKPassException if the file does not exist. ```php $pass->addFile('/path/to/icon.png'); $pass->addFile('/path/to/logo.png', 'logo.png'); ``` -------------------------------- ### setName Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the base filename for the generated PKPass file. ```APIDOC ## setName($name) ### Description Sets the filename for the generated pass. ### Parameters #### Parameters - **$name** (string): Filename (without extension) ### Example ```php $pass->setName('my-store-card'); ``` ``` -------------------------------- ### Add Localized Strings to PKPass Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Use this method to add key-value pairs of localized strings for a specific language. Ensure strings are not empty and are provided as an array. ```php $pass->addLocaleStrings('en', [ 'BALANCE' => 'Balance', 'POINTS' => 'Points' ]); $pass->addLocaleStrings('fr', [ 'BALANCE' => 'Solde', 'POINTS' => 'Points' ]); ``` -------------------------------- ### Add Localized File to PKPass Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Incorporate a localized file from the local filesystem into the pass archive. The file must exist at the specified path. ```php $pass->addLocaleFile('en', '/path/to/en/logo.png'); $pass->addLocaleFile('fr', '/path/to/fr/logo.png', 'logo.png'); ``` -------------------------------- ### Data Management Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Methods for setting and retrieving the order data and its filename. ```APIDOC ## setData ### Description Sets the order data, typically in JSON format, which will be included in the order payload. ### Method `setData(array $data)` ### Parameters #### Path Parameters - **data** (array) - Required - An array representing the JSON content of the order. ## setName ### Description Sets the filename for the generated order file. ### Method `setName(string $name)` ### Parameters #### Path Parameters - **name** (string) - Required - The desired filename for the order. ## getName ### Description Gets the currently set filename for the generated order file. ### Method `getName(): string` ### Response #### Success Response (200) - **name** (string) - The filename of the order. ``` -------------------------------- ### Set Temporary Path Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Define the directory where the PKPass class will store temporary files during the pass creation process. ```php $pass->setTempPath('/tmp/pkpass'); ``` -------------------------------- ### Handle PKPassBundle Exceptions Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Always wrap bundle operations in try-catch blocks to handle potential InvalidArgumentException or RuntimeException errors. ```php try { $bundle = new PKPassBundle(); $bundle->add($pass1); $bundle->add($pass2); $bundle->save('/path/to/bundle.pkpasses'); } catch (InvalidArgumentException $e) { echo 'Invalid pass object: ' . $e->getMessage(); } catch (RuntimeException $e) { echo 'Bundle creation failed: ' . $e->getMessage(); } ``` -------------------------------- ### Decrypt and Re-encrypt PKCS12 File for OpenSSL Compatibility Source: https://github.com/tschoffelen/php-pkpass/blob/master/README.md Use these OpenSSL commands to convert an encrypted .p12 file to a new one compatible with OpenSSL v3+. This is useful when encountering 'Could not read certificate file' errors due to deprecated OpenSSL hashes. ```bash openssl pkcs12 -legacy -in key.p12 -nodes -out key_decrypted.tmp ``` ```bash openssl pkcs12 -in key_decrypted.tmp -export -out key_new.p12 -certpbe AES-256-CBC -keypbe AES-256-CBC -iter 2048 ``` -------------------------------- ### Handle PKPassException in FinanceOrder Operations Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Wrap critical FinanceOrder operations in a try-catch block to handle potential PKPassException errors. This ensures graceful error management for operations like setting data, adding files, and creating the order. ```php try { $order->setData($orderData); $order->addFile('/path/to/icon.png'); $orderContent = $order->create(false); } catch (PKPassException $e) { echo 'Error: ' . $e->getMessage(); } ``` -------------------------------- ### addFile Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a local file from a given path to the pass package. An optional name can be provided for the file within the archive. ```APIDOC ## addFile($path, $name = null) ### Description Adds a file to the pass package. ### Parameters #### Parameters - **$path** (string): Path to the file - **$name** (string, optional): Name to use in the pass archive (defaults to basename of path) ### Throws - PKPassException: if file doesn't exist ### Example ```php $pass->addFile('/path/to/icon.png'); $pass->addFile('/path/to/logo.png', 'logo.png'); ``` ``` -------------------------------- ### getName Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Retrieves the currently set filename for the PKPass file, including the .pkpass extension. ```APIDOC ## getName() ### Description Gets the filename for the generated pass. ### Returns - string: The filename with extension ### Example ```php $filename = $pass->getName(); // Returns 'my-store-card.pkpass' ``` ``` -------------------------------- ### Add File Content to Pass Package Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a file to the pass package using its string content. A filename must be provided. ```php $svgContent = '...'; $pass->addFileContent($svgContent, 'logo.svg'); ``` -------------------------------- ### Add Remote File to Pass Package Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a file from a URL to the pass package. If no name is provided, the basename of the URL is used. ```php $pass->addRemoteFile('https://example.com/icon.png'); $pass->addRemoteFile('https://example.com/logo.png', 'custom-logo.png'); ``` -------------------------------- ### Set WWDR Certificate Path Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Specify the file path for the Apple WWDR Intermediate certificate, which is necessary for signing passes. ```php $pass->setWwdrCertificatePath('/path/to/AppleWWDRCA.pem'); ``` -------------------------------- ### Set WWDR Certificate Path Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the file path for the Apple Worldwide Developer Relations Certificate Authority (WWDR) intermediate certificate. This is necessary for signing passes. ```APIDOC ## `setWwdrCertificatePath($path)` Sets the path to the Apple WWDR Intermediate certificate. ### Parameters - `$path` (string): Path to the WWDR certificate ### Returns `bool` - Always returns true ### Example ```php $pass->setWwdrCertificatePath('/path/to/AppleWWDRCA.pem'); ``` ``` -------------------------------- ### Add Localized File Content to PKPass Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Embed localized file content directly from a string into the pass archive. A filename must be provided for the content. ```php $frenchContent = 'Localized content in French'; $pass->addLocaleFileContent('fr', $frenchContent, 'terms.txt'); ``` -------------------------------- ### Set Certificate Path Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the file path for the P12 certificate used for signing the pass. This method is part of the configuration options for the PKPass instance. ```APIDOC ## `setCertificatePath($path)` Sets the path to the certificate file. ### Parameters - `$path` (string): Path to the P12 certificate file ### Returns `bool` - Always returns true ### Example ```php $pass->setCertificatePath('/path/to/certificate.p12'); ``` ``` -------------------------------- ### Set Temporary Path Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Specifies the directory where temporary files will be stored during the pass creation process. This is useful for managing disk space and permissions. ```APIDOC ## `setTempPath($path)` Sets the path to the temporary directory for file operations. ### Parameters - `$path` (string): Path to temporary directory ### Example ```php $pass->setTempPath('/tmp/pkpass'); ``` ``` -------------------------------- ### Bundle Management Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPassBundle.md Methods for managing the passes within a bundle, primarily adding new passes. ```APIDOC ## add(PKPass $pass) ### Description Adds a pass to the bundle. ### Method `add(PKPass $pass)` ### Parameters #### Path Parameters - **pass** (PKPass) - Required - A PKPass instance to add to the bundle ### Throws - `InvalidArgumentException` if the parameter is not a PKPass instance ### Example ```php use PKPass\PKPass; use PKPass\PKPassBundle; // Create individual passes $pass1 = new PKPass('/path/to/certificate.p12', 'password'); $pass1->setData($passData1); $pass1->addFile('/path/to/icon1.png'); $pass2 = new PKPass('/path/to/certificate.p12', 'password'); $pass2->setData($passData2); $pass2->addFile('/path/to/icon2.png'); // Create bundle and add passes $bundle = new PKPassBundle(); $bundle->add($pass1); $bundle->add($pass2); ``` ``` -------------------------------- ### Class Constants Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/FinanceOrder.md Defines constants related to the order file type, extension, MIME type, payload file name, and hashing algorithm. ```APIDOC ## Constants ### Class Constants - **FILE_TYPE**: 'order' - The type identifier for orders. - **FILE_EXT**: 'order' - The file extension for orders. - **MIME_TYPE**: 'application/vnd.apple.finance.order' - The MIME type for orders. - **PAYLOAD_FILE**: 'order.json' - The main payload file name. - **HASH_ALGO**: 'sha256' - The hashing algorithm used. ``` -------------------------------- ### Set Certificate Password Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Set the password required to access the P12 certificate. ```php $pass->setCertificatePassword('mypassword'); ``` -------------------------------- ### addLocaleFile Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a localized file from the local filesystem for a given language. This allows you to include language-specific assets like images or configuration files within the pass. ```APIDOC ## addLocaleFile($language, $path, $name = null) ### Description Adds a localized file for a specific language. ### Parameters #### Parameters - **language** (string) - Required - Language code - **path** (string) - Required - Path to the file - **name** (string) - Optional - Name to use in the pass archive ### Throws - PKPassException if file doesn't exist ### Example ```php $pass->addLocaleFile('en', '/path/to/en/logo.png'); $pass->addLocaleFile('fr', '/path/to/fr/logo.png', 'logo.png'); ``` ``` -------------------------------- ### Set Certificate String Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the P12 certificate directly from a string. This method overrides any previously set certificate path. ```APIDOC ## `setCertificateString($p12_string)` Sets the certificate from a string. If specified, this overrides any previously set certificate path. ### Parameters - `$p12_string` (string): The P12 certificate content as a string ### Returns `bool` - Always returns true ``` -------------------------------- ### addFileContent Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a file to the pass package using its content directly as a string. A name must be provided for the file within the archive. ```APIDOC ## addFileContent($content, $name) ### Description Adds a file from string content to the pass package. ### Parameters #### Parameters - **$content** (string): File content - **$name** (string): Filename to use in the pass archive ### Example ```php $svgContent = '...'; $pass->addFileContent($svgContent, 'logo.svg'); ``` ``` -------------------------------- ### Set Certificate Password Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the password for the P12 certificate. This is required if the certificate is protected by a password. ```APIDOC ## `setCertificatePassword($password)` Sets the certificate password. ### Parameters - `$password` (string): Password for the certificate ### Returns `bool` - Always returns true ### Example ```php $pass->setCertificatePassword('mypassword'); ``` ``` -------------------------------- ### Add Localized Remote File to PKPass Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Include a localized file from a remote URL into the pass archive. You can optionally specify a name for the file within the archive. ```php $pass->addLocaleRemoteFile('en', 'https://example.com/en/logo.png'); $pass->addLocaleRemoteFile('fr', 'https://example.com/fr/logo.png', 'logo.png'); ``` -------------------------------- ### Set Pass Filename Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the filename for the generated pass. The filename should not include the extension. ```php $pass->setName('my-store-card'); ``` -------------------------------- ### addLocaleFileContent Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds localized file content directly from a string for a specific language. This is convenient for dynamically generated content or when you have the file content readily available as a string. ```APIDOC ## addLocaleFileContent($language, $content, $name) ### Description Adds a localized file from string content for a specific language. ### Parameters #### Parameters - **language** (string) - Required - Language code - **content** (string) - Required - File content - **name** (string) - Required - Filename to use in the pass archive ### Example ```php $frenchContent = 'Localized content in French'; $pass->addLocaleFileContent('fr', $frenchContent, 'terms.txt'); ``` ``` -------------------------------- ### addRemoteFile Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a file from a remote URL to the pass package. An optional name can be specified for the file within the archive. ```APIDOC ## addRemoteFile($url, $name = null) ### Description Adds a file from a URL to the pass package. ### Parameters #### Parameters - **$url** (string): URL to the file - **$name** (string, optional): Name to use in the pass archive (defaults to basename of URL) ### Example ```php $pass->addRemoteFile('https://example.com/icon.png'); $pass->addRemoteFile('https://example.com/logo.png', 'custom-logo.png'); ``` ``` -------------------------------- ### Send Push Notification to Update Wallet Pass Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/Push.md Use the send method to notify a device that a Wallet pass has been updated. Ensure you have the correct device token, title, and body for the update. ```php $deviceToken = 'abcdef1234567890...'; // Obtained when device registers $title = '1234567890'; // Title $body = '1234567890'; // Body $push->send($deviceToken, $title, $body); ``` -------------------------------- ### addLocaleRemoteFile Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds a localized file from a remote URL for a specific language. This method is useful for including assets that are hosted externally and can be fetched during pass creation. ```APIDOC ## addLocaleRemoteFile($language, $url, $name = null) ### Description Adds a localized file from a URL for a specific language. ### Parameters #### Parameters - **language** (string) - Required - Language code - **url** (string) - Required - URL to the file - **name** (string) - Optional - Name to use in the pass archive ### Example ```php $pass->addLocaleRemoteFile('en', 'https://example.com/en/logo.png'); $pass->addLocaleRemoteFile('fr', 'https://example.com/fr/logo.png', 'logo.png'); ``` ``` -------------------------------- ### Set Pass Data Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the main JSON content of the pass. Accepts data as a JSON string, array, or object. Throws PKPassException if data is invalid. ```php $passData = [ 'description' => 'My Store Card', 'formatVersion' => 1, 'organizationName' => 'My Company', 'passTypeIdentifier' => 'pass.com.mycompany.mypass', 'serialNumber' => '123456', 'teamIdentifier' => 'TEAM123456', 'storeCard' => [ 'primaryFields' => [ [ 'key' => 'balance', 'label' => 'Balance', 'value' => '$25.00' ] ] ] ]; $pass->setData($passData); ``` -------------------------------- ### Access PKPass MIME Type Constant Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Retrieve the MIME type for PKPass files using the `PKPass::MIME_TYPE` class constant. This is useful for setting HTTP headers when serving pass files. ```php echo PKPass::MIME_TYPE; // 'application/vnd.apple.pkpass' ``` -------------------------------- ### Push updates to Wallet (APNs) Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/Push.md This method allows you to send a push notification to a specific device token to update a Wallet pass. It requires the necessary APNs authentication credentials to be configured. ```APIDOC ## Push updates to Wallet (APNs) ### Description Sends a push notification to a device to update a Wallet pass. This is useful for notifying users about changes such as new balances, flight delays, or order updates. ### Method `send(string $deviceToken, string $title, string $body)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php use PKPass\Push; $push = new Push([ 'teamId' => 'ABCD1234XY', // Apple Developer Team ID 'keyId' => 'XYZ9876543', // Key ID from Apple Developer portal 'authKey' => '/path/AuthKey.p8', // Path to the AuthKey file 'bundleId' => 'pass.com.example.demo' // Your Pass Type Identifier ]); $deviceToken = 'abcdef1234567890...'; // Obtained when device registers $title = '1234567890'; // Title $body = '1234567890'; // Body $push->send($deviceToken, $title, $body); ``` ### Response #### Success Response (200) This method does not return a value upon success. It throws an exception on failure. #### Response Example None ``` -------------------------------- ### setData Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Sets the main JSON content for the pass. Accepts data as a JSON string, PHP array, or object. ```APIDOC ## setData($data) ### Description Sets the pass data (the main JSON content of the pass). ### Parameters #### Parameters - **$data** (string|array|object): Pass data as JSON string, array, or object ### Throws - PKPassException: if data is invalid ### Example ```php $passData = [ 'description' => 'My Store Card', 'formatVersion' => 1, 'organizationName' => 'My Company', 'passTypeIdentifier' => 'pass.com.mycompany.mypass', 'serialNumber' => '123456', 'teamIdentifier' => 'TEAM123456', 'storeCard' => [ 'primaryFields' => [ [ 'key' => 'balance', 'label' => 'Balance', 'value' => '$25.00' ] ] ] ]; $pass->setData($passData); ``` ``` -------------------------------- ### addLocaleStrings Source: https://github.com/tschoffelen/php-pkpass/blob/master/docs/PKPass.md Adds localized string key-value pairs for a specified language to the pass. This is useful for translating text displayed within the pass, such as labels or values. ```APIDOC ## addLocaleStrings($language, $strings = []) ### Description Adds localized strings for a specific language. ### Parameters #### Parameters - **language** (string) - Required - Language code (e.g., 'en', 'fr', 'de') - **strings** (array) - Required - Key-value pairs of translation strings ### Throws - PKPassException if strings are empty or not an array ### Example ```php $pass->addLocaleStrings('en', [ 'BALANCE' => 'Balance', 'POINTS' => 'Points' ]); $pass->addLocaleStrings('fr', [ 'BALANCE' => 'Solde', 'POINTS' => 'Points' ]); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.