Mangopay / mangopay2-php-sdk

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

transfer money from User wallet to Client Wallet #91

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi, I use mangopay on my marketplace. I would like to add some "Bonus" into this marketplace. These bonus allows users to improve their visibility on my website. To have an access to this Bonus, Users have to pay.

Let's take an example: Bonus 1 = 4.99€

When a User choose the Bonus 1, my App create a Pay-IN with: amount = 4.99€ fees = 0€ and it works

In this case, I get the whole amount, not fees, but I didn't find how to create a "transfer" from the User's Wallet to my Client Wallet.

Is there a solution ? Thx.

PhentomPT commented 8 years ago

Hey, hope this helps

//Transfer between wallets
$transfer = new MangoPay\Transfer();
$transfer->AuthorId = $author_id;
$transfer->CreditedUserId = $credited_user_id;
$transfer->DebitedFunds->Amount = "1234";
$transfer->DebitedFunds->Currency = "EUR";
$transfer->Fees->Amount = 0;
$transfer->Fees->Currency = "EUR";
$transfer->DebitedWalletID = $debited_wallet_id; //losses the money
$transfer->CreditedWalletID = $credited_wallet_id; //gets the money
$transfer->Tag = "Custom Tag";

try {
    $mangoPay->Transfers->Create($transfer);
} 
catch (Exception $e) {
    echo "<pre>";
    var_dump($e);
    echo "</pre>";
}
ghost commented 8 years ago

Hi @PhentomPT, thanks for the help but it's not solve my problem. I know how to make a transfer between two user's wallet. But I don't know how to make a transfer between a user's wallet and my Client wallet. I don't know where the Client wallet ID is.

Client Wallet = the portfolio of the owner of the application.

PhentomPT commented 8 years ago

"a transfer between a user's wallet and my Client wallet" is the same as a normal transfer between wallets.

Do you have the client id? From that you can get his wallet(s) and then make the transfer.

$mangoPay->Users->GetWallets($userId);
ghost commented 8 years ago

Ok, I have to get the wallet linked to the ClientID. The same as the "$clientid" below ?

$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = $clientId;
$this->mangoPayApi->Config->ClientPassword = $clientPassword;
$this->mangoPayApi->Config->TemporaryFolder = '/tmp/';

So, the code looks like below:

$clientWallet= $mangoPay->Users->GetWallets($clientId);

And THEN, make a transfer between user wallet and client the client ?

//Transfer between wallets
$transfer = new MangoPay\Transfer();
$transfer->AuthorId = $author_id;
$transfer->CreditedUserId = $credited_user_id;
$transfer->DebitedFunds->Amount = "1234";
$transfer->DebitedFunds->Currency = "EUR";
$transfer->Fees->Amount = 0;
$transfer->Fees->Currency = "EUR";
$transfer->DebitedWalletID = $debited_wallet_id; //losses the money
$transfer->CreditedWalletID = $clientWallet->Id; //gets the money
$transfer->Tag = "Custom Tag";

try {
    $mangoPay->Transfers->Create($transfer);
} 
catch (Exception $e) {
    echo "<pre>";
    var_dump($e);
    echo "</pre>";
}
PhentomPT commented 8 years ago

Depending on the wallet you want to obtain you need to know the MangoPay User Id (ex: 11543411)

ghost commented 8 years ago

I know. I try to be as clear as possible.

On my marketplace, there are two possible case :

Do I have to create a User and a Wallet as if I was a simple user ? Or is there a default Wallet created for client ( app owner ) ?

PhentomPT commented 8 years ago

Oh, i got it now. I tough you already had a User. As you said you need to create a User and a Wallet for your self, since there is no default Wallet or User for the Owner (that i know of).

ghost commented 8 years ago

Okey :) thx for the help ! I'm french, sorry for my poor english ^^

PhentomPT commented 8 years ago

Sure, no problem!