Mangopay / mangopay2-php-sdk

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

can not update Bank Account active status #420

Closed sohaieb closed 3 years ago

sohaieb commented 4 years ago

Hello,

i tried to update BankAccount active status, but i could not do that, here is my code :

        $this->api->Users->GetBankAccounts($userId);
        $bankAccount = $this->api->Users->GetBankAccounts($userId)[0];
        $bankAccount = $this->api->Users->GetBankAccount($userId,$bankAccount->Id);
        $bankAccountToDeactivate = clone $bankAccount;
        $bankAccountToDeactivate->Active = false;
        /*$bk = $this->api->Users->UpdateBankAccount($userId, $bankAccount);*/
        /*dd($this->api->Users->GetBankAccount($userId,$bankAccount->Id));*/
        $bk = $this->api->Users->UpdateBankAccount($userId, $bankAccountToDeactivate);

the result of the $bk variable still containing Active = true not false

thanks

sohaieb commented 4 years ago

Any updates please about my topic ??

SoloJr commented 4 years ago

Hi @sohaieb

I've written some tests using your code, and the bank account deactivates.

Please check: 425

sohaieb commented 4 years ago

Hello @SoloJr , Thank you for your answer, but to add an additional information: my code wich i wrote before is used in a Laravel 5.7 project. i will re-test this again and i will give you more details about it.

sohaieb commented 3 years ago

thank you @SoloJr , to confirm, it was a problem when i wanted to retreive the last created BankAccount, so my fault is that i'm getting the first account bank wich is Disabled instead of getting the last created BankAccount wich is Enabled , here is my bad and correct code s now : The problem was here :

        $this->api->Users->GetBankAccounts($userId);
        $bankAccount = $this->api->Users->GetBankAccounts($userId)[0];
        $bankAccount = $this->api->Users->GetBankAccount($userId,$bankAccount->Id);

The correction is here:

       $countBanks = count($this->api->Users->GetBankAccounts($userId));
       $bankAccount = $this->api->Users->GetBankAccounts($userId)[$countBanks-1];