Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(playstore): Add GetSubscription #297

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading