AppleReceiptVerifier.NET
0.3.0
See the version list below for details.
dotnet add package AppleReceiptVerifier.NET --version 0.3.0
NuGet\Install-Package AppleReceiptVerifier.NET -Version 0.3.0
<PackageReference Include="AppleReceiptVerifier.NET" Version="0.3.0" />
paket add AppleReceiptVerifier.NET --version 0.3.0
#r "nuget: AppleReceiptVerifier.NET, 0.3.0"
// Install AppleReceiptVerifier.NET as a Cake Addin #addin nuget:?package=AppleReceiptVerifier.NET&version=0.3.0 // Install AppleReceiptVerifier.NET as a Cake Tool #tool nuget:?package=AppleReceiptVerifier.NET&version=0.3.0
đ What is AppleReceiptVerifier.NET?
AppleReceiptVerifier.NET is a library used to verify the App Store receipts with the App Store verification service.
You can read more about receipt verification on the official documentation website.
âī¸ Which .NET versions and OS platforms are supported?
The library targets .NET Standard 2.0 and .NET 5 which makes it compatible with the following .NET implementations:
- .NET Framework 4.6.1 and above;
- .NET Core 2.0 and above;
- .NET 5;
- and others, see .NET implementation support.
The library is platform-agnostic and can run on any OS supported by the selected .NET implementation.
âšī¸ Usage
To use the library you need an iOS or MacOS application that has in-app purchases. You also need to get the app shared secret from the App Store Connect (how?). Next, you need to decide whether you want to use the library's DI integration. If not, refer to the Standalone section below. Otherwise, scroll down to the DI Integration section.
đĻ Standalone
The verifier can be used without the DI container. Simply instantiate it like this:
string receipt = "[[very long base64encoded string]]";
var verifierOptions = new AppleReceiptVerifierOptions()
{
AppSecret = "your app shared secret",
AcceptTestEnvironmentReceipts = false // don't trust test environment receipts in production!
};
var httpClient = new HttpClient();
var verifier = new AppleReceiptVerifier(verifierOptions, httpClient);
var response = await verifier.VerifyReceiptAsync(receipt, true);
if (!response.IsValid)
{
Console.WriteLine("Failed to verify the receipt: " + response.ErrorDescription);
}
else
{
Console.WriteLine("Receipt is valid");
}
âī¸ DI Integration
The library supports integration with the Microsoft.Extensions.DependencyInjection
DI implementation.
If you want to use a single verifier to verify receipts from a single app, take the following steps:
Register a verifier in your
Startup.cs
.services.AddAppleReceiptVerifier(c => { c.AppSecret = "your app shared secret"; c.AcceptTestEnvironmentReceipts = false; // don't trust test environment receipts in production! });
Inject
IAppleReceiptVerifier
in your controller or a service:public class ExampleController { readonly IAppleReceiptVerifier _verifier; public ExampleController(IAppleReceiptVerifier verifier) { _verifier = verifier; } public async Task<IActionResult> CheckReceiptAsync(string receipt) { var response = await _verifier.VerifyReceiptAsync(receipt, true); if (!response.IsValid) { return BadRequest(response.ErrorDescription); } else { return Ok(); } } }
If you want to support multiple verifiers, for multiple applications, things are a little bit more tricky:
Register multiple verifiers in your
Startup.cs
, each with a unique name:services.AddAppleReceiptVerifier(c => { c.AppSecret = "first app shared secret"; c.AcceptTestEnvironmentReceipts = true; }, "App1"); services.AddAppleReceiptVerifier(c => { c.AppSecret = "second app shared secret"; c.AcceptTestEnvironmentReceipts = true; }, "App2");
Inject
IAppleReceiptVerifierResolver
in your constructor and resolve the registered verifiers by their names:public class ExampleController { readonly IAppleReceiptVerifier _verifier1; readonly IAppleReceiptVerifier _verifier2; public ExampleController(IAppleReceiptVerifierResolver verifierResolver) { _verifier1 = verifierResolver.Resolve("App1"); _verifier2 = verifierResolver.Resolve("App2"); } public async Task<IActionResult> CheckReceiptAsync(string receipt, string appName) { var response = await (appName switch { "App1" => _verifier1.VerifyReceiptAsync(receipt, true), "App2" => _verifier2.VerifyReceiptAsync(receipt, true), _ => throw new ArgumentOutOfRangeException(nameof(appName), appName, "Invalid app name.") }); if (!response.IsValid) { return BadRequest(response.ErrorDescription); } else { return Ok(); } } }
đ¤ Advanced usage
Please refer to the official documentation to learn more about how different receipt fields can be used.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Http (>= 2.1.0)
- Microsoft.Extensions.Options (>= 2.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.0)
- System.Text.Json (>= 5.0.0)
-
net5.0
- Microsoft.Extensions.Http (>= 2.1.0)
- Microsoft.Extensions.Options (>= 2.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.1.0)
- System.Text.Json (>= 5.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AppleReceiptVerifier.NET:
Package | Downloads |
---|---|
ReceiptVerifierMiddlewareEndpoint
ReceiptVerifierMiddleware adds an endpoint to retrieve receipt info via AppleReceiptVerifier.NET |
GitHub repositories
This package is not used by any popular GitHub repositories.
* Tidied the surface API.