The Java server library for the App Store Server API, App Store Server Notifications, Retention Messaging API, and Advanced Commerce API. Also available in Swift, Python, and Node.js.
- Java 11+
implementation 'com.apple.itunes.storekit:app-store-server-library:5.2.0'<dependency>
<groupId>com.apple.itunes.storekit</groupId>
<artifactId>app-store-server-library</artifactId>
<version>5.2.0</version>
</dependency>To use the App Store Server API or create promotional offer signatures, a signing key downloaded from App Store Connect is required. To obtain this key, you must have the Admin role. Go to Users and Access > Integrations > In-App Purchase. Here you can create and manage keys, as well as find your issuer ID. When using a key, you'll need the key ID and issuer ID as well.
Download and store the root certificates found in the Apple Root Certificates section of the Apple PKI site. Provide these certificates as an array to a SignedDataVerifier to allow verifying the signed data comes from Apple.
importcom.apple.itunes.storekit.client.APIException;
importcom.apple.itunes.storekit.client.AppStoreServerAPIClient;
importcom.apple.itunes.storekit.model.Environment;
importcom.apple.itunes.storekit.model.SendTestNotificationResponse;
importjava.io.IOException;
importjava.nio.file.Files;
importjava.nio.file.Path;
publicclassAPIExample {
publicstaticvoidmain(String[] args) throwsException {
StringissuerId = "99b16628-15e4-4668-972b-eeff55eeff55";
StringkeyId = "ABCDEFGHIJ";
StringbundleId = "com.example";
PathfilePath = Path.of("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8");
StringencodedKey = Files.readString(filePath);
Environmentenvironment = Environment.SANDBOX;
AppStoreServerAPIClientclient =
newAppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment);
try {
SendTestNotificationResponseresponse = client.requestTestNotification();
System.out.println(response);
} catch (APIException | IOExceptione) {
e.printStackTrace();
}
}
}importcom.apple.itunes.storekit.model.Environment;
importcom.apple.itunes.storekit.model.ResponseBodyV2DecodedPayload;
importcom.apple.itunes.storekit.verification.SignedDataVerifier;
importcom.apple.itunes.storekit.verification.VerificationException;
importjava.io.FileInputStream;
importjava.io.InputStream;
importjava.util.Set;
publicclassExampleVerification {
publicstaticvoidmain(String[] args) {
StringbundleId = "com.example";
Environmentenvironment = Environment.SANDBOX;
Set<InputStream> rootCAs = Set.of(
newFileInputStream("/path/to/rootCA1"),
newFileInputStream("/path/to/rootCA2")
);
LongappAppleId = null; // appAppleId must be provided for the Production environmentSignedDataVerifiersignedPayloadVerifier = newSignedDataVerifier(rootCAs, bundleId, appAppleId, environment, true);
StringnotificationPayload = "ey...";
try {
ResponseBodyV2DecodedPayloadpayload = signedPayloadVerifier.verifyAndDecodeNotification(notificationPayload);
System.out.println(payload);
} catch (VerificationExceptione) {
e.printStackTrace();
}
}
}importcom.apple.itunes.storekit.client.AppStoreServerAPIClient;
importcom.apple.itunes.storekit.client.GetTransactionHistoryVersion;
importcom.apple.itunes.storekit.migration.ReceiptUtility;
importcom.apple.itunes.storekit.model.Environment;
importcom.apple.itunes.storekit.model.HistoryResponse;
importcom.apple.itunes.storekit.model.TransactionHistoryRequest;
importjava.nio.file.Files;
importjava.nio.file.Path;
importjava.util.LinkedList;
importjava.util.List;
publicclassExampleMigration {
publicstaticvoidmain(String[] args) throwsException {
StringissuerId = "99b16628-15e4-4668-972b-eeff55eeff55";
StringkeyId = "ABCDEFGHIJ";
StringbundleId = "com.example";
PathfilePath = Path.of("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8");
StringencodedKey = Files.readString(filePath);
Environmentenvironment = Environment.SANDBOX;
AppStoreServerAPIClientclient =
newAppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment);
StringappReceipt = "MI...";
ReceiptUtilityreceiptUtil = newReceiptUtility();
StringtransactionId = receiptUtil.extractTransactionIdFromAppReceipt(appReceipt);
if (transactionId != null) {
TransactionHistoryRequestrequest = newTransactionHistoryRequest()
.sort(TransactionHistoryRequest.Order.ASCENDING)
.revoked(false)
.productTypes(List.of(TransactionHistoryRequest.ProductType.AUTO_RENEWABLE));
HistoryResponseresponse = null;
List<String> transactions = newLinkedList<>();
do {
Stringrevision = response != null ? response.getRevision() : null;
response = client.getTransactionHistory(transactionId, revision, request, GetTransactionHistoryVersion.V2);
transactions.addAll(response.getSignedTransactions());
} while (response.getHasMore());
System.out.println(transactions);
}
}
}importcom.apple.itunes.storekit.offers.PromotionalOfferSignatureCreator;
importjava.nio.file.Files;
importjava.nio.file.Path;
importjava.util.UUID;
publicclassExampleSignatureCreation {
publicstaticvoidmain(String[] args) throwsException {
StringkeyId = "ABCDEFGHIJ";
StringbundleId = "com.example";
PathfilePath = Path.of("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8");
StringencodedKey = Files.readString(filePath);
PromotionalOfferSignatureCreatorsignatureCreator = newPromotionalOfferSignatureCreator(encodedKey, keyId, bundleId);
StringproductId = "<product_id>";
StringsubscriptionOfferId = "<subscription_offer_id>";
StringappAccountToken = "<app_account_token>";
UUIDnonce = UUID.randomUUID();
longtimestamp = System.currentTimeMillis();
StringencodedSignature = signatureCreator.createSignature(productId, subscriptionOfferId, appAccountToken, nonce, timestamp);
System.out.println(encodedSignature);
}
}Only the latest major version of the library will receive updates, including security updates. Therefore, it is recommended to update to new major versions.