Skip to content

Commit

Permalink
Add a KYCHeper to create documents
Browse files Browse the repository at this point in the history
  • Loading branch information
paulandrieux committed Sep 20, 2018
1 parent e3abdf9 commit d968304
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Helper/KYCHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Troopers\MangopayBundle\Helper;

use MangoPay\KycDocument;
use MangoPay\KycPage;
use MangoPay\Money;
use MangoPay\PayIn;
use MangoPay\PayInExecutionDetailsDirect;
use MangoPay\PayInPaymentDetailsBankWire;
use MangoPay\Wallet;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\HttpFoundation\File\File;

/**
* ref: troopers_mangopay.kyc_helper.
**/
class KYCHelper
{
protected $mangopayHelper;

public function __construct(MangopayHelper $mangopayHelper)
{
$this->mangopayHelper = $mangopayHelper;
}

/**
* Create a bankWire as discribed here: https://docs.mangopay.com/endpoints/v2/payins#e288_the-direct-debit-web-payin-object.
*
* @param Wallet $wallet
* @param $authorId
* @param $creditedUserId
* @param $amount
* @param $feesAmount
*
* @return KycDocument
*/
public function createDocument(File $file)
{
$page = new KycPage();

if (false === $file = @file_get_contents($value->getPathname(), FILE_BINARY)) {
throw new TransformationFailedException(sprintf('Unable to read the "%s" file', $value->getPathname()));
}

$page->File = base64_encode($file);

$this->mangopayHelper->KycDocuments->CreateKycDocumentConsult();
$debitedFunds = new Money();
$debitedFunds->Amount = $amount * 100;
$debitedFunds->Currency = 'EUR';
$fees = new Money();
$fees->Amount = $feesAmount;
$fees->Currency = 'EUR';
$payin = new PayIn();
$payin->CreditedWalletId = $wallet->Id;
$payin->ExecutionType = 'Direct';
$executionDetails = new PayInExecutionDetailsDirect();
$payin->ExecutionDetails = $executionDetails;
$paymentDetails = new PayInPaymentDetailsBankWire();
$paymentDetails->DeclaredDebitedFunds = $debitedFunds;
$paymentDetails->DeclaredFees = $fees;
$payin->PaymentDetails = $paymentDetails;
$payin->AuthorId = $authorId;
$payin->CreditedUserId = $creditedUserId;

$bankWire = $this->mangopayHelper->PayIns->Create($payin);

return $bankWire;
}
}

0 comments on commit d968304

Please sign in to comment.