Skip to content

Commit

Permalink
Merge pull request #236 from dbican-gpsw/master
Browse files Browse the repository at this point in the history
Add GetSubscriptionOffer method to IABMonetization for `monetization.subscriptions` API
  • Loading branch information
richzw authored Sep 6, 2023
2 parents 110cbf1 + 1380c5b commit ffc1b76
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
40 changes: 39 additions & 1 deletion playstore/mocks/playstore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion playstore/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
androidpublisher "google.golang.org/api/androidpublisher/v3"
)

//go:generate mockgen -destination=mocks/playstore.go -package=mocks github.com/awa/go-iap/playstore IABProduct,IABSubscription
//go:generate mockgen -destination=mocks/playstore.go -package=mocks github.com/awa/go-iap/playstore IABProduct,IABSubscription,IABMonetization

// The IABProduct type is an interface for product service
type IABProduct interface {
Expand All @@ -36,6 +36,11 @@ type IABSubscription interface {
RevokeSubscription(context.Context, string, string, string) error
}

// The IABMonetization type is an interface for monetization service
type IABMonetization interface {
GetSubscriptionOffer(context.Context, string, string, string, string) (*androidpublisher.SubscriptionOffer, error)
}

// The Client type implements VerifySubscription method
type Client struct {
service *androidpublisher.Service
Expand Down Expand Up @@ -196,6 +201,19 @@ func (c *Client) RevokeSubscription(ctx context.Context, packageName string, sub
return err
}

// GetSubscriptionOffer reads a single subscription offer.
func (c *Client) GetSubscriptionOffer(ctx context.Context,
packageName string,
productID string,
basePlanID string,
offerID string,
) (*androidpublisher.SubscriptionOffer, error) {
ps := androidpublisher.NewMonetizationSubscriptionsBasePlansOffersService(c.service)
result, err := ps.Get(packageName, productID, basePlanID, offerID).Context(ctx).Do()

return result, err
}

type VoidedPurchaseType int64

const (
Expand Down
16 changes: 16 additions & 0 deletions playstore/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,22 @@ func TestRevokeSubscription(t *testing.T) {
// TODO Normal scenario
}

func TestGetSubscriptionOffer(t *testing.T) {
t.Parallel()
// Exception scenario
expected := "googleapi: Error 404: Package not found: package., notFound"

client, _ := New(jsonKey)
ctx := context.Background()
_, err := client.GetSubscriptionOffer(ctx, "package", "productID", "basePlanID", "offerID")

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

// TODO Normal scenario
}

func TestVerifySignature(t *testing.T) {
t.Parallel()
receipt := []byte(`{"orderId":"GPA.xxxx-xxxx-xxxx-xxxxx","packageName":"my.package","productId":"myproduct","purchaseTime":1437564796303,"purchaseState":0,"developerPayload":"user001","purchaseToken":"some-token"}`)
Expand Down

0 comments on commit ffc1b76

Please sign in to comment.