Skip to content

Commit b29ee78

Browse files
committed
Payment push 2
1 parent be847b8 commit b29ee78

12 files changed

Lines changed: 889 additions & 356 deletions

File tree

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: 412 additions & 61 deletions
Large diffs are not rendered by default.

OpenFlow/src/Messages/StripeMessage.ts

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,75 @@
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+
constructor() {
15+
super();
16+
this._type = "billing";
17+
this.hascard = false;
18+
}
19+
}
20+
21+
export class EnsureStripeCustomerMessage implements IReplyMessage {
22+
public error: string;
23+
public jwt: string;
24+
25+
public userid: string;
26+
public billing: Billing;
27+
public customer: stripe_customer;
28+
static assign(o: any): EnsureStripeCustomerMessage {
29+
if (typeof o === "string" || o instanceof String) {
30+
return Object.assign(new EnsureStripeCustomerMessage(), JSON.parse(o.toString()));
31+
}
32+
return Object.assign(new EnsureStripeCustomerMessage(), o);
33+
}
34+
}
35+
36+
export class StripeCancelPlanMessage implements IReplyMessage {
37+
public error: string;
38+
public jwt: string;
39+
40+
public userid: string;
41+
public planid: string;
42+
public customer: stripe_customer;
43+
static assign(o: any): StripeCancelPlanMessage {
44+
if (typeof o === "string" || o instanceof String) {
45+
return Object.assign(new StripeCancelPlanMessage(), JSON.parse(o.toString()));
46+
}
47+
return Object.assign(new StripeCancelPlanMessage(), o);
48+
}
49+
}
50+
export class StripeAddPlanMessage implements IReplyMessage {
51+
public error: string;
52+
public jwt: string;
53+
54+
public userid: string;
55+
public planid: string;
56+
public subplanid: string;
57+
public customer: stripe_customer;
58+
public checkout: stripe_checkout_session;
59+
static assign(o: any): StripeAddPlanMessage {
60+
if (typeof o === "string" || o instanceof String) {
61+
return Object.assign(new StripeAddPlanMessage(), JSON.parse(o.toString()));
62+
}
63+
return Object.assign(new StripeAddPlanMessage(), o);
64+
}
65+
}
66+
167
export class stripe_base {
268
public id: string;
369
public object: string;
470
public created: number;
571
public livemode: boolean;
6-
public deleted: boolean;
72+
public metadata: { [key: string]: any };
773
}
874
export class StripeMessage implements IReplyMessage {
975
public error: string;
@@ -22,20 +88,84 @@ export class StripeMessage implements IReplyMessage {
2288
return Object.assign(new StripeMessage(), o);
2389
}
2490
}
91+
export class stripeplan {
92+
public id: string;
93+
public name: string;
94+
public price: number;
95+
public subtitle: string;
96+
public text: string;
97+
public subplan: stripeplan;
98+
}
2599
export class stripe_list<T> {
26100
public object: string;
27101
public has_more: boolean;
102+
public total_count: number;
28103
public url: string;
29104
public data: T[];
30105
}
106+
export class tax_info {
107+
public tax_id: string;
108+
public type: string;
109+
}
110+
export class tax_info_verification {
111+
public status: string;
112+
public verified_name: string;
113+
}
114+
export class stripe_plan {
115+
public status: boolean;
116+
public nickname: string;
117+
public id: string;
118+
public product: string;
119+
public amount: number;
120+
public usage_type: string;
121+
}
122+
export class stripe_subscription_data {
123+
public items: stripe_subscription_item[];
124+
}
125+
export class stripe_checkout_session extends stripe_base {
126+
public success_url: string;
127+
public cancel_url: string;
128+
public payment_method_types: string[] = ["card"];
129+
public customer: string;
130+
public mode: string = "subscription";
131+
public subscription_data: stripe_subscription_data;
132+
}
31133
export class stripe_customer extends stripe_base {
134+
public description: string;
135+
public name: string;
136+
public email: string;
137+
public tax_ids: stripe_list<stripe_tax_id>;
138+
public subscriptions: stripe_list<stripe_subscription>;
139+
// deprecated tax_info and tax_info_verification
140+
// public tax_info: tax_info;
141+
// public tax_info_verification: tax_info_verification;
142+
}
143+
export class stripe_tax_verification {
144+
public status: string;
145+
public verified_address: string;
146+
public verified_name: string;
32147
}
33148
export class stripe_tax_id extends stripe_base {
149+
public country: string;
150+
public customer: string;
151+
public type: string;
152+
public value: string;
153+
public verification: stripe_tax_verification;
154+
}
155+
export class stripe_subscription_item extends stripe_base {
156+
public id: string;
157+
public quantity: number;
158+
public subscription: string;
159+
public plan: stripe_plan;
160+
public tax_rates: string;
34161
}
35162
export class stripe_subscription extends stripe_base {
163+
// public plan: stripe_plan;
36164
public address: string;
37165
public balance: number;
38166
public currency: string;
39167
public subscriptions: stripe_list<stripe_subscription>;
40168
public tax_ids: stripe_list<stripe_tax_id>;
169+
public items: stripe_list<stripe_subscription_item>;
170+
public default_tax_rates: string[];
41171
}

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)