Skip to content

Commit 3f0fe41

Browse files
committed
Add a public GetApiToken that returns a signed JWT to make calls to the App Store API directly
Fixes #8
1 parent fc22f0b commit 3f0fe41

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/AppStoreServerApiClient.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,40 @@ public Task SendConsumptionData(string transactionId, ConsumptionRequest consump
106106
return this.MakeRequest<object?>(path, HttpMethod.Put, null, consumptionRequest, false);
107107
}
108108

109+
/// <summary>
110+
/// Get information about a single transaction for your app.
111+
/// </summary>
112+
/// <param name="transactionId">The identifier of a transaction that belongs to the customer, and which may be an original transaction identifier.</param>
113+
/// <exception cref="ApiException">Thrown when a response indicates the request could not be processed</exception>
114+
/// <remarks>
115+
/// See <see href="https://developer.apple.com/documentation/appstoreserverapi/get-v1-transactions-_transactionid_">Get Transaction Info</see>
116+
/// </remarks>
109117
public Task<TransactionInfoResponse?> GetTransactionInfo(string transactionId)
110118
{
111-
//Call to https://developer.apple.com/documentation/appstoreserverapi/get-v1-transactions-_transactionid_
112119
string path = $"/inApps/v1/transactions/{transactionId}";
113120

114121
return this.MakeRequest<TransactionInfoResponse>(path, HttpMethod.Get);
115122
}
116123

124+
/// <summary>
125+
/// Get a customer’s in-app purchases from a receipt using the order ID.
126+
/// </summary>
127+
/// <param name="orderId">The order ID for in-app purchases that belong to the customer.</param>
128+
/// <exception cref="ApiException">Thrown when a response indicates the request could not be processed</exception>
129+
/// <remarks>
130+
/// See <see href="https://developer.apple.com/documentation/appstoreserverapi/get-v1-lookup-_orderid_">Look Up Order ID</see>
131+
/// </remarks>
117132
public Task<OrderLookupResponse> LookUpOrderId(string orderId)
118133
{
119-
//Call to https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id
120134
string path = $"/inApps/v1/lookup/{orderId}";
121135

122136
return this.MakeRequest<OrderLookupResponse>(path, HttpMethod.Get)!;
123137
}
124138

125-
private static string CreateBearerToken(string keyId, string issuerId, string signingKey, string bundleId)
139+
/// <summary>
140+
/// Returns a signed JWT token that can be used to make requests to the App Store Server API directly.
141+
/// </summary>
142+
public string GetApiToken()
126143
{
127144
var prvKey = ECDsa.Create();
128145
prvKey.ImportFromPem(signingKey);
@@ -156,7 +173,7 @@ private static string CreateBearerToken(string keyId, string issuerId, string si
156173
)
157174
where TReturn : class
158175
{
159-
string token = CreateBearerToken(keyId, issuerId, signingKey, bundleId);
176+
string token = this.GetApiToken();
160177

161178
UriBuilder builder = new(environment.BaseUrl) { Path = path };
162179

0 commit comments

Comments
 (0)