PHP code example of nullform / app-store-server-api-client

1. Go to this page and download the library: Download nullform/app-store-server-api-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nullform / app-store-server-api-client example snippets


// 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)'
);

// 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');

$client = new AppStoreServerApiClient($apiKey, $bundle, Environment::PRODUCTION);

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();
}

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::getTransactionHistory(
    string $transactionId,
    null|string|GetTransactionHistoryParams $paramsOrRevision = null
): HistoryResponse

AppStoreServerApiClient::getAllTransactionHistory(
    string $transactionId
): JWSTransactionDecodedPayload[]

AppStoreServerApiClient::getTransactionInfo(
    string $transactionId
): TransactionInfoResponse

AppStoreServerApiClient::getAllSubscriptionStatuses(
    string $transactionId
): StatusResponse

AppStoreServerApiClient::sendConsumptionInformation(
    string $transactionId,
    ConsumptionRequest $request
): void

AppStoreServerApiClient::lookUpOrderId(
    string $orderId
): OrderLookupResponse

AppStoreServerApiClient::getRefundHistory(
    string $transactionId
): RefundLookupResponse

AppStoreServerApiClient::extendSubscriptionRenewalDate(
    string $originalTransactionId,
    ExtendRenewalDateRequest $request
): ExtendRenewalDateResponse

AppStoreServerApiClient::extendSubscriptionRenewalDatesForAllActiveSubscribers(
    MassExtendRenewalDateRequest $request
): MassExtendRenewalDateResponse

AppStoreServerApiClient::getStatusOfSubscriptionRenewalDateExtensions(
    string $productId,
    string $requestIdentifier
): MassExtendRenewalDateStatusResponse

AppStoreServerApiClient::requestTestNotification(): SendTestNotificationResponse

AppStoreServerApiClient::getTestNotificationStatus(
    string $testNotificationToken
): CheckTestNotificationResponse

AppStoreServerApiClient::getNotificationHistory(
    NotificationHistoryRequest $params,
    ?string $paginationToken = null
): CheckTestNotificationResponse

AppStoreServerApiClient::setBundle(
    BundleInterface $bundle
): self

AppStoreServerApiClient::setTokenTtl(
    int $ttl
): self

AppStoreServerApiClient::setHttpClientRequestTimeout(
    float $timeout
): self

AppStoreServerApiClient::callApi(
    string $method,
    string $path,
    ?AbstractModel $params = null,
    ?AbstractModel $body = null
): \Psr\Http\Message\ResponseInterface

$notificationClient = new AppStoreServerNotificationsClient();

try {
    $payload = $notificationClient->receive($requestBody);
} catch (NotificationBadRequestException $exception) {
    echo $exception->getMessage();
}