mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
553 stars 191 forks source link

Question: Split Payments #24

Closed petericebear closed 8 years ago

petericebear commented 8 years ago

Hi,

Can you explain how to use these functions from the connect Site (https://www.mollie.com/nl/connect)?

Shifted Fee Transactiekosten factureren op ander account.

Application Fee Voeg transactiekosten toe en houd direct je kosten in.

Split payments Verdeel inkomende betalingen over meerdere accounts.

Affiliate fees Verschuif een deel van de transactie naar je affiliate.

The only reference I found in the documentation was about the applicationFee (ie. https://www.mollie.com/nl/docs/reference/payments/create#pfp-params)

Is it possible to combine these? For example:

With kind regards, Peter

petericebear commented 8 years ago

Any update on this?

jeffreyvanhees commented 8 years ago

I would like to use this too for one of my projects. Is it possible to write more documentation/examples for this features?

mollierobbert commented 8 years ago

I'm sorry to inform you we've been falsely advertising this feature.

We did plan on shipping the feature with Mollie Connect, but it got delayed and hasn't been integrated as of yet. Since the demand is currently quite low, I don't think we'll build it in the near future either.

I'll make sure the feature copy is removed from the page.

To answer your second question: yes, the affiliate receives their kickback even if the payment is made via an app that charges application fees.

petericebear commented 8 years ago

Can you give an example for a (monthly/recurring) payment using a applicationfee and affiliationfee? With that I can build the rest in our framework.

mollierobbert commented 8 years ago

Application fees and kickbacks can be configured for you on account level. They cannot currently be managed via our APIs.

Please contact us at info@mollie.com or by phone if you'd like more information on either of these products.

mollierobbert commented 4 years ago

Perhaps it's a type issue. Did you try submitting applicationFee.amount.value as a string? So 'value' => '1.00' instead of 'value' => 1.00.

sandervanhooft commented 4 years ago

@Deftsoftdemo

  1. Please do not share your username/passwords on GitHub. Ever.
  2. As it is now compromised, I've asked Mollie security to reset your account credentials. Be sure to set a new password and keep it safe :).
  3. Please open a new ticket for your issue and I'll take a look with you.
sebastianbouckaert commented 4 years ago

I receive the following issue when I add applicationFee, If I do not add to my call it works, so it is clearly something with the applicationFee

{ "status": false, "message": "Error executing API call (422: Unprocessable Entity): Unable to process application request for this account. Documentation: https://docs.mollie.com/guides/handling-errors", "response": true }

applicationFee: applicationFee={"amount":{"currency":"EUR","value":"51.00"},"description":"BlaBlaBla"}

My mollie call:

$payment = $mollie->payments->create([ 'amount' => [ 'currency' => 'EUR', 'value' => (string) (sprintf("%.2f", $order_total)) ], 'description' => 'test order number', 'webhookUrl' => $url_callback, 'redirectUrl' => $url_success, 'method' => 'bancontact', 'locale' => $language_id, 'metadata' => [ "order_id" => $ref ], 'profileId' => $shop_mollie_data->profile_id, 'testmode' => true, 'applicationFee' => $applicationFee ==> If this is disabled everything works..... ]);

JorikMollie commented 4 years ago

Hi @sebastianbouckaert ,

You're probably getting the Error executing API call (422: Unprocessable Entity): Unable to process application request for this account error because you're either trying to charge application fees on a payment on the same account as the application fees would go to.

You can only charge Application Fees on payments that are created on an other account than the account the App is registered to.

sebastianbouckaert commented 4 years ago

I don't think so: |$shop_mollie_data->profile_id that id is realy of the shop that needs to be payed, so I don't know how to put the applicationFee into the API else ...

sebastianbouckaert commented 4 years ago

Problem is that I'm usiing an access token in my application to execute the api call, to us ethe application fee I have to use the API_key of each sub website, which means I have to keep all those keys in my db...

So actually it doesn't work if I use 'OAuth' but it does work if I choose for the 'API key' way of working

sandervanhooft commented 4 years ago

Creating a payment with an application fee requires you to use oAuth, because you're creating the payment on the other account's behalf. This would require you to store the oauth refresh token, so you can generate new access tokens (which you can also store until they're too old). The way OAuth is designed you shouldn't be needing the API key of the other account. In fact, you shouldn't even know it.

AFAK applicationFee will not work with any other way of authenticating.

More info about Mollie Connect / OAuth here: https://docs.mollie.com/oauth/overview .

If there are any more questions specifically about this topic, could you please open a new issue?

sebastianbouckaert commented 4 years ago

??????

I’m working Witt OAuth and the applicationFee is not working, but of I use the API key it actually works

mollierobbert commented 4 years ago

@sebastianbouckaert can you share with us what $applicationFee contains? It's unclear from your code what request you are actually sending.

sebastianbouckaert commented 4 years ago

applicationFee: applicationFee={"amount":{"currency":"EUR","value":"51.00"},"description":"BlaBlaBla"}

And I have recheck the code, my call works with the API key but does not work with OAuth

mollierobbert commented 4 years ago

Can you share the actual PHP code?

If your code looks like this:

$applicationFee = '{"amount":{"currency":"EUR","value":"51.00"},"description":"BlaBlaBla"}';

$mollieApi->payments->create([
    ...
    "applicationFee" => $applicationFee
]);

Then it is indeed not gonna work, since you are passing along a string to a parameter that expects an array. Try this instead:

$applicationFee = ["amount" => ["currency" => "EUR", "value" => "51.00"], "description" => "BlaBlaBla"];
sebastianbouckaert commented 4 years ago
      $provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
              $newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);

              $mollie = new MollieApiClient();
               $mollie->setAccessToken($newAccessToken['access_token']);

              Log::debug('So far so good');
              Log::debug('cleint_id:' . env('clientId'));
              Log::debug('clientSecret:' . env('clientSecret'));
              Log::debug($shop_mollie_data->refresh_token);
              Log::debug($shop_mollie_data->profile_id);
              Log::debug('applicationFee:' . json_encode($applicationFee));
              //$mollie->setApiKey("test_Q8SHxSEFn3UthdvQauQtEtjuKhSJVP");

              $payment = $mollie->payments->create([
                'amount' => [
                  'currency' => 'EUR',
                  'value' => (string) (sprintf("%.2f", $order_total))
                ],
                'description' => ucfirst($shop->name) . ' - Order #' . $order_nm,
                'webhookUrl' => $url_callback,
                'redirectUrl' => $url_success,
                'method' => 'bancontact',
                'locale' => $language_id,
                'metadata' => [
                  "order_id" => $ref,
                  "shop id" => $shop->id

                ],
                 'profileId' => $shop_mollie_data->profile_id,
                 'testmode' => true,
               'applicationFee' =>["amount" => ["currency" => "EUR", "value" => "51.00"], "description" => "BlaBlaBla"]
              ]);

Thats the full code, same error, if I leave this out:

'applicationFee' =>["amount" => ["currency" => "EUR", "value" => "51.00"], "description" => "BlaBlaBla"]

it works....

ndijkstra commented 4 years ago

We only return the error Unable to process application request for this account if the connected account is the same as the developer account. We can't move the applicationFee to the same Mollie account so to test this you need an other Mollie account.

sebastianbouckaert commented 4 years ago

So I cannot use a developer account to test this? I'm using OAuth with a clientId and secret from my application, and that's the only way the applicationFee works, so I have no idea what to do now..

ndijkstra commented 4 years ago

You can create another Mollie account just for testing, and with that Mollie account you can create an access token.So the developer account is the Mollie Account where you created the OAuth App, and then you need a new Mollie account that you use to login as customer of your app.

sebastianbouckaert commented 4 years ago

???? Looks like I'm an idiot probably :) but But how can I make my authentication mechansism work then, now I'm using a clientId and secret which then generates an access token to make the call;

     **//OAuth app with Mollie,
              $provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
              $newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);

              $mollie = new MollieApiClient();
              $mollie->setAccessToken($newAccessToken['access_token']);**

So I do not understand what an other account has to do with this?

petericebear commented 4 years ago

I think Nick means that the account with the app contains remains the same as now. You can create a new account on mollie, which can authenticate with the connect_as_mollie button. That new account is the new customer. The new customer receives the payment, and the applicationFee will be added to your account.

I am correct Nick? If so, I will implement and test it also, because I am going to need this also. Now using stripe at the moment but prefer mollie.

sebastianbouckaert commented 4 years ago

My setup is different and I think there is the issue, for my customer I'm settings up a general platform where customers from my customer, can sell there stuff, kinda like an Amazon, and when people buy things from the site , a certain amount of the purchase is for my customer, but I get the feeling that the applicationFee is not meant for this? In my mollie account I will around 50 website profile, and those profiles will nee to pay a certain fee to my customer, which I was trying to accomplish through the applicationFee The documentation says: Adding an application fee allows you to charge the merchant for the payment and transfer this to your own account. The application fee is deducted from the payment

I mean it like booking.com it's the same principal, booking.com receives a payment for each reservation on their website.

mollierobbert commented 4 years ago

That's indeed not what application fees are for.

Application fees are for the simple use case of having an OAuth app that processes payments for other Mollie merchants, and taking a chunk out of that payment as an OAuth app fee.

For other use cases, please contact our sales department. We will be offering more advanced 'marketplace' functionality in the future.

sebastianbouckaert commented 4 years ago

So all the other need a Mollie account as well? If I speak in the example of booking.com each hotel needs a Mollie account?

ndijkstra commented 4 years ago

Yes, correct

sebastianbouckaert commented 4 years ago

So now I have several website profiles connected, stil the damn thing doesn't work. I still do not understand what I'm doing wrong:

1 Authentication:

     //OAuth app with Mollie,
              $provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
              $newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);

              $mollie = new MollieApiClient();
              $mollie->setAccessToken($newAccessToken['access_token']);
  1. Call

    $payment = $mollie->payments->create([ 'amount' => [ 'currency' => 'EUR', 'value' => (string) (sprintf("%.2f", $order_total)) ], 'description' => ucfirst($shop->name) . ' - Order #' . $order_nm, 'webhookUrl' => $url_callback, 'redirectUrl' => $url_success, 'method' => 'bancontact', 'locale' => $language_id, 'metadata' => [ "order_id" => $ref, "shop id" => $shop->id

                ],
                'profileId' => $shop_mollie_data->profile_id,
                'testmode' => true,
                'applicationFee' => $applicationFee
              ]);

    'profileId' => $shop_mollie_data->profile_id ==> this I find in my dashboard under website profiles.

