Well, not quite. But, miraculously, that was enough! I found this:
And then I did this!!
api.modifyClass("controller:subscribe-show", {
pluginId: "pfaffmanager",
async _advanceSuccessfulTransaction(plan) {
window.console.log("modifying subscription!!!", plan, this);
this.alert("plans.success");
this.set("loading", false);
let servers = [];
servers = await Server.listServers().then((result) => {
if (currentUser && currentUser.servers !== undefined) {
servers = currentUser.servers.sort((b, a) => {
return ("" + a.updated_at).localeCompare(b.updated_at);
});
window.console.log("sorted servers", servers);
if (servers.length > 0) {
window.console.log(`going to first! ${servers[0].id}`);
this.transitionToRoute(
"pfaffmanager.servers.show",
servers[0].id
);
} else {
window.console.log(`server not found. going to index!`);
this.transitionToRoute("pfaffmanager.servers.index");
}
// window.location = getURL(`/`);
// window.location = getURL(`/pfaffmanager/servers/${id}`);
}
});
},
});
Which is so very, fary, close. The issue now is that there is a race condition, as the add_model_callback(DiscourseSubscriptions::Customer, :after_save) do might not be finished before I do my ajax query to get the servers.
Well, it’s stranger than that. Even if I add a delay (using later) before it does the ajax call to get the new server list, it is still getting a stale list, not the one after the new server has been added in the callback. I can refresh the window in another tab and see that it gets the right data before it does the ajax call.
I guess I’ll give up for now. For the case whether the server exists before the purchase (which I think is more common–you’d configure everything and then say, “yeah, let’s do it”) it works; it’s just the case where they say “Yeah, I want to pay for an installation; I’ll pay and then see what happens.”