A
A
Anton2021-08-30 03:54:04
go
Anton, 2021-08-30 03:54:04

How are purchases validated?

There is a repository https://github.com/panuwattoa/in-app-purchase/

There is a func NewValidate() function in the validate.go file that requires sg Storage.
How to correctly describe / implement this Storage so that it can be transferred there? Can someone post an example?

type Storage interface {
  StorePurchases(ctx context.Context, sp []*Purchase) ([]*Purchase, error)
  StoreSubscriptionPurchases(ctx context.Context, sp []*SubscriptionPurchase) ([]*SubscriptionPurchase, error)
}

func NewValidate(sg Storage, applePassword string, gc IAPGoogleConfig) *Validate {
  return &Validate{
    Storage:       sg,
    ApplePassword: applePassword,
    GoogleConfig:  gc,
  }
}


with applePassword and IAPGoogleConfig it's clear

googleConfig := validate.IAPGoogleConfig{
    ClientEmail: "[email protected]",
    PrivateKey:  "123456789abcdefg",
  }

NewValidate(STORAGE,  "",  googleConfig)


what should STORAGE look like?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2021-09-06
@TequilaOne

Judging by the methods of the Storage interface, it is necessary for this library to be able to save subscription / payment data to your database.
You can start by making an empty implementation, see what parameters you will receive / what you will need, and there you will already figure out how it is more convenient for you to save the data.
Let's say you store data in MySQL... then the implementation might look like this

type MySQLStorage struct {
    db *sql.DB
}

func NewMySQLStorage(db *sql.DB) *MySQLStorage {
    return &MySQLStorage{
        db: db,
    }
}

func (sg *MySQLStorage) StorePurchases(ctx context.Context, sp []*Purchase) ([]*Purchase, error) {
    for _, p := range sp {
        fmt.Printf("%+v\n", p)
    }

    return sp, nil
}

func (sg *MySQLStorage) StoreSubscriptionPurchases(ctx context.Context, sp []*SubscriptionPurchase) ([]*SubscriptionPurchase, error) {
    for _, p := range sp {
        fmt.Printf("%+v\n", p)
    }

    return sp, nil
}

those. challenge could be like this
db := connectToDB...
sg := NewMySQLStorage(db)
NewValidate(sg  "",  googleConfig)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question