appstore-notifications-go is a Golang package designed to assist in handling, verifying, and parsing the App Store Server Notifications, which is a webhook service corresponds to Apple's App Store events related to your apps.
App Store Server Notifications is a service provided by Apple for its App Store. It's designed to notify developers about key events and changes related to their app's in-app purchases and subscriptions. By integrating this service into their server-side logic, developers can receive real-time (I think, almost real-time) updates about various events without having to repeatedly poll the Apple servers.
To install the package, you can use following command on your terminal in your project directory:
go get github.com/izniburak/appstore-notifications-go
package main
import (
"encoding/json"
"fmt"
"strings"
appstore "github.com/izniburak/appstore-notifications-go"
)
func main() {
// App Store Server Notification Request JSON String
appStoreServerRequest := "..." // {"signedPayload":"..."}
var request appstore.AppStoreServerRequest
err := json.Unmarshal([]byte(appStoreServerRequest), &request) // bind byte to header structure
if err != nil {
panic(err)
}
// Apple Root CA - G3 Root certificate
// for details: https://www.apple.com/certificateauthority/
// you need download it and covert it to a valid pem file in order to verify X5c certificates
// `openssl x509 -in AppleRootCA-G3.cer -out cert.pem`
rootCert := "-----BEGIN CERTIFICATE----- ......"
if rootCert == "" {
panic("Apple Root Cert not valid")
}
appStoreServerNotification := appstore.New(request.SignedPayload, rootCert)
fmt.Printf("App Store Server Notification is valid?: %t\n", appStoreServerNotification.IsValid)
fmt.Printf("Product Id: %s\n", appStoreServerNotification.TransactionInfo.ProductId)
}
You can access the all data in the payload by using one of the 4 params in instance of the AppStoreServerNotification
:
The MIT License (MIT) - see license.md
for more details