wl-online-payments-direct / sdk-nodejs

Other
3 stars 0 forks source link

Need help to use this lib from a typescript service #1

Closed vdoulcier closed 2 years ago

vdoulcier commented 2 years ago

Hello,

I'm currently trying to use this library in a typescript service, but unfortunately neither documentation or readme file help me to start with (would be great if you can share a full code example of some methods).

I can not be sure about the result of the init method ; here are some open questions I have :

Please find below a code example, and thank's for any help!

import { Injectable } from '@nestjs/common';

import directSdk from 'direct-sdk-nodejs';

@Injectable()
export class ExampleService {

  public async initialization(): Promise<void> {
    console.log('Welcome!');

    directSdk.init({
      integrator: '*****',
      host: 'https://payment.preprod.direct.ingenico.com',
      scheme: 'https',
      port: 443,
      enableLogging: true,
      apiKeyId: '*****',
      secretApiKey: '*****'
    });

    const result = await directSdk.hostedCheckout.createHostedCheckout({
      order: {
        amountOfMoney: {
          amount: 100,
          currencyCode: 'EUR',
        }
      }
    });
    console.log(result);

    // console.log(directSdk); // Looks like it returns some available methods...
    // const result = await directSdk.services.testConnection();
    // const result = await directSdk.services.testConnection('*****');
    // const result = await directSdk.merchant('*****').services.testConnection();
    // console.log(result);
  }
}
rob-spoor commented 2 years ago

The directSdk import is the entry point for the SDK. You initialize it, as documented at Initialization of the Node.js SDK. The init function returns the object itself, but you can ignore its return value - it's the same as the directSdk import itself.

I tried to find some examples, but I didn't get any further than the integration tests. These do show mostly how to use the SDK. The empty objects at the end are the so-called payment content, which can be used for idempotency (see https://support.direct.ingenico.com/documentation/sdk/server/nodejs/#Idempotent-requests). In your example, you're missing the merchant id.

As for auto-completion, the SDK currently has no TypeScript definitions available. Without those, IDEs are unable to tell what properties and functions are available.