mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Move pp client from pp repository to any-sync
This commit is contained in:
parent
84adb5f6fd
commit
82c5df80cf
6 changed files with 2268 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -27,7 +27,7 @@ proto:
|
||||||
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. consensus/consensusproto/protos/*.proto
|
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. consensus/consensusproto/protos/*.proto
|
||||||
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. identityrepo/identityrepoproto/protos/*.proto
|
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. identityrepo/identityrepoproto/protos/*.proto
|
||||||
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. nameservice/nameserviceproto/protos/*.proto
|
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. nameservice/nameserviceproto/protos/*.proto
|
||||||
|
protoc --gogofaster_out=:. --go-drpc_out=protolib=github.com/gogo/protobuf:. paymentservice/paymentserviceproto/protos/*.proto
|
||||||
|
|
||||||
deps:
|
deps:
|
||||||
go mod download
|
go mod download
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: paymentservice/paymentserviceclient/paymentserviceclient.go
|
||||||
|
//
|
||||||
|
// Generated by this command:
|
||||||
|
//
|
||||||
|
// mockgen -source paymentservice/paymentserviceclient/paymentserviceclient.go
|
||||||
|
//
|
||||||
|
// Package mock_paymentserviceclient is a generated GoMock package.
|
||||||
|
package mock_paymentserviceclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
app "github.com/anyproto/any-sync/app"
|
||||||
|
paymentserviceproto "github.com/anyproto/any-sync/paymentservice/paymentserviceproto"
|
||||||
|
gomock "go.uber.org/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockAnyPpClientService is a mock of AnyPpClientService interface.
|
||||||
|
type MockAnyPpClientService struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockAnyPpClientServiceMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockAnyPpClientServiceMockRecorder is the mock recorder for MockAnyPpClientService.
|
||||||
|
type MockAnyPpClientServiceMockRecorder struct {
|
||||||
|
mock *MockAnyPpClientService
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockAnyPpClientService creates a new mock instance.
|
||||||
|
func NewMockAnyPpClientService(ctrl *gomock.Controller) *MockAnyPpClientService {
|
||||||
|
mock := &MockAnyPpClientService{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockAnyPpClientServiceMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockAnyPpClientService) EXPECT() *MockAnyPpClientServiceMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuySubscription mocks base method.
|
||||||
|
func (m *MockAnyPpClientService) BuySubscription(ctx context.Context, in *paymentserviceproto.BuySubscriptionRequestSigned) (*paymentserviceproto.BuySubscriptionResponse, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "BuySubscription", ctx, in)
|
||||||
|
ret0, _ := ret[0].(*paymentserviceproto.BuySubscriptionResponse)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuySubscription indicates an expected call of BuySubscription.
|
||||||
|
func (mr *MockAnyPpClientServiceMockRecorder) BuySubscription(ctx, in any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BuySubscription", reflect.TypeOf((*MockAnyPpClientService)(nil).BuySubscription), ctx, in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close mocks base method.
|
||||||
|
func (m *MockAnyPpClientService) Close(ctx context.Context) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Close", ctx)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close indicates an expected call of Close.
|
||||||
|
func (mr *MockAnyPpClientServiceMockRecorder) Close(ctx any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockAnyPpClientService)(nil).Close), ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubscriptionStatus mocks base method.
|
||||||
|
func (m *MockAnyPpClientService) GetSubscriptionStatus(ctx context.Context, in *paymentserviceproto.GetSubscriptionRequestSigned) (*paymentserviceproto.GetSubscriptionResponse, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "GetSubscriptionStatus", ctx, in)
|
||||||
|
ret0, _ := ret[0].(*paymentserviceproto.GetSubscriptionResponse)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubscriptionStatus indicates an expected call of GetSubscriptionStatus.
|
||||||
|
func (mr *MockAnyPpClientServiceMockRecorder) GetSubscriptionStatus(ctx, in any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubscriptionStatus", reflect.TypeOf((*MockAnyPpClientService)(nil).GetSubscriptionStatus), ctx, in)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init mocks base method.
|
||||||
|
func (m *MockAnyPpClientService) Init(a *app.App) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Init", a)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init indicates an expected call of Init.
|
||||||
|
func (mr *MockAnyPpClientServiceMockRecorder) Init(a any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockAnyPpClientService)(nil).Init), a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name mocks base method.
|
||||||
|
func (m *MockAnyPpClientService) Name() string {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Name")
|
||||||
|
ret0, _ := ret[0].(string)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name indicates an expected call of Name.
|
||||||
|
func (mr *MockAnyPpClientServiceMockRecorder) Name() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockAnyPpClientService)(nil).Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run mocks base method.
|
||||||
|
func (m *MockAnyPpClientService) Run(ctx context.Context) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "Run", ctx)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run indicates an expected call of Run.
|
||||||
|
func (mr *MockAnyPpClientServiceMockRecorder) Run(ctx any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockAnyPpClientService)(nil).Run), ctx)
|
||||||
|
}
|
97
paymentservice/paymentserviceclient/paymentserviceclient.go
Normal file
97
paymentservice/paymentserviceclient/paymentserviceclient.go
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
package paymentserviceclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/anyproto/any-sync/app"
|
||||||
|
"github.com/anyproto/any-sync/net/pool"
|
||||||
|
"github.com/anyproto/any-sync/net/rpc/rpcerr"
|
||||||
|
"github.com/anyproto/any-sync/nodeconf"
|
||||||
|
|
||||||
|
pp "github.com/anyproto/any-sync/paymentservice/paymentserviceproto"
|
||||||
|
)
|
||||||
|
|
||||||
|
const CName = "any-pp.drpcclient"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This client component can be used to access the Any Payment Processing node
|
||||||
|
* from other components.
|
||||||
|
*/
|
||||||
|
type AnyPpClientService interface {
|
||||||
|
GetSubscriptionStatus(ctx context.Context, in *pp.GetSubscriptionRequestSigned) (out *pp.GetSubscriptionResponse, err error)
|
||||||
|
BuySubscription(ctx context.Context, in *pp.BuySubscriptionRequestSigned) (out *pp.BuySubscriptionResponse, err error)
|
||||||
|
|
||||||
|
app.ComponentRunnable
|
||||||
|
}
|
||||||
|
|
||||||
|
type service struct {
|
||||||
|
pool pool.Pool
|
||||||
|
nodeconf nodeconf.Service
|
||||||
|
close chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Init(a *app.App) (err error) {
|
||||||
|
s.pool = a.MustComponent(pool.CName).(pool.Pool)
|
||||||
|
s.nodeconf = a.MustComponent(nodeconf.CName).(nodeconf.Service)
|
||||||
|
s.close = make(chan struct{})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Name() (name string) {
|
||||||
|
return CName
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() AnyPpClientService {
|
||||||
|
return new(service)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Run(_ context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Close(_ context.Context) error {
|
||||||
|
select {
|
||||||
|
case <-s.close:
|
||||||
|
default:
|
||||||
|
close(s.close)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) doClient(ctx context.Context, fn func(cl pp.DRPCAnyPaymentProcessingClient) error) error {
|
||||||
|
// it will try to connect to the Payment Node
|
||||||
|
// please use "paymentProcessingNode" type of node in the config (in the network.nodes array)
|
||||||
|
peer, err := s.pool.Get(ctx, s.nodeconf.PaymentProcessingNodePeers()[0])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dc, err := peer.AcquireDrpcConn(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer peer.ReleaseDrpcConn(dc)
|
||||||
|
|
||||||
|
return fn(pp.NewDRPCAnyPaymentProcessingClient(dc))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) GetSubscriptionStatus(ctx context.Context, in *pp.GetSubscriptionRequestSigned) (out *pp.GetSubscriptionResponse, err error) {
|
||||||
|
err = s.doClient(ctx, func(cl pp.DRPCAnyPaymentProcessingClient) error {
|
||||||
|
if out, err = cl.GetSubscriptionStatus(ctx, in); err != nil {
|
||||||
|
return rpcerr.Unwrap(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) BuySubscription(ctx context.Context, in *pp.BuySubscriptionRequestSigned) (out *pp.BuySubscriptionResponse, err error) {
|
||||||
|
err = s.doClient(ctx, func(cl pp.DRPCAnyPaymentProcessingClient) error {
|
||||||
|
if out, err = cl.BuySubscription(ctx, in); err != nil {
|
||||||
|
return rpcerr.Unwrap(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
1783
paymentservice/paymentserviceproto/paymentservice.pb.go
Normal file
1783
paymentservice/paymentserviceproto/paymentservice.pb.go
Normal file
File diff suppressed because it is too large
Load diff
153
paymentservice/paymentserviceproto/paymentservice_drpc.pb.go
Normal file
153
paymentservice/paymentserviceproto/paymentservice_drpc.pb.go
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||||
|
// protoc-gen-go-drpc version: v0.0.33
|
||||||
|
// source: paymentservice/paymentserviceproto/protos/paymentservice.proto
|
||||||
|
|
||||||
|
package paymentserviceproto
|
||||||
|
|
||||||
|
import (
|
||||||
|
bytes "bytes"
|
||||||
|
context "context"
|
||||||
|
errors "errors"
|
||||||
|
jsonpb "github.com/gogo/protobuf/jsonpb"
|
||||||
|
proto "github.com/gogo/protobuf/proto"
|
||||||
|
drpc "storj.io/drpc"
|
||||||
|
drpcerr "storj.io/drpc/drpcerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto struct{}
|
||||||
|
|
||||||
|
func (drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto) Marshal(msg drpc.Message) ([]byte, error) {
|
||||||
|
return proto.Marshal(msg.(proto.Message))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto) Unmarshal(buf []byte, msg drpc.Message) error {
|
||||||
|
return proto.Unmarshal(buf, msg.(proto.Message))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto) JSONMarshal(msg drpc.Message) ([]byte, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err := new(jsonpb.Marshaler).Marshal(&buf, msg.(proto.Message))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto) JSONUnmarshal(buf []byte, msg drpc.Message) error {
|
||||||
|
return jsonpb.Unmarshal(bytes.NewReader(buf), msg.(proto.Message))
|
||||||
|
}
|
||||||
|
|
||||||
|
type DRPCAnyPaymentProcessingClient interface {
|
||||||
|
DRPCConn() drpc.Conn
|
||||||
|
|
||||||
|
GetSubscriptionStatus(ctx context.Context, in *GetSubscriptionRequestSigned) (*GetSubscriptionResponse, error)
|
||||||
|
BuySubscription(ctx context.Context, in *BuySubscriptionRequestSigned) (*BuySubscriptionResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type drpcAnyPaymentProcessingClient struct {
|
||||||
|
cc drpc.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDRPCAnyPaymentProcessingClient(cc drpc.Conn) DRPCAnyPaymentProcessingClient {
|
||||||
|
return &drpcAnyPaymentProcessingClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *drpcAnyPaymentProcessingClient) DRPCConn() drpc.Conn { return c.cc }
|
||||||
|
|
||||||
|
func (c *drpcAnyPaymentProcessingClient) GetSubscriptionStatus(ctx context.Context, in *GetSubscriptionRequestSigned) (*GetSubscriptionResponse, error) {
|
||||||
|
out := new(GetSubscriptionResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/AnyPaymentProcessing/GetSubscriptionStatus", drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto{}, in, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *drpcAnyPaymentProcessingClient) BuySubscription(ctx context.Context, in *BuySubscriptionRequestSigned) (*BuySubscriptionResponse, error) {
|
||||||
|
out := new(BuySubscriptionResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/AnyPaymentProcessing/BuySubscription", drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto{}, in, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type DRPCAnyPaymentProcessingServer interface {
|
||||||
|
GetSubscriptionStatus(context.Context, *GetSubscriptionRequestSigned) (*GetSubscriptionResponse, error)
|
||||||
|
BuySubscription(context.Context, *BuySubscriptionRequestSigned) (*BuySubscriptionResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DRPCAnyPaymentProcessingUnimplementedServer struct{}
|
||||||
|
|
||||||
|
func (s *DRPCAnyPaymentProcessingUnimplementedServer) GetSubscriptionStatus(context.Context, *GetSubscriptionRequestSigned) (*GetSubscriptionResponse, error) {
|
||||||
|
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DRPCAnyPaymentProcessingUnimplementedServer) BuySubscription(context.Context, *BuySubscriptionRequestSigned) (*BuySubscriptionResponse, error) {
|
||||||
|
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DRPCAnyPaymentProcessingDescription struct{}
|
||||||
|
|
||||||
|
func (DRPCAnyPaymentProcessingDescription) NumMethods() int { return 2 }
|
||||||
|
|
||||||
|
func (DRPCAnyPaymentProcessingDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||||
|
switch n {
|
||||||
|
case 0:
|
||||||
|
return "/AnyPaymentProcessing/GetSubscriptionStatus", drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto{},
|
||||||
|
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||||
|
return srv.(DRPCAnyPaymentProcessingServer).
|
||||||
|
GetSubscriptionStatus(
|
||||||
|
ctx,
|
||||||
|
in1.(*GetSubscriptionRequestSigned),
|
||||||
|
)
|
||||||
|
}, DRPCAnyPaymentProcessingServer.GetSubscriptionStatus, true
|
||||||
|
case 1:
|
||||||
|
return "/AnyPaymentProcessing/BuySubscription", drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto{},
|
||||||
|
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||||
|
return srv.(DRPCAnyPaymentProcessingServer).
|
||||||
|
BuySubscription(
|
||||||
|
ctx,
|
||||||
|
in1.(*BuySubscriptionRequestSigned),
|
||||||
|
)
|
||||||
|
}, DRPCAnyPaymentProcessingServer.BuySubscription, true
|
||||||
|
default:
|
||||||
|
return "", nil, nil, nil, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DRPCRegisterAnyPaymentProcessing(mux drpc.Mux, impl DRPCAnyPaymentProcessingServer) error {
|
||||||
|
return mux.Register(impl, DRPCAnyPaymentProcessingDescription{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type DRPCAnyPaymentProcessing_GetSubscriptionStatusStream interface {
|
||||||
|
drpc.Stream
|
||||||
|
SendAndClose(*GetSubscriptionResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type drpcAnyPaymentProcessing_GetSubscriptionStatusStream struct {
|
||||||
|
drpc.Stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *drpcAnyPaymentProcessing_GetSubscriptionStatusStream) SendAndClose(m *GetSubscriptionResponse) error {
|
||||||
|
if err := x.MsgSend(m, drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return x.CloseSend()
|
||||||
|
}
|
||||||
|
|
||||||
|
type DRPCAnyPaymentProcessing_BuySubscriptionStream interface {
|
||||||
|
drpc.Stream
|
||||||
|
SendAndClose(*BuySubscriptionResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type drpcAnyPaymentProcessing_BuySubscriptionStream struct {
|
||||||
|
drpc.Stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *drpcAnyPaymentProcessing_BuySubscriptionStream) SendAndClose(m *BuySubscriptionResponse) error {
|
||||||
|
if err := x.MsgSend(m, drpcEncoding_File_paymentservice_paymentserviceproto_protos_paymentservice_proto{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return x.CloseSend()
|
||||||
|
}
|
107
paymentservice/paymentserviceproto/protos/paymentservice.proto
Normal file
107
paymentservice/paymentserviceproto/protos/paymentservice.proto
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
option go_package = "paymentservice/paymentserviceproto";
|
||||||
|
|
||||||
|
// TODO: no marshalling avail :-(
|
||||||
|
//import "google/protobuf/timestamp.proto";
|
||||||
|
|
||||||
|
enum SubscriptionTier {
|
||||||
|
Tier_Unknown = 0;
|
||||||
|
|
||||||
|
Tier_Friend = 1;
|
||||||
|
Tier_Supporter1Year = 2;
|
||||||
|
Tier_Patron1Year = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SubscriptionStatus {
|
||||||
|
Status_Unknown = 0;
|
||||||
|
Status_Pending = 1;
|
||||||
|
Status_Active = 2;
|
||||||
|
Status_Expired = 3;
|
||||||
|
Status_Canceled = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum PaymentMethod {
|
||||||
|
Method_Card = 0;
|
||||||
|
Method_Crypto = 1;
|
||||||
|
Method_ApplePay = 2;
|
||||||
|
Method_GooglePay = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1
|
||||||
|
message GetSubscriptionRequest {
|
||||||
|
// in the following format: "12D3KooWA8EXV3KjBxEU5EnsPfneLx84vMWAtTBQBeyooN82KSuS"
|
||||||
|
string ownerAnyID = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSubscriptionRequestSigned {
|
||||||
|
// GetSubscriptionRequest
|
||||||
|
bytes payload = 1;
|
||||||
|
|
||||||
|
// this is payload signed with payload.ownerAnyID
|
||||||
|
bytes signature = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSubscriptionResponse {
|
||||||
|
SubscriptionTier tier = 1;
|
||||||
|
SubscriptionStatus status = 2;
|
||||||
|
|
||||||
|
//TODO: use google.protobuf.Timestamp and marshall it
|
||||||
|
uint64 dateStarted = 3;
|
||||||
|
uint64 dateEnds = 4;
|
||||||
|
bool isAutoRenew = 5;
|
||||||
|
|
||||||
|
// if client has "downgraded" - he is still able to use the service until the end of the period
|
||||||
|
// (dateEnds) but then he will be on nextTier until nextTierEnds
|
||||||
|
//
|
||||||
|
// if Tier0_Unknown -> then no next tier
|
||||||
|
SubscriptionTier nextTier = 6;
|
||||||
|
uint64 nextTierEnds = 7;
|
||||||
|
|
||||||
|
PaymentMethod paymentMethod = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2
|
||||||
|
message BuySubscriptionRequest {
|
||||||
|
// in the following format: "12D3KooWA8EXV3KjBxEU5EnsPfneLx84vMWAtTBQBeyooN82KSuS"
|
||||||
|
string ownerAnyID = 1;
|
||||||
|
|
||||||
|
// this is the owner's ETH main EOA (External Owned Account) address
|
||||||
|
// not AccountAbstraction's SCW (Smart Contract Wallet) address!
|
||||||
|
//
|
||||||
|
// in the following format: "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"
|
||||||
|
// this is required to reserve a name for the owner
|
||||||
|
string ownerEthAddress = 2;
|
||||||
|
|
||||||
|
SubscriptionTier requestedTier = 3;
|
||||||
|
|
||||||
|
PaymentMethod paymentMethod = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BuySubscriptionRequestSigned {
|
||||||
|
// BuySubscriptionRequest
|
||||||
|
bytes payload = 1;
|
||||||
|
|
||||||
|
// this is payload signed with payload.ownerAnyID
|
||||||
|
bytes signature = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BuySubscriptionResponse {
|
||||||
|
// will feature current billing ID
|
||||||
|
// stripe.com/?client_reference_id=1234
|
||||||
|
string paymentUrl = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
service AnyPaymentProcessing {
|
||||||
|
rpc GetSubscriptionStatus(GetSubscriptionRequestSigned) returns (GetSubscriptionResponse) {}
|
||||||
|
|
||||||
|
// Will save a new BillingID to DB, and return a payment link
|
||||||
|
// You can:
|
||||||
|
// a) buy a subscription
|
||||||
|
// b) TODO: upgrade your tier
|
||||||
|
// c) TODO: renew subscription
|
||||||
|
//
|
||||||
|
// WARNING:
|
||||||
|
// 1 - User can not ask for a payment link on behalf of another user (a signature is required)
|
||||||
|
// 2 - Admin can do that on behalf of a user
|
||||||
|
rpc BuySubscription(BuySubscriptionRequestSigned) returns (BuySubscriptionResponse) {}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue