nullform/app-store-server-api-client
Composer 安装命令:
composer require nullform/app-store-server-api-client
包简介
PHP client for App Store Server API and App Store Server Notifications
README 文档
README
Unoffical PHP client for App Store Server API and App Store Server Notifications.
Installation
Requirements
- PHP >= 8.0
Composer
composer require nullform/app-store-server-api-client
Usage
Create an API Key instance:
// As instance of anonymous class... $apiKey = new class extends AbstractApiKey {}; $apiKey->setPrivateKey(\file_get_contents($privateKeyFile)); $apiKey->setPrivateKeyId('Your private key id'); $apiKey->setIssuerId('Your issuer id'); $apiKey->setName('Key name (optional)'); // ... or as instance of ApiKey $apiKey = new ApiKey( \file_get_contents($privateKeyFile), 'Your private key id', 'Your issuer id', 'Key name (optional)' );
Create a Bundle instance(s):
// As instance of anonymous class... $bundle = new class extends AbstractBundle {}; $bundle->setBundleId('Your bundle id'); $bundle->setName('Bundle name (optional)'); // ... or as instance of Bundle $bundle2 = new Bundle('Your bundle #2 id');
Create an API client instance:
$client = new AppStoreServerApiClient($apiKey, $bundle, Environment::PRODUCTION);
Use client for one or multiple bundles:
try { $historyResponse = $client->getTransactionHistory($originalTransactionId); $transactions = $historyResponse->getDecodedTransactions(); } catch (HttpClientException $httpClientException) { echo "HTTP client error: " . $httpClientException->getMessage(); } catch (AppleException $appleException) { echo "Apple error ({$appleException->getCode()}): " . $appleException->getMessage(); } try { $bundle2HistoryResponse = $client->setBundle($bundle2)->getTransactionHistory($originalTransactionId); } catch (\Exception $e) { echo "Error: " . $e->getMessage(); }
You can manually call the App Store Server API via universal callApi() method:
use Nullform\AppStoreServerApiClient\AppStoreServerApiClient; use Nullform\AppStoreServerApiClient\AbstractModel; use Nullform\AppStoreServerApiClient\Environment; $apiKey = new MyApiKey(); // Extends AbstractApiKey $bundle = new MyBundle(); // Extends AbstractBundle $client = new AppStoreServerApiClient($apiKey, $bundle, Environment::SANDBOX); $queryParams = new class extends AbstractModel { public $param = 'value'; }; $requestBody = new class extends AbstractModel { public $bodyParam = 'value'; }; // Get instance of ResponseInterface $response = $client->callApi("POST", "inApps/v1/notifications/test", $queryParams, $requestBody); // Get response body $responseBody = $response->getBody()->getContents();
AppStoreServerApiClient methods
Get Transaction History
AppStoreServerApiClient::getTransactionHistory( string $transactionId, null|string|GetTransactionHistoryParams $paramsOrRevision = null ): HistoryResponse
Get a customer’s in-app purchase transaction history for your app.
https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history
Get All Transactions History
AppStoreServerApiClient::getAllTransactionHistory( string $transactionId ): JWSTransactionDecodedPayload[]
Recursively get FULL transaction history.
Get Transaction Info
AppStoreServerApiClient::getTransactionInfo( string $transactionId ): TransactionInfoResponse
Get information about a single transaction for your app.
https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info
Get All Subscription Statuses
AppStoreServerApiClient::getAllSubscriptionStatuses( string $transactionId ): StatusResponse
Get the statuses for all of a customer’s subscriptions in your app.
https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses
Send Consumption Information
AppStoreServerApiClient::sendConsumptionInformation( string $transactionId, ConsumptionRequest $request ): void
Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
Look Up Order Id
AppStoreServerApiClient::lookUpOrderId( string $orderId ): OrderLookupResponse
Get a customer’s in-app purchases from a receipt using the order ID.
https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id
Get Refund History
AppStoreServerApiClient::getRefundHistory( string $transactionId ): RefundLookupResponse
Get a list of all refunded in-app purchases in your app for a customer.
https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
Extend a Subscription Renewal Date
AppStoreServerApiClient::extendSubscriptionRenewalDate( string $originalTransactionId, ExtendRenewalDateRequest $request ): ExtendRenewalDateResponse
Extend the renewal date of a customer’s active subscription using the original transaction identifier.
https://developer.apple.com/documentation/appstoreserverapi/extend_a_subscription_renewal_date
Extend Subscription Renewal Dates for All Active Subscribers
AppStoreServerApiClient::extendSubscriptionRenewalDatesForAllActiveSubscribers( MassExtendRenewalDateRequest $request ): MassExtendRenewalDateResponse
Uses a subscription’s product identifier to extend the renewal date for all of its eligible active subscribers.
Get Status of Subscription Renewal Date Extensions
AppStoreServerApiClient::getStatusOfSubscriptionRenewalDateExtensions( string $productId, string $requestIdentifier ): MassExtendRenewalDateStatusResponse
Checks whether a renewal date extension request completed, and provides the final count of successful or failed extensions.
Request a Test Notification
AppStoreServerApiClient::requestTestNotification(): SendTestNotificationResponse
Ask App Store Server Notifications to send a test notification to your server.
https://developer.apple.com/documentation/appstoreserverapi/request_a_test_notification
Get Test Notification Status
AppStoreServerApiClient::getTestNotificationStatus( string $testNotificationToken ): CheckTestNotificationResponse
Check the status of the test App Store server notification sent to your server.
https://developer.apple.com/documentation/appstoreserverapi/get_test_notification_status
Get Notification History
AppStoreServerApiClient::getNotificationHistory( NotificationHistoryRequest $params, ?string $paginationToken = null ): CheckTestNotificationResponse
Get a list of notifications that the App Store server attempted to send to your server.
https://developer.apple.com/documentation/appstoreserverapi/get_notification_history
Set App Store Bundle
AppStoreServerApiClient::setBundle( BundleInterface $bundle ): self
Set App Store bundle for authorize your API calls.
Set Token TTL
AppStoreServerApiClient::setTokenTtl( int $ttl ): self
Set new value for JWT TTL (in seconds). Maximum value: 3600.
https://developer.apple.com/documentation/appstoreserverapi/generating_tokens_for_api_requests
Set HTTP Client Request Timeout
AppStoreServerApiClient::setHttpClientRequestTimeout( float $timeout ): self
Set new value for HTTP client request timeout (in seconds).
Call API
AppStoreServerApiClient::callApi( string $method, string $path, ?AbstractModel $params = null, ?AbstractModel $body = null ): \Psr\Http\Message\ResponseInterface
Custom call App Store Server API with your previously passed credentials.
Receiving App Store Server Notifications V2
To receive App Store Server Notifications use AppStoreServerNotificationsClient:
$notificationClient = new AppStoreServerNotificationsClient(); try { $payload = $notificationClient->receive($requestBody); } catch (NotificationBadRequestException $exception) { echo $exception->getMessage(); }
Note that AppStoreServerNotificationsClient only for version 2 notifications.
Tests
For unit tests you must create credentials.php and private-key.p8 with the key and sandbox credentials from App Store Connect (see tests/credentials.example.php).
nullform/app-store-server-api-client 适用场景与选型建议
nullform/app-store-server-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.4k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2022 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「apple」 「itunes」 「app store」 「App Store Server API」 「app store server notifications」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nullform/app-store-server-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nullform/app-store-server-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nullform/app-store-server-api-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple library to decode and parse Apple Sign In client tokens.
Generate RSS feed for podcast, including iTunes, RawVoice, DublinCore and syndication fields.
A library that implements the App Store API (Server API and Connect API) and facilitates App Store Server Notifications V2
Apple Push Notification & Feedback Provider
Make your bundle an application
PHP library to find podcasts
统计信息
- 总下载量: 1.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-22