Mimo.AppStoreServerLibrary 0.0.3

dotnet add package Mimo.AppStoreServerLibrary --version 0.0.3                
NuGet\Install-Package Mimo.AppStoreServerLibrary -Version 0.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mimo.AppStoreServerLibrary" Version="0.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mimo.AppStoreServerLibrary --version 0.0.3                
#r "nuget: Mimo.AppStoreServerLibrary, 0.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Mimo.AppStoreServerLibrary as a Cake Addin
#addin nuget:?package=Mimo.AppStoreServerLibrary&version=0.0.3

// Install Mimo.AppStoreServerLibrary as a Cake Tool
#tool nuget:?package=Mimo.AppStoreServerLibrary&version=0.0.3                

App Store Server Library for .NET

An unofficial .NET SDK for App Store Server Notifications v2 and API

The overall library and API design is copied from the official Apple libraries and it is intended to be used in the same way. More resources:

Features

This is a list of the features that are currently implemented in the library, compared to the official Apple libraries.

Feature Apple This library
Verify and decode notifications
Verify and decode transactions
Verify and decode renewal infos
Generate API Token
Get All Subscription Statuses
Get Notification History
Get Transaction History v2
Extract Transaction Id from receipt
Get Transaction History v1
Get Transaction Info
Send Consumption Information
Look Up Order ID
Get Refund History
Extending the renewal date for auto-renewable subscriptions
Request a Test Notification

Installation

The library is available on NuGet. You can install it using the following command:

dotnet add package Mimo.AppStoreServerLibrary

Usage

Obtaining Apple Root Certificates

Download and store the root certificates found in the Apple Root Certificates section of the Apple PKI site. Provide these certificates as an array to a SignedDataVerifier to allow verifying the signed data comes from Apple.

Notification Verification

Here is an example of how to verify a notification:

var signedDataVerifier = new SignedDataVerifier(
    appleRootCertificates: rootCertificatesBytes,
    enableOnlineChecks: true,
    environment: AppStoreEnvironment.Sandbox,
    bundleId: "com.example.app"
);

try {
    var decodedPayload = await signedDataVerifier.VerifyAndDecodeNotification(signedPayload);

} catch (VerificationException ex) {
    Console.WriteLine($"Verification failed: {ex.Message}");
}

[!IMPORTANT]
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.

API

Here is an example of how to get all notification history for a specific transaction using the Pagination token :

// Create a request for notification history
NotificationHistoryRequest request = new()
{
    StartDate = DateTimeOffset.UtcNow.AddDays(-7).ToUnixTimeMilliseconds(),
    EndDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
    // Optional: filter by transaction ID
    TransactionId = "your-transaction-id"
};

// Get initial page of notifications
NotificationHistoryResponse? notifications =
    await appStoreServerClient.GetNotificationHistory(request);

if (notifications != null)
{
    // Process notifications on current page
    foreach (var notification in notifications.NotificationHistory)
    {
        Console.WriteLine($"Notification ID: {notification.SignedPayload}");
    }

    // Get additional pages if they exist
    while (notifications.HasMore)
    {
        notifications = await appStoreServerClient.GetNotificationHistory(
            request,
            notifications.PaginationToken
        );

        foreach (var notification in notifications!.NotificationHistory)
        {
            Console.WriteLine($"Notification ID: {notification.SignedPayload}");
        }
    }
}

Receipt Utility

Here is an example of how to extract the transaction id from a receipt:

string receiptData = "your-receipt-data";
ReceiptUtility utility = new();

string transactionId = utility.ExtractTransactionIdFromAppReceipt(receiptData);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.3 162 1/21/2025
0.0.2 71 1/20/2025
0.0.1 187 1/15/2025