Mangopay / mangopay2-php-sdk

PHP SDK for MANGOPAY
https://packagist.org/packages/mangopay/php-sdk-v2
MIT License
122 stars 133 forks source link

Create PayOut (PHP): Bad request. One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error. #414

Closed sohaieb closed 3 years ago

sohaieb commented 4 years ago

Hello,

When i wanted to perform a PayOut operation i got this error:

Bad request. One or several required parameters are missing or incorrect. 
An incorrect resource ID also raises this kind of error.

here is my PayOut object informations:

image

here is my code in Laravel (PHP):

public function createPayOut($userId, $walletId, $bankAccountId, $amount = null, $fees = null, $currency = null)
    {
        $PayOut = new PayOut();
        $PayOut->AuthorId = $userId;
        $PayOut->DebitedWalletId = $walletId;
        $this->setMoney($PayOut, $currency, $amount, 'DebitedFunds');
        if ($fees === null || $fees === 0.0) {
            $fees = $this->fees;
        }
        $this->setMoney($PayOut, $currency, $fees);
        $PayOut->PaymentType = "BANK_WIRE";
        $PayOut->MeanOfPaymentDetails = new PayOutPaymentDetailsBankWire();
        $PayOut->MeanOfPaymentDetails->BankAccountId = $bankAccountId;
        return $this->api->PayOuts->Create($PayOut);
    }
H4wKs commented 4 years ago

Looking at your dump, it look like you have an issue with your setMoney function. Instead of setting the amount, you created a new Money object for the amount, containing amount + currency.

Your dump look like this:

  +DebitedFunds: MangoPay\Money^ {#196
    +Currency: "EUR"
    +Amount: MangoPay\Money^ {#249
      +Currency: "EUR"
      +Amount: 1450

And it should look like this:

  +DebitedFunds: MangoPay\Money^ {#196
    +Currency: "EUR"
    +Amount: 1450
sohaieb commented 4 years ago

Looking at your dump, it look like you have an issue with your setMoney function. Instead of setting the amount, you created a new Money object for the amount, containing amount + currency.

Your dump look like this:

  +DebitedFunds: MangoPay\Money^ {#196
    +Currency: "EUR"
    +Amount: MangoPay\Money^ {#249
      +Currency: "EUR"
      +Amount: 1450

And it should look like this:

  +DebitedFunds: MangoPay\Money^ {#196
    +Currency: "EUR"
    +Amount: 1450

Hello Sir, I will test it with our parameters, and i will give you a feedback concerning to this issue as soon as possible.

mangomaxoasis commented 3 years ago

Feel free to reopen if needed

sohaieb commented 3 years ago

@mangomaxoasis i confirm the solution of @H4wKs , the amount was not defined correctly. thank you a lot.