Skip to content

Commit f2d7270

Browse files
authored
Merge pull request #198 from richzw/master
feat(playstore): add voidedpurchases.list api
2 parents b7c21ca + 88fc6a8 commit f2d7270

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

playstore/validator.go

+35
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,41 @@ func (c *Client) RevokeSubscription(ctx context.Context, packageName string, sub
196196
return err
197197
}
198198

199+
type VoidedPurchaseType int64
200+
201+
const (
202+
VoidedPurchaseTypeWithoutSubscription VoidedPurchaseType = 0
203+
VoidedPurchaseTypeWithSubscription VoidedPurchaseType = 1
204+
)
205+
206+
// VoidedPurchases list of orders that are associated with purchases that a user has voided
207+
// Quotas:
208+
// 1. 6000 queries per day. (The day begins and ends at midnight Pacific Time.)
209+
// 2. 30 queries during any 30-second period.
210+
func (c *Client) VoidedPurchases(
211+
ctx context.Context,
212+
packageName string,
213+
startTime int64,
214+
endTime int64,
215+
maxResult int64,
216+
token string,
217+
startIndex int64,
218+
productType VoidedPurchaseType,
219+
) (*androidpublisher.VoidedPurchasesListResponse, error) {
220+
ps := androidpublisher.NewPurchasesVoidedpurchasesService(c.service)
221+
222+
call := ps.List(packageName).StartTime(startTime).EndTime(endTime).Type(int64(productType)).MaxResults(maxResult).Context(ctx)
223+
if token == "" && startIndex == 0 {
224+
return call.Do()
225+
} else if token != "" && startIndex == 0 {
226+
return call.Token(token).Do()
227+
} else if token != "" && startIndex != 0 {
228+
return call.StartIndex(startIndex).Token(token).Do()
229+
} else {
230+
return call.StartIndex(startIndex).Do()
231+
}
232+
}
233+
199234
// VerifySignature verifies in app billing signature.
200235
// You need to prepare a public key for your Android app's in app billing
201236
// at https://play.google.com/apps/publish/

playstore/validator_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ func TestConsumeProduct(t *testing.T) {
192192
// TODO Normal scenario
193193
}
194194

195+
func TestVoidedPurchases(t *testing.T) {
196+
t.Parallel()
197+
// Exception scenario
198+
expected := "googleapi: Error 403: The current user has insufficient permissions to perform the requested operation., forbidden"
199+
200+
client, _ := New(jsonKey)
201+
ctx := context.Background()
202+
_, err := client.VoidedPurchases(ctx, "package", 0, 0, 3, "token", 0, VoidedPurchaseTypeWithoutSubscription)
203+
204+
if err == nil || err.Error() != expected {
205+
t.Errorf("got %v", err)
206+
}
207+
208+
// TODO Normal scenario
209+
}
210+
195211
func TestCancelSubscription(t *testing.T) {
196212
t.Parallel()
197213
ctx := context.Background()

0 commit comments

Comments
 (0)