From d96830460b939da341f1d793118da22a2edf585f Mon Sep 17 00:00:00 2001 From: Paul Andrieux Date: Thu, 20 Sep 2018 10:50:26 +0200 Subject: [PATCH] Add a KYCHeper to create documents --- Helper/KYCHelper.php | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Helper/KYCHelper.php diff --git a/Helper/KYCHelper.php b/Helper/KYCHelper.php new file mode 100644 index 0000000..5fefcb3 --- /dev/null +++ b/Helper/KYCHelper.php @@ -0,0 +1,71 @@ +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; + } +}