yousefkadah/apple-pay-decoder
Composer 安装命令:
composer require yousefkadah/apple-pay-decoder
包简介
A PHP library for decrypting Apple Pay payment tokens (EC_v1) with production-ready cryptographic operations
README 文档
README
A production-ready PHP library for decrypting Apple Pay payment tokens using real cryptographic operations. This package implements the complete EC_v1 token decryption process including ECDH key agreement, KDF derivation, and AES-GCM decryption.
Features
- ✅ EC_v1 Token Support: Full support for Apple Pay's EC_v1 encrypted payment tokens
- ✅ Production Ready: Real cryptographic operations using OpenSSL
- ✅ Security First: Proper validation and error handling
- ✅ Framework Agnostic: Works with any PHP framework or standalone
- ✅ PSR-4 Compatible: Modern PHP package structure
- ✅ Well Tested: Comprehensive test suite
- ✅ Type Safe: Full PHP 8+ type declarations
Requirements
- PHP 8.0 or higher
- OpenSSL extension
- JSON extension
Installation
You can install the package via composer:
composer require yousefkadah/apple-pay-decoder
Quick Start
Method 1: Using the Facade (Easiest)
<?php use YousefKadah\ApplePayDecoder\Facade\ApplePay; // One-time decryption $decryptedData = ApplePay::decrypt( $paymentToken, 'merchant.com.yourcompany.app', '/path/to/merchant_certificate.pem', '/path/to/merchant_private_key.pem' ); // Or configure once, use multiple times ApplePay::configure( 'merchant.com.yourcompany.app', '/path/to/merchant_certificate.pem', '/path/to/merchant_private_key.pem' ); $decryptedData = ApplePay::quickDecrypt($paymentToken);
Method 2: Using Environment Variables
<?php use YousefKadah\ApplePayDecoder\Facade\ApplePay; // Set environment variables $_ENV['APPLE_PAY_MERCHANT_ID'] = 'merchant.com.yourcompany.app'; $_ENV['APPLE_PAY_CERT_PATH'] = '/path/to/merchant_certificate.pem'; $_ENV['APPLE_PAY_KEY_PATH'] = '/path/to/merchant_private_key.pem'; // Configure from environment ApplePay::configureFromEnvironment(); // Use it $decryptedData = ApplePay::quickDecrypt($paymentToken);
Method 3: Using the Service Class Directly
<?php use YousefKadah\ApplePayDecoder\ApplePayDecryptionService; use YousefKadah\ApplePayDecoder\Config\MerchantConfig; // Configure your merchant credentials $config = new MerchantConfig( merchantId: 'merchant.com.yourcompany.app', certificatePath: '/path/to/merchant_certificate.pem', privateKeyPath: '/path/to/merchant_private_key.pem' ); // Create service instance $service = new ApplePayDecryptionService($config); // Decrypt the payment token $decryptedData = $service->decrypt($paymentToken); // Access decrypted payment information echo "Card Number: " . $decryptedData['applicationPrimaryAccountNumber']; echo "Expiry: " . $decryptedData['applicationExpirationDate']; echo "Amount: " . $decryptedData['transactionAmount']; echo "Currency: " . $decryptedData['currencyCode'];
Laravel Integration
For Laravel applications, you can easily integrate the facade:
<?php // In a service provider or controller use YousefKadah\ApplePayDecoder\Facade\ApplePay; class PaymentController extends Controller { public function processApplePayment(Request $request) { // Configure once in service provider ApplePay::configure( config('applepay.merchant_id'), config('applepay.cert_path'), config('applepay.key_path') ); // Use in controllers $paymentData = $request->get('paymentData'); $decryptedData = ApplePay::quickDecrypt($paymentData); // Process payment... return response()->json(['status' => 'success']); } }
Configuration Management
Environment Variables
Set these environment variables for easy configuration:
APPLE_PAY_MERCHANT_ID=merchant.com.yourcompany.app APPLE_PAY_CERT_PATH=/path/to/merchant_certificate.pem APPLE_PAY_KEY_PATH=/path/to/merchant_private_key.pem
Then use:
ApplePay::configureFromEnvironment(); $result = ApplePay::quickDecrypt($paymentToken);
Advanced Usage
Custom Logger
use Psr\Log\LoggerInterface; use YousefKadah\ApplePayDecoder\ApplePayDecryptionService; $service = new ApplePayDecryptionService($config, $logger);
Legacy Compatibility
// For backward compatibility, the old ApplePayDecoder still works use YousefKadah\ApplePayDecoder\ApplePayDecoder; $decoder = new ApplePayDecoder($config); $result = $decoder->decrypt($paymentToken);
Component Usage (Advanced)
// Use individual components for custom implementations use YousefKadah\ApplePayDecoder\Crypto\EcdhKeyAgreement; use YousefKadah\ApplePayDecoder\Crypto\KeyDerivationFunction; use YousefKadah\ApplePayDecoder\Crypto\AesGcmDecryption; $ecdh = new EcdhKeyAgreement($logger); $kdf = new KeyDerivationFunction($logger, $merchantId); $aes = new AesGcmDecryption($logger); // Perform individual cryptographic operations...
Decrypted Data Structure
The decrypted payment token contains the following information:
[
'applicationPrimaryAccountNumber' => '4111111111111111', // Card number
'applicationExpirationDate' => '251231', // YYMMDD format
'currencyCode' => '840', // ISO 4217 currency code
'transactionAmount' => 1000, // Amount in smallest currency unit
'deviceManufacturerIdentifier' => '040010030273', // Device identifier
'paymentDataType' => '3DSecure', // Payment data type
'paymentData' => [
'onlinePaymentCryptogram' => 'base64-cryptogram' // 3DS cryptogram
]
]
Apple Pay Setup
Before using this package, you need to set up Apple Pay merchant certificates:
- Apple Developer Account: Enroll in Apple Developer Program
- Merchant ID: Create a merchant identifier
- Payment Processing Certificate: Generate and download the certificate
- Private Key: Extract the private key from the certificate
For detailed setup instructions, visit Apple's official documentation.
Security Considerations
- 🔒 Certificate Security: Store certificates securely and rotate regularly
- 🔒 Private Key Protection: Never expose private keys in version control
- 🔒 Environment Variables: Use environment variables for sensitive configuration
- 🔒 Logging: Avoid logging sensitive decrypted data in production
- 🔒 Validation: Always validate merchant configuration before processing
Testing
# Run tests composer test # Run tests with coverage composer test-coverage # Run static analysis composer phpstan # Check code style composer cs-check # Fix code style composer cs-fix
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security related issues, please email your-email@example.com instead of using the issue tracker.
Credits
Inspired by Apple's Payment Token Format Reference and various open-source implementations.
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
Support
Made with ❤️ for the PHP community
yousefkadah/apple-pay-decoder 适用场景与选型建议
yousefkadah/apple-pay-decoder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 123 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「token」 「decrypt」 「ecdh」 「AES-GCM」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yousefkadah/apple-pay-decoder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yousefkadah/apple-pay-decoder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yousefkadah/apple-pay-decoder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A package for validating Google Cloud's JWT provided by webhooks
JSON Web Token Authentication for Laravel and Lumen
JSON Web Token Authentication for Laravel and Lumen
JSON Web Token Authentication for Laravel and Lumen
JSON Web Token Authentication for Laravel and Lumen
JSON Web Token for codeigniter4 authentication.
统计信息
- 总下载量: 123
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-26