Skip to content

Commit

Permalink
Merge pull request #297 from aubrunet/master
Browse files Browse the repository at this point in the history
feat(playstore): Add GetSubscription
  • Loading branch information
takecy authored Oct 2, 2024
2 parents 8b3def9 + 904dcd9 commit 435550f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions playstore/mocks/playstore.go

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

12 changes: 12 additions & 0 deletions playstore/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type IABSubscriptionV2 interface {

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

Expand Down Expand Up @@ -232,6 +233,17 @@ func (c *Client) DeferSubscription(ctx context.Context, packageName string, subs
return result, err
}

// GetSubscription reads a single subscription.
func (c *Client) GetSubscription(ctx context.Context,
packageName string,
productID string,
) (*androidpublisher.Subscription, error) {
ps := androidpublisher.NewMonetizationSubscriptionsService(c.service)
result, err := ps.Get(packageName, productID).Context(ctx).Do()

return result, err
}

// GetSubscriptionOffer reads a single subscription offer.
func (c *Client) GetSubscriptionOffer(ctx context.Context,
packageName string,
Expand Down
16 changes: 16 additions & 0 deletions playstore/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ func TestDeferSubscription(t *testing.T) {
// TODO Normal scenario
}

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

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

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

// TODO Normal scenario
}

func TestGetSubscriptionOffer(t *testing.T) {
t.Parallel()
// Exception scenario
Expand Down

0 comments on commit 435550f

Please sign in to comment.