wl-online-payments-direct / sdk-client-js

Other
3 stars 2 forks source link

Multiple instances of client SDK #3

Closed TheoGautier closed 2 years ago

TheoGautier commented 2 years ago

apiVersion: v2.

Hi Wordline,

I have an issue when creating multiple instances of the onlinepayments-sdk-nodej defaultApi in the same file, for two separate integrators.

Context

I have the following :

// directSdkProvider.js
import directSdk from "onlinepayments-sdk-nodejs";

class DirectSdkProvider {
    constructor(integrator, ingenicoConfig, apiConfig) {
        const context = {
            integrator: integrator,
            host: ingenicoConfig.apiHost,
            scheme: 'https', // default
            port: 443, // default
            // enableLogging: process.env.NODE_ENV !== "production", // defaults to false
            enableLogging: false, // defaults to false
            apiKeyId: apiConfig.sdkKeyId,
            secretApiKey: apiConfig.sdkSecretKey,
        };
        this.sdk = directSdk.init(context);
    }
}

export default DirectSdkProvider;

And this:

// directSdk.js
import DirectSdkProvider from "./directSdkProvider.js";
import config from "../config/index.js";
const ingenicoConfig = config.ingenico;

const initIngenicoDirectSdk = function(integrator) {
    const drouot = integrator === "GDrouotGroupe" || integrator === "DROUOTFLEXTEST";
    const apiConfig = drouot ?
        ingenicoConfig.drouot : ingenicoConfig.dnid;
    return new DirectSdkProvider(integrator, ingenicoConfig, apiConfig).sdk;
}

export const mainDirectSdk = initIngenicoDirectSdk(ingenicoConfig.integrator);
export const dnidDirectSdk = initIngenicoDirectSdk(ingenicoConfig.dnidIntegrator);

const pspids = new Set(config.ingenico.dnidPspids);

export function getSdk(pspid) {
    if (pspids.has(pspid)) {
        return dnidDirectSdk
    }
    return mainDirectSdk
}

export default {
    drouotDefaultMerchantId: ingenicoConfig.drouotDefaultMerchantId,
    moniteurDefaultMerchantId: ingenicoConfig.moniteurDefaultMerchantId,
};

Issue

The issue is simple: When I have both instances, the second one seems to crush the first one. In this configuration, a payment using mainDirectSdk does not succeed -> I cannot even init my session, sdk.sessions.createSession fails with DIRECT_PLATFORM_ERROR, ACCESS_TO_MERCHANT_NOT_ALLOWED. When I comment or remove the second sdk instance, dnidDirectSdk, it works.

Can you help me with this? Thank you.

worldline-direct-support-team commented 2 years ago

Hi Theo, thanks for reaching out!

It seems you are using the sdk-nodejs, not this sdk-client-js.

It is currently not possible to use the NodeJS SDK with multiple configurations in a single application. When you call initIngenicoDirectSdk with 'dnidIntegrator' config it overrides the configuration of 'integrator'. This means that your dnid API keys will be used for calls with your main merchant. This is due to the way directSdk.init is set up.

We're working on making multiple instances possible this summer. In the meantime we'll work on getting a work-around available for you. We'll get back to you within a week.

Kind regards, Worldline support team

worldline-direct-support-team commented 2 years ago

Hi Theo,

Unfortunately the work-around isn't satisfactory. Instead, we'll focus on the update of the SDK and pull its release forward to next week by the latest.

Kind regards, Worldline support team

TheoGautier commented 2 years ago

Hi Wordline,

Thanks for the update, I'm expecting your release for soon, have a nice day.

TheoGautier commented 2 years ago

Hi Wordline,

Are there any news on this issue?

Have a nice day.

worldline-direct-support-team commented 2 years ago

Hello Theo,

We have published a new release on the NodeJS SDK that should resolve this issue. Version 3.4.2. https://github.com/wl-online-payments-direct/sdk-nodejs/releases/tag/3.4.2

Kind regards, Worldline support team

edit: updated referenced version to 3.4.1. edit: updated referenced version to 3.4.2.

worldline-direct-support-team commented 2 years ago

After further investigation the fix wasn't deemed enough. The SDK has been updated with a better solution in release 4.0.0: https://github.com/wl-online-payments-direct/sdk-nodejs/releases/tag/4.0.0