mollie-api-node
mollie-api-node copied to clipboard
TypeError: Missing parameter "apiKey" or "accessToken".
I'm trying to us the Mollie NodeJS API in a NestJS application, but when I use the createMollieClient function, I get the error TypeError: Missing parameter "apiKey" or "accessToken". while I'm providing the apiKey options. See code below:
import { PaymentsService } from './payments.service';
import {
ConfigurableModuleClass,
OPTIONS_TYPE,
PAYMENT_MODULE_OPTIONS,
} from './backend-payments-util.module.definition';
import { MolliePaymentsProvider } from './providers/mollie.payments.provider';
import createMollieClient, { MollieClient, MollieOptions } from '@mollie/api-client';
@Module({})
export class BackendPaymentsUtilModule extends ConfigurableModuleClass {
constructor(
@Inject(PAYMENT_MODULE_OPTIONS) private options: string | symbol,
) {
super();
}
static register(options: typeof OPTIONS_TYPE) {
if (options.paymentProvider === 'mollie') {
**const mollieClient: MollieClient = createMollieClient({
apiKey: process.env['MOLLIE_API_KEY'] || '',
} as MollieOptions);**
return {
...super.register(options),
providers: [
{
provide: PAYMENT_MODULE_OPTIONS,
useValue: options,
},
{
provide: PaymentsService,
useFactory: () => new MolliePaymentsProvider(mollieClient),
},
],
};
} else {
throw new Error('Payment provider not supported');
}
}
}
I also tried the createMollieClient available like so:
import { createMollieClient, MollieClient, MollieOptions } from '@mollie/api-client';
But same issue.