But I still do not understand the comment of using another user, I'm guesing that's why the profile_id is for no ?

Because I'm using testmode ?

sebastianbouckaert commented 4 years ago

If you are using organization access tokens or are creating an OAuth app, the only mandatory extra parameter is the profileId parameter. With it, you can specify which profile the payment belongs to. Organizations can have multiple profiles for each of their websites. See Profiles API for more information.

So if the profileId is different from my profileId it should work.... but it does not

ndijkstra commented 4 years ago

Currently, you are using 1 account to do all. This is not possible.

You need 1 account for the platform, where you can create the OAuth App and where you receive the Application Fees.

You need a second account, this is the user of your platform. With this account, you need to login via the "Connect with Mollie" button in your platform. You also need to use the Profile ID of this second account. For this merchant account you can create payments using the obtained access token. If you specify the applicationFee in this payment, this appFee will get subtracted from the payment amount and will be added to your account of the platform where you created the OAuth app.

I advise you also to read this guide for some more information: https://docs.mollie.com/oauth/overview

sebastianbouckaert commented 4 years ago

What we are trying to accomplish is a platform where local stores can subscribe to. People can order on the platform for a certain local store, and the order will be delivered. form the order a certain amount needs to be payed to the platform, that is in general the setup.

So I have no idea where to place this button uberhaupt, and if I'm following you each local store will need a Mollie account, which would make it harder for the local stores to hook up to the platform

So I need just 2 accounts then, and one account needs to give concent to the one that will receive the applicationFee and that will handle the payment. But that i coverred in this piece of code normally:

       //OAuth app with Mollie,
              $provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
              $newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);
              $mollie = new MollieApiClient();
              $mollie->setAccessToken($newAccessToken['access_token']);

and then in the api call the profileId is the profile Id of the account that gave consent.

Edit:

If I'm using organization access tokens the call does work... so this is getting confusing

holtkamp commented 4 years ago

if I'm following you each local store will need a Mollie account, which would make it harder for the local stores to hook up to the platform

Indeed, each of the involved "merchants" / local stores will need to have a Mollie account.

GertGettoweb commented 4 years ago

Hey, I have an other problem. I get the message: "API call failed: Error executing API call (request): Application fee amount is invalid." And I used the example above:

$applicationFee = ["amount" => ["currency" => "EUR", "value" => "1.00"], "description" => "BlaBlaBla"];

sandervanhooft commented 4 years ago

Application fees have a maximum: https://docs.mollie.com/oauth/application-fees#maximum-application-fees .

Can you check that you're not crossing that?