Skip to content

Commit

Permalink
GO-4351 Membership v2 API WiP: cart, store
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyAkentiev committed Oct 25, 2024
1 parent 60e9443 commit b4494c3
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 0 deletions.
220 changes: 220 additions & 0 deletions pb/protos/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7564,6 +7564,226 @@ message Rpc {
}
}
}

message MembershipV2 {
message GetStatus {
message Request {
}

message Response {
Error error = 1;
repeated anytype.model.MembershipV2.PurchasedProduct products = 2;
anytype.model.MembershipV2.Invoice nextInvoice = 3;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
}
}
}
}

// Some products require extra allocation step
message ProductAllocateToSpace {
message Request {
string spaceId = 1;
string productId = 2;
// some additional data
string context = 3;
}

message Response {
Error error = 1;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}
}

message Store {
message ProductsEnumerate {
message Request {
}

message Response {
Error error = 1;
repeated anytype.model.MembershipV2.StoreProduct products = 2;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}

message Cart {
message Get {
message Request {
}

message Response {
Error error = 1;
anytype.model.MembershipV2.Cart cart = 2;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}

message ProductAdd {
message Request {
string productId = 1;
// if "isAttachedToSpace" was true for that product
string spaceID = 2;
// some additional context (extra)
string context = 3;
}

message Response {
Error error = 1;
anytype.model.MembershipV2.Cart cart = 2;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}

message ProductRemove {
message Request {
// each product instance has a unique index
// each product instance can have a different "context" attached (like spaceId)
string index = 1;
}

message Response {
Error error = 1;
anytype.model.MembershipV2.Cart cart = 2;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}

message PromocodeApply {
message Request {
string promocode = 1;
}

message Response {
Error error = 1;
anytype.model.MembershipV2.Cart cart = 2;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}

// go to the payment page
message CheckoutGenerate {
message Request {
}

message Response {
Error error = 1;
string paymentUrl = 2;

message Error {
Code code = 1;
string description = 2;

enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
NOT_LOGGED_IN = 3;
PAYMENT_NODE_ERROR = 4;
CACHE_ERROR = 5;
CAN_NOT_CONNECT = 6;
}
}
}
}
}
}
}


Expand Down
11 changes: 11 additions & 0 deletions pb/protos/service/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,15 @@ service ClientCommands {
rpc ChatUnsubscribe (anytype.Rpc.Chat.Unsubscribe.Request) returns (anytype.Rpc.Chat.Unsubscribe.Response);
rpc ObjectChatAdd (anytype.Rpc.Object.ChatAdd.Request) returns (anytype.Rpc.Object.ChatAdd.Response);

// Store
rpc StoreProductsEnumerate (anytype.Rpc.Store.ProductsEnumerate.Request) returns (anytype.Rpc.Store.ProductsEnumerate.Response);
rpc StoreCartGet (anytype.Rpc.Store.Cart.Get.Request) returns (anytype.Rpc.Store.Cart.Get.Response);
rpc StoreCartProductAdd (anytype.Rpc.Store.Cart.ProductAdd.Request) returns (anytype.Rpc.Store.Cart.ProductAdd.Response);
rpc StoreCartProductRemove (anytype.Rpc.Store.Cart.ProductRemove.Request) returns (anytype.Rpc.Store.Cart.ProductRemove.Response);
rpc StoreCartPromocodeApply (anytype.Rpc.Store.Cart.PromocodeApply.Request) returns (anytype.Rpc.Store.Cart.PromocodeApply.Response);
rpc StoreCartCheckoutGenerate (anytype.Rpc.Store.Cart.CheckoutGenerate.Request) returns (anytype.Rpc.Store.Cart.CheckoutGenerate.Response);

// MembershipV2
rpc MembershipV2GetStatus (anytype.Rpc.MembershipV2.GetStatus.Request) returns (anytype.Rpc.MembershipV2.GetStatus.Response);
rpc MembershipV2ProductAllocateToSpace (anytype.Rpc.MembershipV2.ProductAllocateToSpace.Request) returns (anytype.Rpc.MembershipV2.ProductAllocateToSpace.Response);
}
80 changes: 80 additions & 0 deletions pkg/lib/pb/model/protos/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,7 @@ message MembershipTierData {
string androidProductId = 17;
string androidManageUrl = 18;
}

enum DeviceNetworkType {
WIFI = 0;
CELLULAR = 1;
Expand Down Expand Up @@ -1360,3 +1361,82 @@ message ChatMessage {
}
}
}

message MembershipV2 {
message Amount {
string currency = 1;
// $0.01 = 1
// $1.00 = 100
uint32 amountCents = 2;
}

message Product {
// this is a unique Payment Node ID of the tier
// adding 2 same products to a cart means we will have 2 items with same ID
uint32 id = 1;
bool isActive = 2;
// is it a product that should be attached to a space
bool isAttachToSpace = 3;
// the price of a Package may not be equal to the sum of all underlying products
bool isPackage = 4;
// localized
string name = 5;
string description = 6;
bool isTest = 7;
MembershipTierData.PeriodType periodType = 8;
// i.e. "5 days" or "3 years"
uint32 periodValue = 9;
}

message PurchaseInfo {
uint64 dateStarted = 1;
uint64 dateEnds = 2;
bool isAutoRenew = 3;
Membership.PaymentMethod paymentMethod = 4;
}

message ProductStatus {
enum Status {
StatusUnknown = 0;
StatusPending = 1;
StatusActive = 2;
StatusPendingRequiresFinalization = 3;
}
Status status = 1;

string spaceAttachedTo = 2;
bool isNeedsAttachmentToSpace = 3;
}

message PurchasedProduct {
Product product = 1;
PurchaseInfo purchaseInfo = 2;
ProductStatus productStatus = 3;
}

message StoreProduct {
Product product = 1;
Amount price = 2;
}

message Invoice {
enum Status {
Unpaid = 0;
Paid = 1;
}

string id = 1;
uint64 date = 2;
Amount total = 3;
Status status = 4;
}

message Cart {
// if you add Nx the same product - it will be Nx in the 'products' array, i.e:
// each product instance has a unique index
// each product instance can have a different "context" attached (like spaceId)
repeated Product products = 1;
// total amount of the cart (including discounts, etc)
Amount total = 2;
}
}

0 comments on commit b4494c3

Please sign in to comment.