Skip to content

Commit 435550f

Browse files
authored
Merge pull request #297 from aubrunet/master
feat(playstore): Add GetSubscription
2 parents 8b3def9 + 904dcd9 commit 435550f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

playstore/mocks/playstore.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playstore/validator.go

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type IABSubscriptionV2 interface {
4545

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

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

236+
// GetSubscription reads a single subscription.
237+
func (c *Client) GetSubscription(ctx context.Context,
238+
packageName string,
239+
productID string,
240+
) (*androidpublisher.Subscription, error) {
241+
ps := androidpublisher.NewMonetizationSubscriptionsService(c.service)
242+
result, err := ps.Get(packageName, productID).Context(ctx).Do()
243+
244+
return result, err
245+
}
246+
235247
// GetSubscriptionOffer reads a single subscription offer.
236248
func (c *Client) GetSubscriptionOffer(ctx context.Context,
237249
packageName string,

playstore/validator_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ func TestDeferSubscription(t *testing.T) {
277277
// TODO Normal scenario
278278
}
279279

280+
func TestGetSubscription(t *testing.T) {
281+
t.Parallel()
282+
// Exception scenario
283+
expected := "googleapi: Error 404: Package not found: package., notFound"
284+
285+
client, _ := New(jsonKey)
286+
ctx := context.Background()
287+
_, err := client.GetSubscription(ctx, "package", "productID")
288+
289+
if err == nil || err.Error() != expected {
290+
t.Errorf("got %v", err)
291+
}
292+
293+
// TODO Normal scenario
294+
}
295+
280296
func TestGetSubscriptionOffer(t *testing.T) {
281297
t.Parallel()
282298
// Exception scenario

0 commit comments

Comments
 (0)