Code Monkey home page Code Monkey logo

appstore-notifications-go's Introduction

App Store Server Notifications in Golang PkgGoDev

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.

Install

To install the package, you can use following command on your terminal in your project directory:

go get github.com/izniburak/appstore-notifications-go

Examples

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:

  • instance.Payload: Access the Payload.
  • instance.TransactionInfo: Access the Transaction Info.
  • instance.RenewalInfo: Access the Renewal Info.
  • instance.IsValid: Check the payload parsed and verified successfully.

Contributing

  1. Fork this repo
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • izniburak İzni Burak Demirtaş - creator, maintainer

License

The MIT License (MIT) - see license.md for more details

appstore-notifications-go's People

Contributors

izniburak avatar hunter-ji avatar laredoer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.