OSSPhilippines / paymongo

A lightweight Node.js client for Paymongo API

Home Page:https://paymongo.ossph.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the same library to process payment with 2 paymongo account

davidnjuko opened this issue · comments

commented

Describe the bug
We are using this library to process payment with different paymongo account in the same application runtime. Cause of the Singleton design pattern we sometime don't have the ref to the expected Paymongo instance.

To Reproduce
paymongo1 = new Paymongo("secretKey1");
...
paymongo2 = new Paymongo("another_secretKey");
...

Expected behavior
The constructor should double check the existing instance API Key to avoid this

commented
export default class Paymongo {
  constructor (secret) {
    if (!secret) throw new Error('API key is required!');

    if (Paymongo.instance instanceof Paymongo) {
      if (Paymongo.instance.secret === secret) {
        return Paymongo.instance;
      }
    }
    this.secret = secret;

Hi @davidnjuko this make sense, thank you for posting an issue. I'll see to it as soon as possible.

commented

Hi @jofftiquez

Any news on this ?

@jofftiquez Do you plan to update this library or not ?

@jofftiquez Do you plan to update this library or not ?

PRs are welcome, thank you.