Skip to content

Commit b85fd72

Browse files
committed
Add stripe portal button on payment page
1 parent 2ab2d38 commit b85fd72

6 files changed

Lines changed: 41 additions & 6 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,10 +1513,12 @@ export class Message {
15131513
let user: NoderedUser;
15141514
const span: Span = Logger.otel.startSubSpan("message._EnsureNoderedInstance", parent);
15151515
try {
1516-
Logger.instanse.debug("[" + cli.user.username + "] EnsureNoderedInstance");
1516+
// Logger.instanse.debug("[" + cli.user.username + "] EnsureNoderedInstance");
15171517
if (_id === null || _id === undefined || _id === "") _id = cli.user._id;
15181518
const name = await this.GetInstanceName(_id, cli.user._id, cli.user.username, cli.jwt, span);
15191519

1520+
Logger.instanse.debug("[" + cli.user.username + "] EnsureNoderedInstance for " + name + " in namespace " + Config.namespace);
1521+
15201522
const users = await Config.db.query<NoderedUser>({ _id: _id }, null, 1, 0, null, "users", cli.jwt, undefined, undefined, span);
15211523
if (users.length == 0) {
15221524
throw new Error("Unknown userid " + _id);
@@ -1858,7 +1860,12 @@ export class Message {
18581860
private async _DeleteNoderedInstance(_id: string, myuserid: string, myusername: string, jwt: string, parent: Span): Promise<void> {
18591861
const span: Span = Logger.otel.startSubSpan("message._DeleteNoderedInstance", parent);
18601862
try {
1863+
1864+
if (_id === null || _id === undefined || _id === "") _id = myuserid;
18611865
const name = await this.GetInstanceName(_id, myuserid, myusername, jwt, span);
1866+
1867+
1868+
// const name = await this.GetInstanceName(_id, myuserid, myusername, jwt, span);
18621869
const user = Crypt.verityToken(jwt);
18631870
const namespace = Config.namespace;
18641871
let nodered_domain_schema = Config.nodered_domain_schema;
@@ -1867,7 +1874,6 @@ export class Message {
18671874
}
18681875
const hostname = nodered_domain_schema.replace("$nodered_id$", name);
18691876

1870-
18711877
const deployment = await KubeUtil.instance().GetDeployment(namespace, name);
18721878
if (deployment != null) {
18731879
let image: string = "unknown";
@@ -1883,14 +1889,20 @@ export class Message {
18831889
Audit.NoderedAction(user, false, name, "deletedeployment", image, null, span);
18841890
throw error;
18851891
}
1892+
} else {
1893+
Logger.instanse.warn("_DeleteNoderedInstance: Did not find deployment for " + name + " in namespace " + namespace);
18861894
}
18871895
const service = await KubeUtil.instance().GetService(namespace, name);
18881896
if (service != null) {
18891897
await KubeUtil.instance().CoreV1Api.deleteNamespacedService(name, namespace);
1898+
} else {
1899+
Logger.instanse.warn("_DeleteNoderedInstance: Did not find service for " + name + " in namespace " + namespace);
18901900
}
18911901
const replicaset = await KubeUtil.instance().GetReplicaset(namespace, "app", name);
18921902
if (replicaset !== null) {
18931903
KubeUtil.instance().AppsV1Api.deleteNamespacedReplicaSet(replicaset.metadata.name, namespace);
1904+
} else {
1905+
Logger.instanse.warn("_DeleteNoderedInstance: Did not find replicaset for " + name + " in namespace " + namespace);
18941906
}
18951907
const ingress = await KubeUtil.instance().GetIngressV1beta1(namespace, "useringress");
18961908
if (ingress !== null) {
@@ -1904,6 +1916,8 @@ export class Message {
19041916
if (updated) {
19051917
delete ingress.metadata.creationTimestamp;
19061918
await KubeUtil.instance().ExtensionsV1beta1Api.replaceNamespacedIngress("useringress", namespace, ingress);
1919+
} else {
1920+
Logger.instanse.warn("_DeleteNoderedInstance: Did not find ingress entry for " + name + " in namespace " + namespace);
19071921
}
19081922
} else {
19091923
throw new Error("failed locating useringress");
@@ -3284,7 +3298,9 @@ export class Message {
32843298
if (NoderedUtil.IsNullEmpty(msg.object)) throw new Error("object is mandatory");
32853299
if (!cli.user.HasRoleName("admins")) {
32863300
if (!NoderedUtil.IsNullEmpty(msg.url)) throw new Error("Custom url not allowed");
3287-
if (msg.object != "plans" && msg.object != "subscription_items" && msg.object != "invoices_upcoming") throw new Error("Access to " + msg.object + " is not allowed");
3301+
if (msg.object != "plans" && msg.object != "subscription_items" && msg.object != "invoices_upcoming" && msg.object != "billing_portal/sessions") {
3302+
throw new Error("Access to " + msg.object + " is not allowed");
3303+
}
32883304

32893305
if (msg.object == "subscription_items" && msg.method != "POST") throw new Error("Access to " + msg.object + " is not allowed");
32903306
if (msg.object == "plans" && msg.method != "GET") throw new Error("Access to " + msg.object + " is not allowed");

OpenFlow/src/public/Controllers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,22 @@ export class PaymentCtrl extends entityCtrl<Billing> {
37233723
}
37243724
if (!this.$scope.$$phase) { this.$scope.$apply(); }
37253725
}
3726+
async OpenPortal() {
3727+
try {
3728+
var payload: stripe_base = {} as any;
3729+
(payload as any).customer = this.stripe_customer.id;
3730+
var session: any = await NoderedUtil.Stripe("POST", "billing_portal/sessions", null, null, payload, null);
3731+
if (session && session.url) {
3732+
window.open(session.url, '_blank');
3733+
// window.location.href = session.url;
3734+
} else {
3735+
this.cardmessage = "Failed getting portal session url";
3736+
}
3737+
} catch (error) {
3738+
console.error(error);
3739+
this.cardmessage = error;
3740+
}
3741+
}
37263742
async CheckOut(planid: string, subplanid: string) {
37273743
try {
37283744
const result = await NoderedUtil.StripeAddPlan(this.userid, planid, subplanid, null);

OpenFlow/src/public/Payment.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,12 @@
344344
</div>
345345
<!-- ng-hide="ctrl.hastaxinfo && ctrl.hascustomer && (ctrl.model.coupon==null || ctrl.model.coupon == "")" -->
346346
<div class="form-group">
347+
<label class="control-label" translate lib="web" ng-hide="!ctrl.hastaxinfo">Update / Manage</label>
347348
<div class="col-sm-offset-3 col-sm-9">
348349
<button type="button" ng-click="ctrl.Save()" ng-disabled="ctrl.loading==true" class="btn btn-success"
349350
translate lib="web">save</button>
351+
<button type="button" ng-click="ctrl.OpenPortal()" ng-disabled="ctrl.loading==true"
352+
class="btn btn-success" translate lib="web">Portal</button>
350353
</div>
351354
</div>
352355
<!-- If you are based in Denmark, or you are based in an EU country and do not have a valid VAT number, you will be

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.2.107",
3+
"version": "1.2.108",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.107
1+
1.2.108

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.2.107",
3+
"version": "1.2.108",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)