I need to share a payment service class between two (or more) plugins and am wondering if Kuzzle's Pipes are the best solution for that?
I made a poc which seems to work, nevertheless, I don't found any similar example on kuzzle's plugins (like for hooks with Kuzzle-plugin-logger)
What are the other options?
The best way to share functionalities between plugins is to declare them as API actions.
You could expose your payment service features by creating a plugin named payment
for example and declaring a controller inside.
this.controllers = {
card: {
pay: request => ...,
fraudCheck: request => ...
}
};
Then you can use the embedded SDK to call those actions from another plugin. The request will be directly transmitted to Kuzzle without using the network.
this.context.accessors.sdk.query({
controller: 'payment/card',
action: pay,
number: '...',
ccv: 543,
...
});
Since Kuzzle rights are whitelist based so external users will not be able to call your actions unless you explicitly specify it in their roles.