Skip to content

Commit

Permalink
Merge pull request #70 from Troopers/feature/wallet-transfer
Browse files Browse the repository at this point in the history
add a method to transfer funds between wallets
  • Loading branch information
paulandrieux authored May 14, 2019
2 parents 3f4edd9 + 3a9bdeb commit 56c0061
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Helper/User/LegalUserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ protected function createDocument($fileContent, UserInterface $user, $type)
$kycDocument = new KycDocument();
$kycDocument->UserId = $user->getMangoUserId();
$kycDocument->Type = $type;
$kycDocument->Status = KycDocumentStatus::ValidationAsked;

$document = $this->mangopayHelper->Users->CreateKycDocument($user->getMangoUserId(), $kycDocument);

Expand All @@ -181,6 +180,9 @@ protected function createDocument($fileContent, UserInterface $user, $type)

$this->mangopayHelper->Users->CreateKycPage($user->getMangoUserId(), $document->Id, $page);

$document->Status = KycDocumentStatus::ValidationAsked;

$this->mangopayHelper->Users->UpdateKycDocument($user->getMangoUserId(), $document);

return $document;
}
Expand Down
30 changes: 30 additions & 0 deletions Helper/WalletHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Troopers\MangopayBundle\Helper;

use Doctrine\ORM\EntityManager;
use MangoPay\Money;
use MangoPay\Transfer;
use MangoPay\Wallet;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Troopers\MangopayBundle\Entity\UserInterface;
Expand Down Expand Up @@ -65,4 +67,32 @@ public function getTransactions($walletId)
{
return $this->mangopayHelper->Wallets->GetTransactions($walletId);
}

public function createTransfer(UserInterface $debitedUser, UserInterface $creditedUser, int $debitedAmount, int $feesAmount, string $tag = null, UserInterface $author = null)
{
$tranfer = new Transfer();

$tranfer->CreditedWalletId = $creditedUser->getMangoWalletId();
$tranfer->DebitedWalletId = $debitedUser->getMangoWalletId();
$tranfer->CreditedUserId = $creditedUser->getMangoUserId();

$debited = new Money();
$debited->Amount = $debitedAmount;
$debited->Currency = 'EUR';

$fees = new Money();
$fees->Amount = $feesAmount;
$fees->Currency = 'EUR';

$tranfer->DebitedFunds = $debited;
$tranfer->Fees = $fees;

$tranfer->Tag = $tag;

if ($author) {
$tranfer->AuthorId = $author->getMangoUserId();
}

return $this->mangopayHelper->Transfers->Create($tranfer);
}
}

0 comments on commit 56c0061

Please sign in to comment.