1

I'm using the Mollie API for a SwiftUI app I'm creating. I'm communicating with the API using firebase cloud functions, and need to list the mandates of the current user. I'm using the Node.js Mollie client to communicate with the API.

Te following line code gives me a response with the relevant information, but I can't access the actual data in the '_embedded' or '_links' parameters of the response.

const mandates = await mollieClient.customers_mandates.page({customerId:
    customerID});

I keep getting errors like (in the case I attempt to access 'mandates' in '_embedded'):

Unhandled error TypeError: Cannot read property 'mandates' of undefined

I save the response in a constant (named mandates), and have been able to access and log "count" using console.log(mandates.count). However, this does not seem to work for "_embedded" and "_links".

Any tips on how to deal with this? Thanks in advance!

EDIT: Just found the following code snippet as example on the node client GitHub page. Which is different from the code sample provided in the mollie documentation. Trying this code results in similar error, but happens earlier (even before a response is given):

Unhandled error TypeError: Cannot read property 'all' of undefined


/**
 * @docs https://docs.mollie.com/reference/v2/mandates-api/list-mandates
 */
const { createMollieClient } = require('@mollie/api-client');

const mollieClient = createMollieClient({ apiKey: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' });

(async () => {
  try {
    const mandates = await mollieClient.customerMandates.all({
      customerId: 'cst_pzhEvnttJ2',
    });

    console.log(mandates);
  } catch (error) {
    console.warn(error);
  }
})();

Below an example response as provided by the Mollie documentation.

{
"count": 5,
"_embedded": {
    "mandates": [
        {
            "resource": "mandate",
            "id": "mdt_AcQl5fdL4h",
            "mode": "test",
            "status": "valid",
            "method": "directdebit",
            "details": {
                "consumerName": "John Doe",
                "consumerAccount": "NL55INGB0000000000",
                "consumerBic": "INGBNL2A"
            },
            "mandateReference": null,
            "signatureDate": "2018-05-07",
            "createdAt": "2018-05-07T10:49:08+00:00",
            "_links": {
                "self": {
                    "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates/mdt_AcQl5fdL4h",
                    "type": "application/hal+json"
                },
                "customer": {
                    "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U",
                    "type": "application/hal+json"
                },
                "documentation": {
                    "href": "https://mollie.com/en/docs/reference/customers/create-mandate",
                    "type": "text/html"
                }
            }
        },
        { },
        { },
        { },
        { }
    ]
},
"_links": {
    "self": {
        "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates?limit=5",
        "type": "application/hal+json"
    },
    "previous": null,
    "next": {
        "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates?from=mdt_AcQl5fdL4h&limit=5",
        "type": "application/hal+json"
    },
    "documentation": {
        "href": "https://docs.mollie.com/reference/v2/mandates-api/revoke-mandate",
        "type": "text/html"
    }
}

}

Melle
  • 11
  • 2

0 Answers0