cafebazaar_dev_api_v2

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

README

cafebaazar-dev-api-v2

Go CafeBazaar Developer API Version 2

Install:

go get -u github.com/aliforever/cafebazaar-dev-api-v2


Usage:

1) To initialise the library use:
api := cafebazaar_dev_api_v2.NewCafeBazaarAPI("clientId", "clientSecret", "clientUri")

Fill in the parameters clientId, clientSecret, clientUri, set in your api section of developer console

2) You will need a code to get access and refresh tokens, you can get the code by visiting the url:

https://pardakht.cafebazaar.ir/devapi/v2/auth/authorize/?response_type=code&access_type=offline&redirect_uri=<REDIRECT_URI>&client_id=<CLIENT_ID>

Or calling Authorize method of the API:

code, err := api.Authorize("androidpublisher")
if err != nil {
  fmt.Println(err)
  return
}
3) To get accessToken & refreshToken you should pass the code received in the second step to GetAuthorizationTokens:
token, err := api.GetAuthorizationTokens(code)
if err != nil {
  fmt.Println(err)
  return
}
// This will store the token inside the struct for future use, or you can store the tokens and manually import them

To manually import the tokens you can use SetToken:

accessToken := ""
refreshToken := ""
api.SetToken(accessToken, refreshToken)

Supported Functions:

In-app Purchase Validation
iapv, err := api.InAppPurchaseValidate("packageName", "productId", "purchaseToken")
if err != nil {
  fmt.Println(err)
  return
}
fmt.Printf("%+v", iapv)
if iapv.ConsumptionState == 0 {
  fmt.Printf("consumed")
} else {
  fmt.Printf("not consumed")
}
if iapv.PurchaseState == 0 {
  fmt.Printf("success")
} else {
  fmt.Printf("refunded")
}

TODO:

Subscription Validation
Subscription Cancellation

Pull requests are welcome for the missing functions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CafeBazaarAPI

type CafeBazaarAPI struct {
	// contains filtered or unexported fields
}

func NewCafeBazaarAPI

func NewCafeBazaarAPI(clientId, clientSecret, clientUri string) *CafeBazaarAPI

func (*CafeBazaarAPI) Authorize

func (ca *CafeBazaarAPI) Authorize(scope string) (token string, err error)

func (*CafeBazaarAPI) GetAuthorizationTokens

func (ca *CafeBazaarAPI) GetAuthorizationTokens(code string) (token *Token, err error)

func (*CafeBazaarAPI) InAppPurchaseValidate

func (ca *CafeBazaarAPI) InAppPurchaseValidate(packageName, productId, purchaseToken string) (response *InAppPurchaseValidate, err error)

func (*CafeBazaarAPI) LastToken

func (ca *CafeBazaarAPI) LastToken() (token *Token)

func (*CafeBazaarAPI) RefreshToken

func (ca *CafeBazaarAPI) RefreshToken() (err error)

func (*CafeBazaarAPI) SetToken

func (ca *CafeBazaarAPI) SetToken(accessToken, refreshToken string)

type InAppPurchaseValidate

type InAppPurchaseValidate struct {
	ConsumptionState int    `json:"consumptionState"`
	PurchaseState    int    `json:"purchaseState"`
	Kind             string `json:"kind"`
	DeveloperPayload string `json:"developerPayload"`
	PurchaseTime     int64  `json:"purchaseTime"`
	Error            string `json:"error,omitempty"`
	ErrorDescription string `json:"error_description,omitempty"`
}

type Token

type Token struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
	Error        string `json:"error,omitempty"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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