PTGUgoogle

package
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 9 Imported by: 0

README

PTGU Google

Import

import (
	PTGUgoogle "github.com/parinyapt/golang_utils/google/v1"
)

Example

Generate Access Token
google := PTGUgoogle.NewGoogle(&PTGUgoogle.GoogleConfig{
  GenerateAccessToken: PTGUgoogle.GoogleConfigGenerateAccessToken{
    ClientEmail:  "xxx@xxx.iam.gserviceaccount.com",
    PrivateKeyID: "xxxxxx",
    PrivateKey:   "-----BEGIN PRIVATE KEY-----\nXXXXXXXXXXXXXXXXXXXXXXX\n-----END PRIVATE KEY-----\n",
    Scopes: []string{
      "https://www.googleapis.com/xxxxx",
    },
  },
})
token, err := google.GenerateGoolgeAccessTokenWithoutOAuth(context.Background())
if err != nil {
  panic(err)
}
fmt.Println(token)

Documentations:

Verify Google Play Product Purchase
  • Don't forget to add scope https://www.googleapis.com/auth/androidpublisher in Scopes when generate access token
googleToken := PTGUgoogle.NewGoogle(&PTGUgoogle.GoogleConfig{
  AccessToken: token,
})
response, err := googleToken.ValidateGoogleProductPurchase(PTGUgoogle.GooglePurchaseValidateParam{
  PackageName:   "com.xxx.xxx",
  ProductID:     "prinpt_1",
  PurchaseToken: "XXXXXX",
})
if err != nil {
  panic(err)
}
fmt.Println(response.OrderID)
fmt.Println(response.PurchaseTimeMillis)

Documentations:

Reference:

Documentation

Index

Constants

View Source
const (
	GoogleProductPurchaseURL = "" /* 132-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func NewGoogle

func NewGoogle(inputConfig *GoogleConfig) *googleReceiverArgument

Types

type GoogleConfig

type GoogleConfig struct {
	GenerateAccessToken GoogleConfigGenerateAccessToken
	AccessToken         string
}

type GoogleConfigGenerateAccessToken

type GoogleConfigGenerateAccessToken struct {
	// Client Email from service account json file
	ClientEmail string

	// Private Key ID from service account json file
	PrivateKeyID string

	// Private Key from service account json file
	// PrivateKey contains the contents of an RSA private key or the
	// contents of a PEM file that contains a private key. The provided
	// private key is used to sign JWT payloads.
	// PEM containers with a passphrase are not supported.
	// Use the following command to convert a PKCS 12 file into a PEM.
	//
	//    $ openssl pkcs12 -in key.p12 -out key.pem -nodes
	//
	PrivateKey string

	// Scopes optionally specifies a list of requested permission scopes.
	Scopes []string
}

type GoogleProductPurchaseResponse

type GoogleProductPurchaseResponse struct {
	OrderID            string `json:"orderId"`
	PurchaseTimeMillis string `json:"purchaseTimeMillis"`
	DeveloperPayload   string `json:"developerPayload"`

	// Ex. androidpublisher#productPurchase
	Kind string `json:"kind"`

	/* Purchase State
	0 - Purchased
	1 - Canceled
	2 - Pending
	*/
	PurchaseState int `json:"purchaseState"`

	/* Consumption State
	0 - Yet to be consumed
	1 - Consumed
	*/
	ConsumptionState int `json:"consumptionState"`

	/* Purchase Type
	0 - Test (i.e. purchased from a license testing account)
	1 - Promo (i.e. purchased using a promo code)
	2 - Rewarded (i.e. from watching a video ad instead of paying)
	*/
	PurchaseType int `json:"purchaseType"`

	/* Acknowledgement State
	0 - Yet to be acknowledged
	1 - Acknowledged
	*/
	AcknowledgementState int `json:"acknowledgementState"`

	// Region Code - ISO 3166-1 alpha-2 billing region code of the user at the time the product was granted.
	RegionCode string `json:"regionCode"`

	// Quantity - If not present, the quantity is 1.
	Quantity int `json:"quantity"`
}

type GooglePurchaseValidateParam

type GooglePurchaseValidateParam struct {
	PackageName   string
	ProductID     string
	PurchaseToken string
}

type GooglePurchaseValidateResponseError

type GooglePurchaseValidateResponseError struct {
	Error struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Status  string `json:"status"`
	} `json:"error"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL