forked from Mirrors/go-iap
Added acknowledge method for subscription
This commit is contained in:
@@ -16,10 +16,15 @@ import (
|
||||
androidpublisher "google.golang.org/api/androidpublisher/v3"
|
||||
)
|
||||
|
||||
// The IABClient type is an interface to verify purchase token
|
||||
type IABClient interface {
|
||||
VerifySubscription(context.Context, string, string, string) (*androidpublisher.SubscriptionPurchase, error)
|
||||
// The IABProduct type is an interface for product service
|
||||
type IABProduct interface {
|
||||
VerifyProduct(context.Context, string, string, string) (*androidpublisher.ProductPurchase, error)
|
||||
}
|
||||
|
||||
// The IABSubscription type is an interface for subscription service
|
||||
type IABSubscription interface {
|
||||
AcknowledgeSubscription(context.Context, string, string, string, *androidpublisher.SubscriptionPurchasesAcknowledgeRequest) error
|
||||
VerifySubscription(context.Context, string, string, string) (*androidpublisher.SubscriptionPurchase, error)
|
||||
CancelSubscription(context.Context, string, string, string) error
|
||||
RefundSubscription(context.Context, string, string, string) error
|
||||
RevokeSubscription(context.Context, string, string, string) error
|
||||
@@ -53,6 +58,25 @@ func NewWithClient(jsonKey []byte, cli *http.Client) (*Client, error) {
|
||||
return &Client{conf.Client(ctx)}, err
|
||||
}
|
||||
|
||||
// AcknowledgeSubscription acknowledges a subscription purchase.
|
||||
func (c *Client) AcknowledgeSubscription(
|
||||
ctx context.Context,
|
||||
packageName string,
|
||||
subscriptionID string,
|
||||
token string,
|
||||
req *androidpublisher.SubscriptionPurchasesAcknowledgeRequest,
|
||||
) error {
|
||||
service, err := androidpublisher.New(c.httpCli)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ps := androidpublisher.NewPurchasesSubscriptionsService(service)
|
||||
err = ps.Acknowledge(packageName, subscriptionID, token, req).Context(ctx).Do()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// VerifySubscription verifies subscription status
|
||||
func (c *Client) VerifySubscription(
|
||||
ctx context.Context,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
androidpublisher "google.golang.org/api/androidpublisher/v3"
|
||||
"google.golang.org/appengine/urlfetch"
|
||||
)
|
||||
|
||||
@@ -70,6 +71,25 @@ func TestNewWithClient(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcknowledgeSubscription(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Exception scenario
|
||||
expected := "googleapi: Error 404: No application was found for the given package name., applicationNotFound"
|
||||
|
||||
client, _ := New(jsonKey)
|
||||
ctx := context.Background()
|
||||
req := &androidpublisher.SubscriptionPurchasesAcknowledgeRequest{
|
||||
DeveloperPayload: "user001",
|
||||
}
|
||||
err := client.AcknowledgeSubscription(ctx, "package", "subscriptionID", "purchaseToken", req)
|
||||
|
||||
if err.Error() != expected {
|
||||
t.Errorf("got %v\nwant %v", err, expected)
|
||||
}
|
||||
|
||||
// TODO Normal scenario
|
||||
}
|
||||
|
||||
func TestVerifySubscription(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Exception scenario
|
||||
|
||||
Reference in New Issue
Block a user