Skip to content

Commit d53c3e2

Browse files
authored
Merge pull request openiap#44 from skadefro/master
bug fixes and started to added billing support
2 parents b386b48 + f3c7b01 commit d53c3e2

13 files changed

Lines changed: 1315 additions & 697 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM node:latest
1+
# FROM node:latest
2+
FROM node:10.16.0-jessie
23
EXPOSE 80
34
EXPOSE 5858
45
WORKDIR /data

OpenFlow/src/DatabaseConnection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,9 @@ export class DatabaseConnection {
848848
}
849849
}
850850
var _query: Object = {};
851+
if (!Util.IsNullEmpty(Config.stripe_api_secret) && q.collectionname === "users") {
852+
if (!user.hasrolename("admins")) throw new Error("Access denied, no authorization to UpdateMany");
853+
}
851854
if (q.collectionname === "files") { q.collectionname = "fs.files"; }
852855
if (q.collectionname === "fs.files") {
853856
_query = { $and: [q.query, this.getbasequery(q.jwt, "metadata._acl", [Rights.update])] };

OpenFlow/src/Messages/Message.ts

Lines changed: 400 additions & 60 deletions
Large diffs are not rendered by default.

OpenFlow/src/Messages/StripeMessage.ts

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,76 @@
1+
import { Base } from "../base";
2+
3+
export class Billing extends Base {
4+
public stripeid: string;
5+
public userid: string;
6+
public name: string;
7+
public email: string;
8+
public address: string;
9+
public vattype: string;
10+
public vatnumber: string;
11+
public taxrate: string;
12+
public tax: number;
13+
public hascard: boolean;
14+
public coupon: string;
15+
constructor() {
16+
super();
17+
this._type = "billing";
18+
this.hascard = false;
19+
}
20+
}
21+
22+
export class EnsureStripeCustomerMessage implements IReplyMessage {
23+
public error: string;
24+
public jwt: string;
25+
26+
public userid: string;
27+
public billing: Billing;
28+
public customer: stripe_customer;
29+
static assign(o: any): EnsureStripeCustomerMessage {
30+
if (typeof o === "string" || o instanceof String) {
31+
return Object.assign(new EnsureStripeCustomerMessage(), JSON.parse(o.toString()));
32+
}
33+
return Object.assign(new EnsureStripeCustomerMessage(), o);
34+
}
35+
}
36+
37+
export class StripeCancelPlanMessage implements IReplyMessage {
38+
public error: string;
39+
public jwt: string;
40+
41+
public userid: string;
42+
public planid: string;
43+
public customer: stripe_customer;
44+
static assign(o: any): StripeCancelPlanMessage {
45+
if (typeof o === "string" || o instanceof String) {
46+
return Object.assign(new StripeCancelPlanMessage(), JSON.parse(o.toString()));
47+
}
48+
return Object.assign(new StripeCancelPlanMessage(), o);
49+
}
50+
}
51+
export class StripeAddPlanMessage implements IReplyMessage {
52+
public error: string;
53+
public jwt: string;
54+
55+
public userid: string;
56+
public planid: string;
57+
public subplanid: string;
58+
public customer: stripe_customer;
59+
public checkout: stripe_checkout_session;
60+
static assign(o: any): StripeAddPlanMessage {
61+
if (typeof o === "string" || o instanceof String) {
62+
return Object.assign(new StripeAddPlanMessage(), JSON.parse(o.toString()));
63+
}
64+
return Object.assign(new StripeAddPlanMessage(), o);
65+
}
66+
}
67+
168
export class stripe_base {
269
public id: string;
370
public object: string;
471
public created: number;
572
public livemode: boolean;
6-
public deleted: boolean;
73+
public metadata: { [key: string]: any };
774
}
875
export class StripeMessage implements IReplyMessage {
976
public error: string;
@@ -22,20 +89,98 @@ export class StripeMessage implements IReplyMessage {
2289
return Object.assign(new StripeMessage(), o);
2390
}
2491
}
92+
export class stripeplan {
93+
public id: string;
94+
public name: string;
95+
public price: number;
96+
public subtitle: string;
97+
public text: string;
98+
public subplan: stripeplan;
99+
}
25100
export class stripe_list<T> {
26101
public object: string;
27102
public has_more: boolean;
103+
public total_count: number;
28104
public url: string;
29105
public data: T[];
30106
}
107+
export class tax_info {
108+
public tax_id: string;
109+
public type: string;
110+
}
111+
export class tax_info_verification {
112+
public status: string;
113+
public verified_name: string;
114+
}
115+
export class stripe_plan {
116+
public status: boolean;
117+
public nickname: string;
118+
public id: string;
119+
public product: string;
120+
public amount: number;
121+
public usage_type: string;
122+
}
123+
export class stripe_subscription_data {
124+
public items: stripe_subscription_item[];
125+
}
126+
export class stripe_checkout_session extends stripe_base {
127+
public success_url: string;
128+
public cancel_url: string;
129+
public payment_method_types: string[] = ["card"];
130+
public customer: string;
131+
public mode: string = "subscription";
132+
public subscription_data: stripe_subscription_data;
133+
}
134+
135+
export class stripe_coupon extends stripe_base {
136+
public duration: string;
137+
public duration_in_months: number;
138+
public name: string;
139+
//public duration: string;
140+
}
141+
export class stripe_customer_discount extends stripe_base {
142+
public subscription: string;
143+
public start: number;
144+
public customer: string;
145+
public coupon: stripe_coupon;
146+
}
31147
export class stripe_customer extends stripe_base {
148+
public description: string;
149+
public name: string;
150+
public email: string;
151+
public tax_ids: stripe_list<stripe_tax_id>;
152+
public subscriptions: stripe_list<stripe_subscription>;
153+
public discount: stripe_customer_discount;
154+
// deprecated tax_info and tax_info_verification
155+
// public tax_info: tax_info;
156+
// public tax_info_verification: tax_info_verification;
157+
}
158+
export class stripe_tax_verification {
159+
public status: string;
160+
public verified_address: string;
161+
public verified_name: string;
32162
}
33163
export class stripe_tax_id extends stripe_base {
164+
public country: string;
165+
public customer: string;
166+
public type: string;
167+
public value: string;
168+
public verification: stripe_tax_verification;
169+
}
170+
export class stripe_subscription_item extends stripe_base {
171+
public id: string;
172+
public quantity: number;
173+
public subscription: string;
174+
public plan: stripe_plan;
175+
public tax_rates: string;
34176
}
35177
export class stripe_subscription extends stripe_base {
178+
// public plan: stripe_plan;
36179
public address: string;
37180
public balance: number;
38181
public currency: string;
39182
public subscriptions: stripe_list<stripe_subscription>;
40183
public tax_ids: stripe_list<stripe_tax_id>;
184+
public items: stripe_list<stripe_subscription_item>;
185+
public default_tax_rates: string[];
41186
}

OpenFlow/src/public/CommonControllers.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,28 @@ module openflow {
322322
q = await this.WebSocketClient.Send<StripeMessage>(msg);
323323
return (q.payload as any);
324324
}
325+
async EnsureStripeCustomer(billing: Billing, userid: string): Promise<stripe_customer> {
326+
var q: EnsureStripeCustomerMessage = new EnsureStripeCustomerMessage();
327+
q.billing = billing; q.userid = userid;
328+
var msg: Message = new Message(); msg.command = "ensurestripecustomer"; msg.data = JSON.stringify(q);
329+
q = await this.WebSocketClient.Send<EnsureStripeCustomerMessage>(msg);
330+
return q.customer;
331+
}
332+
async StripeAddPlan(userid: string, planid: string, subplanid: string): Promise<StripeAddPlanMessage> {
333+
var q: StripeAddPlanMessage = new StripeAddPlanMessage();
334+
q.userid = userid; q.planid = planid; q.subplanid = subplanid;
335+
var msg: Message = new Message(); msg.command = "stripeaddplan"; msg.data = JSON.stringify(q);
336+
q = await this.WebSocketClient.Send<StripeAddPlanMessage>(msg);
337+
return q;
338+
}
339+
async StripeCancelPlan(userid: string, planid: string): Promise<StripeAddPlanMessage> {
340+
var q: StripeAddPlanMessage = new StripeAddPlanMessage();
341+
q.userid = userid; q.planid = planid;
342+
var msg: Message = new Message(); msg.command = "stripecancelplan"; msg.data = JSON.stringify(q);
343+
q = await this.WebSocketClient.Send<StripeAddPlanMessage>(msg);
344+
return q;
345+
}
346+
325347

326348
setCookie(cname, cvalue, exdays) {
327349
var d = new Date();

0 commit comments

Comments
 (0)