MCPcopy Index your code
hub / github.com/awa/go-iap

github.com/awa/go-iap @v1.52.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.52.0 ↗ · + Follow
482 symbols 891 edges 32 files 303 documented · 63% updated todayv1.53.1 · 2026-07-07★ 1,04935 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-iap

unit test

go-iap verifies the purchase receipt via AppStore, GooglePlayStore, Amazon AppStore, HMS or MicrosoftStore.

Current API Documents:

  • AppStore: GoDoc
  • AppStore Server API: GoDoc
  • GooglePlay: GoDoc
  • Amazon AppStore: GoDoc
  • Huawei HMS: GoDoc
  • Microsoft Store: GoDoc

Installation

go get github.com/awa/go-iap/appstore
go get github.com/awa/go-iap/playstore
go get github.com/awa/go-iap/amazon
go get github.com/awa/go-iap/hms
go get github.com/awa/go-iap/microsoftstore

Quick Start

In App Purchase (via App Store)

import(
    "github.com/awa/go-iap/appstore"
)

func main() {
    client := appstore.New()
    req := appstore.IAPRequest{
        ReceiptData: "your receipt data encoded by base64",
    }
    resp := &appstore.IAPResponse{}
    ctx := context.Background()
    err := client.Verify(ctx, req, resp)
}

Note: The verifyReceipt API has been deprecated as of 5 Jun 2023. Please use App Store Server API instead.

In App Billing (via GooglePlay)

import(
    "github.com/awa/go-iap/playstore"
)

func main() {
    // You need to prepare a public key for your Android app's in app billing
    // at https://console.developers.google.com.
    jsonKey, err := ioutil.ReadFile("jsonKey.json")
    if err != nil {
        log.Fatal(err)
    }

    client := playstore.New(jsonKey)
    ctx := context.Background()
    resp, err := client.VerifySubscription(ctx, "package", "subscriptionID", "purchaseToken")
}

In App Purchase (via Amazon App Store)

import(
    "github.com/awa/go-iap/amazon"
)

func main() {
    client := amazon.New("developerSecret")

    ctx := context.Background()
    resp, err := client.Verify(ctx, "userID", "receiptID")
}

In App Purchase (via Huawei Mobile Services)

import(
    "github.com/awa/go-iap/hms"
)

func main() {
    // If "orderSiteURL" and/or "subscriptionSiteURL" are empty,
    // they will be default to AppTouch German.
    // Please refer to https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5/api-common-statement-0000001050986127-V5 for details.
    client := hms.New("clientID", "clientSecret", "orderSiteURL", "subscriptionSiteURL")
    ctx := context.Background()
    resp, err := client.VerifySubscription(ctx, "purchaseToken", "subscriptionID", 1)
}

In App Store Server API

Note - The App Store Server API differentiates between a sandbox and a production environment based on the base URL:
- Use https://api.storekit.itunes.apple.com/ for the production environment. - Use https://api.storekit-sandbox.itunes.apple.com/ for the sandbox environment. - If you're unsure about the environment, follow these steps: - Initiate a call to the endpoint using the production URL. If the call is successful, the transaction identifier is associated with the production environment. - If you encounter an error code 4040010, indicating a TransactionIdNotFoundError, make a call to the endpoint using the sandbox URL. - If this call is successful, the transaction identifier is associated with the sandbox environment. If the call fails with the same error code, the transaction identifier doesn't exist in either environment.

  • GetTransactionInfo
import(
    "github.com/awa/go-iap/appstore/api"
)

//  For generate key file and download it, please refer to https://developer.apple.com/documentation/appstoreserverapi/creating_api_keys_to_use_with_the_app_store_server_api
const ACCOUNTPRIVATEKEY = `
    -----BEGIN PRIVATE KEY-----
    FAKEACCOUNTKEYBASE64FORMAT
    -----END PRIVATE KEY-----
    `
func main() {
    c := &api.StoreConfig{
        KeyContent: []byte(ACCOUNTPRIVATEKEY),  // Loads a .p8 certificate
        KeyID:      "FAKEKEYID",                // Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
        BundleID:   "fake.bundle.id",           // Your app’s bundle ID
        Issuer:     "xxxxx-xx-xx-xx-xxxxxxxxxx",// Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a")
        Sandbox:    false,                      // default is Production
    }
    transactionId := "FAKETRANSACTIONID"
    a := api.NewStoreClient(c)
    ctx := context.Background()
    response, err := a.GetTransactionInfo(ctx, transactionId)

    transaction, err := a.ParseSignedTransaction(response.SignedTransactionInfo)
    if err != nil {
        // error handling
    }

    if transaction.TransactionID == transactionId {
        // the transaction is valid
    }
}
  • GetTransactionHistory
import(
    "github.com/awa/go-iap/appstore/api"
)

