mollie / mollie-api-node

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

Connect example? #150

Closed RoyBkker closed 3 years ago

RoyBkker commented 4 years ago

Hi,

I can't figure out how the mollie connect process is working for setting up Application fees.

Is it possible to add an example, just like the others?

Thanks.

silveltman commented 3 years ago

Having the same problem here!

Pimm commented 3 years ago

Application fees are documented over at docs.mollie.com. Creating a payment which includes an application fee looks the same as the create payment example, with an added applicationFee property.

Mollie Connect requires a few parts to be in place to work; unlike the basic functionality which only requires an API key. This is why code examples for it would be either lengthy, or only cover part of the story.

Perhaps you could give more of a hint as to where you get stuck. That would be very helpful.

silveltman commented 3 years ago

After a long day of coding I seem to have looked over the fact that application fees should be enabled by contacting the support department.

If someone needs it, here is an example piece of code including the applilcationFee:

const { createMollieClient } = require('@mollie/api-client');
const mollieClient = createMollieClient({accessToken: 'ACCESS_TOKEN'});

mollieClient.payments.create({
    amount: {
      value: '15.00',
      currency: 'EUR'
    },
    description: 'My first API payment',
    redirectUrl: 'http://127.0.0.1:3000/',
    webhookUrl: 'https://yourwebshop.example.org/webhook',
    profileId: 'xxx_1234567890',
    testmode: true,
    locale: 'nl_NL',
    applicationFee: {
      amount: {
        currency: 'EUR',
        value: '0.01',
      },
      description: 'my fee',
    }
  })
    .then(payment => {
      console.log('payment created!');
      console.log(payment);
    })
    .catch(error => {
      console.error(error);
    });

@Pimm Thanks anyway!

Edit: replaced apiKey with accessToken

Pimm commented 3 years ago

If you use an access token (as opposed to an API key, which you would use when making calls on behalf of your own Mollie account), please use:

const mollieClient = createMollieClient({ accessToken: '…' });

And please let me know if you run into any other complications.