Skip to content

Commit

Permalink
Merge pull request #254 from kaijietti/master
Browse files Browse the repository at this point in the history
feat(playstore): add VoidedPurchaseNotification in playstore notification
  • Loading branch information
takecy authored Nov 20, 2023
2 parents cee32c6 + 2a8af1f commit 5d2e2c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
18 changes: 18 additions & 0 deletions playstore/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const (
OneTimeProductNotificationTypeCanceled
)

// https://developer.android.com/google/play/billing/rtdn-reference#voided-purchase
type VoidedPurchaseProductType int

const (
VoidedPurchaseProductTypeSubscription = iota + 1
VoidedPurchaseProductTypeOneTime
)

// DeveloperNotification is sent by a Pub/Sub topic.
// Detailed description is following.
// https://developer.android.com/google/play/billing/rtdn-reference#json_specification
Expand All @@ -36,6 +44,7 @@ type DeveloperNotification struct {
EventTimeMillis string `json:"eventTimeMillis"`
SubscriptionNotification SubscriptionNotification `json:"subscriptionNotification,omitempty"`
OneTimeProductNotification OneTimeProductNotification `json:"oneTimeProductNotification,omitempty"`
VoidedPurchaseNotification VoidedPurchaseNotification `json:"voidedPurchaseNotification,omitempty"`
TestNotification TestNotification `json:"testNotification,omitempty"`
}

Expand All @@ -57,6 +66,15 @@ type OneTimeProductNotification struct {
SKU string `json:"sku,omitempty"`
}

// VoidedPurchaseNotification has token, order and product type to locate the right purchase and order.
// To learn how to get additional information about the voided purchase, check out the Google Play Voided Purchases API,
// which is a pull model that provides additional data for voided purchases between a given timestamp.
type VoidedPurchaseNotification struct {
PurchaseToken string `json:"purchaseToken"`
OrderID string `json:"orderId"`
ProductType VoidedPurchaseProductType `json:"productType"`
}

// TestNotification is the test publish that are sent only through the Google Play Developer Console
type TestNotification struct {
Version string `json:"version"`
Expand Down
9 changes: 7 additions & 2 deletions playstore/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"reflect"
"testing"
"time"

"google.golang.org/api/androidpublisher/v3"
"google.golang.org/appengine/urlfetch"
Expand Down Expand Up @@ -195,11 +196,15 @@ func TestConsumeProduct(t *testing.T) {
func TestVoidedPurchases(t *testing.T) {
t.Parallel()
// Exception scenario
expected := "googleapi: Error 403: The current user has insufficient permissions to perform the requested operation., forbidden"
expected := "googleapi: Error 404: No application was found for the given package name., applicationNotFound"

client, _ := New(jsonKey)
ctx := context.Background()
_, err := client.VoidedPurchases(ctx, "package", 0, 0, 3, "token", 0, VoidedPurchaseTypeWithoutSubscription)

endTime := time.Now()
startTime := endTime.Add(-29 * 24 * time.Hour)

_, err := client.VoidedPurchases(ctx, "package", startTime.UnixMilli(), endTime.UnixMilli(), 3, "", 0, VoidedPurchaseTypeWithoutSubscription)

if err == nil || err.Error() != expected {
t.Errorf("got %v", err)
Expand Down

0 comments on commit 5d2e2c2

Please sign in to comment.