Java classes for server-side App Store receipts validation
I’m working on a bunch of apps that need to verify App Store receipts on a JVM-based server. The process is described in Apples’s Documentation Archive but lacks of any SDK / libraries (at least for JVM). So I made one to improve code reuse.
I assume Jackson is the most popular and widely used JSON library in the JVM world, so the library depends on it for field mappings.
There are no other dependencies.
The library is published to JCenter and requires only one line in your Gradle build (assuming you’re already using jcenter()
repo):
repositories {
jcenter()
}
dependencies {
implementation("by.dev.madhead.utils.appstore_receipts_validator:model:2.0.0")
}
The usage is straightforward (here I use Ktor HTTP client as an example):
suspend fun verify(receipt: String, password: String): VerifyReceiptResponse {
return client.post<VerifyReceiptResponse> {
url("https://buy.itunes.apple.com/verifyReceipt")
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
body = VerifyReceiptRequest(
receipt,
password,
true
)
}
}
Now you can count your money using a Java API (I’ve heard Java is good for that)!