Skip to content

Commit 5d72655

Browse files
authored
Merge pull request #6 from kt81/feat/transaction-info
Add TransactionInfo API
2 parents 2750816 + 6d3c55f commit 5d72655

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This is a list of the features that are currently implemented in the library, co
2323
| Get Transaction History v2 |||
2424
| Extract Transaction Id from receipt |||
2525
| Get Transaction History v1 || |
26-
| Get Transaction Info || |
26+
| Get Transaction Info || |
2727
| Send Consumption Information |||
2828
| Look Up Order ID || |
2929
| Get Refund History || |
@@ -65,7 +65,7 @@ try {
6565

6666
```
6767

68-
> [!IMPORTANT]
68+
> [!IMPORTANT]
6969
> The `SignedDataVerifier` will not verify the payload if the `environment` parameter is `LocalTesting`. This was done to allow testing fake payloads locally without the need to verify them.
7070
7171
### API

src/AppStoreServerApiClient.cs

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

109+
public Task<TransactionInfoResponse?> GetTransactionInfo(string transactionId)
110+
{
111+
//Call to https://developer.apple.com/documentation/appstoreserverapi/get-v1-transactions-_transactionid_
112+
string path = $"/inApps/v1/transactions/{transactionId}";
113+
114+
return this.MakeRequest<TransactionInfoResponse>(path, HttpMethod.Get);
115+
}
116+
109117
private static string CreateBearerToken(string keyId, string issuerId, string signingKey, string bundleId)
110118
{
111119
var prvKey = ECDsa.Create();

src/Models/AppStoreDataTypes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,14 @@ public class TransactionHistoryResponse
603603
public List<string> SignedTransactions { get; set; } = null!;
604604
}
605605

606+
/// <summary>
607+
/// A response that contains the customer’s transaction information for an app.
608+
/// </summary>
609+
public class TransactionInfoResponse
610+
{
611+
public string SignedTransactionInfo { get; set; } = null!;
612+
}
613+
606614
/// <summary>
607615
/// Error response from the App Store Server API.
608616
/// </summary>

tests/AppStoreServerApiClientTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,19 @@ await client.SendConsumptionData(
136136
}
137137
);
138138
}
139+
140+
[Fact]
141+
public async Task GetTransactionInfo_Success()
142+
{
143+
var mockHttp = new MockHttpMessageHandler();
144+
mockHttp
145+
.When($"https://local-testing-base-url/inApps/v1/transactions/1234")
146+
.Respond("application/json", "{\"signedTransactionInfo\":\"signed_transaction_info_value\"}");
147+
148+
AppStoreServerApiClient client = GetAppStoreServerApiClient(mockHttp);
149+
150+
TransactionInfoResponse? response = await client.GetTransactionInfo("1234");
151+
Assert.NotNull(response);
152+
Assert.Equal("signed_transaction_info_value", response.SignedTransactionInfo);
153+
}
139154
}

tests/SignedDataVerifierTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public async Task VerifyAndDecode_TransactionInfo_Success()
232232
BundleId
233233
);
234234

235-
JWSRenewalInfoDecodedPayload result = await dataVerifier.VerifyAndDecodeRenewalInfo(
235+
JwsTransactionDecodedPayload result = await dataVerifier.VerifyAndDecodeTransaction(
236236
didRenewNotificationPayload
237237
);
238238

0 commit comments

Comments
 (0)