mollie / mollie-api-node

Official Mollie API client for Node
http://www.mollie.com
BSD 3-Clause "New" or "Revised" License
228 stars 62 forks source link

Remove withParent #323

Closed Pimm closed 1 year ago

Pimm commented 1 year ago

This library relies heavily on the network, which makes it asynchronous throughout. Asynchronicity doesn't mix well with stateful operations such as withParent.

While this code will always work:

const payment = await mollieClient.customerPayments.withParent({ id: 'cst_pzhEvnttJ2' })
                                                   .create([…]);

This code may be surprising:

mollieClient.customerPayments.withParent({ id: 'cst_pzhEvnttJ2' });
// […]
const payment = mollieClient.customerPayments.create([…]);

If withParent is called after that first line executes but before the second one does, it will overwrite the customer. If the await keyword appears between those two lines, that withParent call could be anywhere.

The stateless variant does not have this issue:

const payment = await mollieClient.customerPayments.create({ customerId: 'cst_pzhEvnttJ2', … });

This change is breaking. The next release will be 4.0.0. withParent was deprecated in 2018.