Skip to content

Commit fc22f0b

Browse files
authored
Merge pull request #9 from kt81/feat/lookUpOrderId
feat: LookUpOrderId API
2 parents 5d72655 + c88d85d commit fc22f0b

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This is a list of the features that are currently implemented in the library, co
2525
| Get Transaction History v1 || |
2626
| Get Transaction Info |||
2727
| Send Consumption Information |||
28-
| Look Up Order ID || |
28+
| Look Up Order ID || |
2929
| Get Refund History || |
3030
| Extending the renewal date for auto-renewable subscriptions || |
3131
| Request a Test Notification || |

src/AppStoreServerApiClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ public Task SendConsumptionData(string transactionId, ConsumptionRequest consump
114114
return this.MakeRequest<TransactionInfoResponse>(path, HttpMethod.Get);
115115
}
116116

117+
public Task<OrderLookupResponse> LookUpOrderId(string orderId)
118+
{
119+
//Call to https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id
120+
string path = $"/inApps/v1/lookup/{orderId}";
121+
122+
return this.MakeRequest<OrderLookupResponse>(path, HttpMethod.Get)!;
123+
}
124+
117125
private static string CreateBearerToken(string keyId, string issuerId, string signingKey, string bundleId)
118126
{
119127
var prvKey = ECDsa.Create();

src/Models/AppStoreDataTypes.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,31 @@ public class TransactionInfoResponse
611611
public string SignedTransactionInfo { get; set; } = null!;
612612
}
613613

614+
/// <summary>
615+
/// A response that includes the order lookup status and an array of signed transactions for the in-app purchases in the order.
616+
/// </summary>
617+
public class OrderLookupResponse
618+
{
619+
public OrderLookupStatus Status { get; set; }
620+
public List<string> SignedTransactions { get; set; } = null!;
621+
}
622+
623+
/// <summary>
624+
/// A value that indicates whether the order ID in the request is valid for your app.
625+
/// </summary>
626+
public enum OrderLookupStatus
627+
{
628+
/// <summary>
629+
/// Valid
630+
/// </summary>
631+
Valid = 0,
632+
633+
/// <summary>
634+
/// Invalid
635+
/// </summary>
636+
Invalid = 1,
637+
}
638+
614639
/// <summary>
615640
/// Error response from the App Store Server API.
616641
/// </summary>

tests/AppStoreServerApiClientTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,35 @@ public async Task GetTransactionInfo_Success()
151151
Assert.NotNull(response);
152152
Assert.Equal("signed_transaction_info_value", response.SignedTransactionInfo);
153153
}
154+
155+
[Fact]
156+
public async Task LookUpOrderId_Success()
157+
{
158+
const string responseData = """
159+
{
160+
"status": 1,
161+
"signedTransactions": [
162+
"signed_transaction_one",
163+
"signed_transaction_two"
164+
]
165+
}
166+
""";
167+
168+
var mockHttp = new MockHttpMessageHandler();
169+
mockHttp
170+
.When($"https://local-testing-base-url/inApps/v1/lookup/W002182")
171+
.Respond("application/json", responseData);
172+
173+
AppStoreServerApiClient client = GetAppStoreServerApiClient(mockHttp);
174+
175+
OrderLookupResponse response = await client.LookUpOrderId("W002182");
176+
177+
Assert.NotNull(response);
178+
Assert.Equal(OrderLookupStatus.Invalid, response.Status);
179+
Assert.Collection(
180+
response.SignedTransactions,
181+
transaction => Assert.Equal("signed_transaction_one", transaction),
182+
transaction => Assert.Equal("signed_transaction_two", transaction)
183+
);
184+
}
154185
}

0 commit comments

Comments
 (0)