PTGUgoogle

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 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)
Verify Google Play Subscription 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.ValidateGoogleSubscriptionsPurchase(PTGUgoogle.GoogleSubscriptionsPurchaseValidateParam{
  PackageName:   "com.xxx.xxx",
  PurchaseToken: "XXXXXX",
})
if err != nil {
  panic(err)
}
fmt.Println(response.subscriptionState)
fmt.Println(response.latestOrderId)

if response.LinkedPurchaseToken != nil {
  fmt.Println(PTGUdata.PointerToStringValue(response.LinkedPurchaseToken))
}else{
  fmt.Println("Response LinkedPurchaseToken is nil")
}

Documentations:

Reference:

Documentation

Index

Constants

View Source
const (
	GoogleProductPurchaseURL = "" /* 132-byte string literal not displayed */
)
View Source
const (
	GoogleSubscriptionsPurchaseV2URL = "" /* 127-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"`
}

type GoogleSubscriptionsPurchaseResponse added in v1.0.14

type GoogleSubscriptionsPurchaseResponse struct {
	Kind string `json:"kind"`

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

	// Time at which the subscription was granted. Not set for pending subscriptions (subscription was created but awaiting payment during signup).
	// Timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
	StartTime time.Time `json:"startTime"`

	/*
		Subscription State
		- SUBSCRIPTION_STATE_UNSPECIFIED
		- SUBSCRIPTION_STATE_PENDING
		- SUBSCRIPTION_STATE_ACTIVE
		- SUBSCRIPTION_STATE_PAUSED
		- SUBSCRIPTION_STATE_IN_GRACE_PERIOD
		- SUBSCRIPTION_STATE_ON_HOLD
		- SUBSCRIPTION_STATE_CANCELED
		- SUBSCRIPTION_STATE_EXPIRED
	*/
	SubscriptionState    string  `json:"subscriptionState"`
	LatestOrderID        string  `json:"latestOrderId"`
	AcknowledgementState string  `json:"acknowledgementState"`
	LinkedPurchaseToken  *string `json:"linkedPurchaseToken"`

	LineItems []SubscriptionPurchaseLineItem `json:"lineItems"`

	// Additional context around paused subscriptions. Only present if the subscription currently has subscriptionState SUBSCRIPTION_STATE_PAUSED.
	PausedStateContext   *SubscriptionPausedStateContext   `json:"pausedStateContext"`
	CanceledStateContext *SubscriptionCanceledStateContext `json:"canceledStateContext"`
}

type GoogleSubscriptionsPurchaseValidateParam added in v1.0.14

type GoogleSubscriptionsPurchaseValidateParam struct {
	PackageName   string
	PurchaseToken string
}

type SubscriptionCanceledStateContext added in v1.0.14

type SubscriptionCanceledStateContext struct {
	UserInitiatedCancellation *SubscriptionUserInitiatedCancellation `json:"userInitiatedCancellation"`
}

type SubscriptionPausedStateContext added in v1.0.14

type SubscriptionPausedStateContext struct {
	AutoResumeTime *time.Time `json:"autoResumeTime"`
}

type SubscriptionPurchaseLineItem added in v1.0.14

type SubscriptionPurchaseLineItem struct {
	ProductId        string                                        `json:"productId"`
	ExpiryTime       time.Time                                     `json:"expiryTime"`
	AutoRenewingPlan *SubscriptionPurchaseLineItemAutoRenewingPlan `json:"autoRenewingPlan"`
	PrepaidPlan      *SubscriptionPurchaseLineItemPrepaidPlan      `json:"prepaidPlan"`
	OfferDetails     *SubscriptionPurchaseLineItemOfferDetails     `json:"offerDetails"`
}

type SubscriptionPurchaseLineItemAutoRenewingPlan added in v1.0.14

type SubscriptionPurchaseLineItemAutoRenewingPlan struct {
	AutoRenewEnabled *bool `json:"autoRenewEnabled"`
}

type SubscriptionPurchaseLineItemOfferDetails added in v1.0.14

type SubscriptionPurchaseLineItemOfferDetails struct {
	OfferTags  *[]string `json:"offerTags"`
	BasePlanId *string   `json:"basePlanId"`
	OfferID    *string   `json:"offerId"`
}

type SubscriptionPurchaseLineItemPrepaidPlan added in v1.0.14

type SubscriptionPurchaseLineItemPrepaidPlan struct {
	AllowExtendAfterTime *time.Time `json:"allowExtendAfterTime"`
}

type SubscriptionUserInitiatedCancellation added in v1.0.14

type SubscriptionUserInitiatedCancellation struct {
	CancelSurveyResult *SubscriptionUserInitiatedCancellationCancelSurveyResult `json:"cancelSurveyResult"`
	CancelTime         *time.Time                                               `json:"cancelTime"`
}

type SubscriptionUserInitiatedCancellationCancelSurveyResult added in v1.0.14

type SubscriptionUserInitiatedCancellationCancelSurveyResult struct {
	/* Cancellation Reason
	- CANCEL_SURVEY_REASON_UNSPECIFIED
	- CANCEL_SURVEY_REASON_NOT_ENOUGH_USAGE
	- CANCEL_SURVEY_REASON_TECHNICAL_ISSUES
	- CANCEL_SURVEY_REASON_COST_RELATED
	- CANCEL_SURVEY_REASON_FOUND_BETTER_APP
	- CANCEL_SURVEY_REASON_OTHERS
	*/
	Reason *string `json:"reason"`

	// Only set for CANCEL_SURVEY_REASON_OTHERS. This is the user's freeform response to the survey.
	ReasonUserInput *string `json:"reasonUserInput"`
}

Jump to

Keyboard shortcuts

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