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 ConvertRegionPrices #302

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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/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 {
ConvertRegionPrices(ctx context.Context, packageName string, price *androidpublisher.Money) (*androidpublisher.ConvertRegionPricesResponse, error)
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 @@ -233,6 +234,20 @@ func (c *Client) DeferSubscription(ctx context.Context, packageName string, subs
return result, err
}

// ConvertRegionPrices
func (c *Client) ConvertRegionPrices(ctx context.Context,
packageName string,
price *androidpublisher.Money,
) (*androidpublisher.ConvertRegionPricesResponse, error) {
ps := androidpublisher.NewMonetizationService(c.service)
convertRegionPricesRequest := &androidpublisher.ConvertRegionPricesRequest{
Price: price,
}
result, err := ps.ConvertRegionPrices(packageName, convertRegionPricesRequest).Context(ctx).Do()

return result, err
}

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

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

client, _ := New(jsonKey)
ctx := context.Background()
price := &androidpublisher.Money{
CurrencyCode: "USD",
Nanos: 1 * 1000,
Units: 1,
ForceSendFields: nil,
NullFields: nil,
}
_, err := client.ConvertRegionPrices(ctx, "package", price)

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

// TODO Normal scenario
}

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