//  For generate key file and download it, please refer to https://developer.apple.com/documentation/appstoreserverapi/creating_api_keys_to_use_with_the_app_store_server_api
const ACCOUNTPRIVATEKEY = `
    -----BEGIN PRIVATE KEY-----
    FAKEACCOUNTKEYBASE64FORMAT
    -----END PRIVATE KEY-----
    `
func main() {
    c := &api.StoreConfig{
        KeyContent: []byte(ACCOUNTPRIVATEKEY),  // Loads a .p8 certificate
        KeyID:      "FAKEKEYID",                // Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
        BundleID:   "fake.bundle.id",           // Your app’s bundle ID
        Issuer:     "xxxxx-xx-xx-xx-xxxxxxxxxx",// Your issuer ID from App Store Connect (Users and Access > Integrations > In-App Purchase)(Ex: "57246542-96fe-1a63-e053-0824d011072a")
        Sandbox:    false,                      // default is Production
    }
    originalTransactionId := "FAKETRANSACTIONID"
    a := api.NewStoreClient(c)
    query := &url.Values{}
    query.Set("productType", "AUTO_RENEWABLE")
    query.Set("productType", "NON_CONSUMABLE")
    ctx := context.Background()
    responses, err := a.GetTransactionHistory(ctx, originalTransactionId, query)

    for _, response := range responses {
        transactions, err := a.ParseSignedTransactions(response.SignedTransactions)
    }
}

Parse Notification from App Store

import (
    "github.com/awa/go-iap/appstore"
    "github.com/golang-jwt/jwt/v5"
)

func main() {
    tokenStr := "SignedRenewalInfo Encode String" // or SignedTransactionInfo string
    token := jwt.Token{}
    client := appstore.New()
    err := client.ParseNotificationV2(tokenStr, &token)

    claims, ok := token.Claims.(jwt.MapClaims)
    for key, val := range claims {
        fmt.Printf("Key: %v, value: %v\n", key, val) // key value of SignedRenewalInfo
    }
}

ToDo

  • [x] Validator for In App Purchase Receipt (AppStore)
  • [x] Validator for Subscription token (GooglePlay)
  • [x] Validator for Purchase Product token (GooglePlay)
  • [ ] More Tests

Support

In App Purchase

This validator supports the receipt type for iOS7 or above.

In App Billing

This validator uses Version 3 API.

In App Purchase (Amazon)

This validator uses RVS for IAP v2.0.

In App Purchase (HMS)

This validator uses Version 2 API.

In App Store Server API

This validator uses Version 1.0+

In App Purchase (Microsoft Store)

This validator uses Version 1.0

License

go-iap is licensed under the MIT.

Extension points exported contracts — how you extend this code

IAPAPIClient (Interface)
IAPAPIClient is an interface to call validation API in App Store Server API [6 implementers]
appstore/api/validator.go
IAPClient (Interface)
IAPClient is an interface to call validation API in Microsoft Store [3 implementers]
microsoftstore/validator.go
IAPClient (Interface)
IAPClient is an interface to call validation API in Amazon App Store [3 implementers]
amazon/validator.go
IAPClient (Interface)
IAPClient is an interface to call validation API in App Store [3 implementers]
appstore/validator.go
IABProduct (Interface)
go:generate mockgen -destination=mocks/playstore.go -package=mocks github.com/awa/go-iap/playstore IABProduct,IABSubscr [3 …
playstore/validator.go
StoreAPIClient (Interface)
(no doc) [3 implementers]
appstore/api/store.go
IABProductV2 (Interface)
The IABProductV2 type is an interface for productV2 service [3 implementers]
playstore/validator.go
SubscriptionExtender (Interface)
(no doc) [3 implementers]
appstore/api/store.go

Core symbols most depended-on inside this repo

newError
called by 59
appstore/api/error.go
Do
called by 27
appstore/api/store.go
Error
called by 23
appstore/api/error.go
New
called by 17
playstore/validator.go
Do
called by 16
appstore/api/store.go
Verify
called by 11
appstore/validator.go
New
called by 9
appstore/validator.go
modifySubscriptionQuery
called by 5
hms/modifier.go

Shape

Method 223
Struct 125
Function 74
TypeAlias 43
Interface 17

Languages

Go100%

Modules by API surface

appstore/api/model.go60 symbols
appstore/api/store.go56 symbols
playstore/mocks/playstore.go48 symbols
appstore/mocks/store.go44 symbols
playstore/validator.go42 symbols
playstore/validator_test.go21 symbols
appstore/notification_v2.go21 symbols
appstore/model.go20 symbols
appstore/validator_test.go16 symbols
appstore/validator.go15 symbols
appstore/mocks/appstore.go12 symbols
appstore/api/error.go12 symbols

For agents

$ claude mcp add go-iap \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact