-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from alexanderjordanbaker/ASSA1.15andASSN2.15
Update to support App Store Server API 1.15 and App Store Server …
- Loading branch information
Showing
21 changed files
with
714 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ava/com/apple/itunes/storekit/advancedcommerce/AdvancedCommerceInAppSignatureCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2025 Apple Inc. Licensed under MIT License. | ||
|
||
package com.apple.itunes.storekit.advancedcommerce; | ||
|
||
import com.apple.itunes.storekit.model.AdvancedCommerceInAppRequest; | ||
import com.apple.itunes.storekit.signature.JWSSignatureCreator; | ||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class AdvancedCommerceInAppSignatureCreator extends JWSSignatureCreator { | ||
|
||
private static final String AUDIENCE = "advanced-commerce-api"; | ||
private static final String REQUEST_KEY = "request"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
/** | ||
* Create an AdvancedCommerceInAppSignatureCreator | ||
* @param signingKey Your private key downloaded from App Store Connect | ||
* @param keyId Your private key ID from App Store Connect | ||
* @param issuerId Your issuer ID from the Keys page in App Store Connect | ||
* @param bundleId Your app's bundle ID | ||
*/ | ||
public AdvancedCommerceInAppSignatureCreator(String signingKey, String keyId, String issuerId, String bundleId) { | ||
super(AUDIENCE, signingKey, keyId, issuerId, bundleId); | ||
this.objectMapper = new ObjectMapper(); | ||
objectMapper.setVisibility(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() | ||
.withFieldVisibility(JsonAutoDetect.Visibility.ANY) | ||
.withGetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
.withSetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); | ||
} | ||
|
||
/** | ||
* Create an Advanced Commerce in-app signed request. | ||
* | ||
* @see <a href="https://developer.apple.com/documentation/storekit/generating-jws-to-sign-app-store-requests">Generating JWS to sign App Store requests</a> | ||
* @param advancedCommerceInAppRequest The request to be signed. | ||
* @return The signed JWS | ||
*/ | ||
public String createSignature(AdvancedCommerceInAppRequest advancedCommerceInAppRequest) throws IOException { | ||
if (advancedCommerceInAppRequest == null) { | ||
throw new IllegalArgumentException("advancedCommerceInAppRequest cannot be null"); | ||
} | ||
String jsonRequest = objectMapper.writeValueAsString(advancedCommerceInAppRequest); | ||
byte[] utf8Bytes = jsonRequest.getBytes(StandardCharsets.UTF_8); | ||
String encodedRequest = Base64.getEncoder().encodeToString(utf8Bytes); | ||
Map<String, Object> claims = new HashMap<>(); | ||
claims.put(REQUEST_KEY, encodedRequest); | ||
return createSignature(claims); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/apple/itunes/storekit/model/AdvancedCommerceInAppRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.apple.itunes.storekit.model; | ||
|
||
public interface AdvancedCommerceInAppRequest { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.