Skip to content

Commit

Permalink
add a helper for bank wire
Browse files Browse the repository at this point in the history
  • Loading branch information
paulandrieux committed Jul 5, 2016
1 parent 043adbf commit 9b931f9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Helper/BankwireHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
namespace AppVentus\MangopayBundle\Helper;

use AppVentus\MangopayBundle\AppVentusMangopayEvents;
use AppVentus\MangopayBundle\Entity\CardPreAuthorisation;
use AppVentus\MangopayBundle\Entity\Order;
use AppVentus\MangopayBundle\Entity\UserInterface;
use AppVentus\MangopayBundle\Event\CardRegistrationEvent;
use AppVentus\MangopayBundle\Event\PayInEvent;
use AppVentus\MangopayBundle\Event\PreAuthorisationEvent;
use AppVentus\MangopayBundle\Exception\MongopayPayInCreationException;
use MangoPay\CardPreAuthorization;
use MangoPay\CardRegistration;
use MangoPay\Money;
use MangoPay\PayIn;
use MangoPay\PayInExecutionDetailsDirect;
use MangoPay\PayInPaymentDetailsBankWire;
use MangoPay\PayInPaymentDetailsPreAuthorized;
use MangoPay\User;
use MangoPay\Wallet;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
*
* ref: appventus_mangopay.bankwire_helper
*
**/
class BankwireHelper
{
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 PayIn
*/
public function bankwireToWallet(Wallet $wallet, $authorId, $creditedUserId, $amount, $feesAmount)
{
$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;
}

}
5 changes: 5 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
appventus_mangopay.mango_api.class: "AppVentus\\MangopayBundle\\Helper\\MangopayHelper"
appventus_mangopay.payment_helper.class: "AppVentus\\MangopayBundle\\Helper\\PaymentHelper"
appventus_mangopay.payment_direct_helper.class: "AppVentus\\MangopayBundle\\Helper\\PaymentDirectHelper"
appventus_mangopay.bankwire_helper.class: "AppVentus\\MangopayBundle\\Helper\\BankwireHelper"
appventus_mangopay.user_helper.class: "AppVentus\\MangopayBundle\\Helper\\UserHelper"
appventus_mangopay.bank_information_helper.class: "AppVentus\\MangopayBundle\\Helper\\BankInformationHelper"
appventus_mangopay.wallet_helper.class: "AppVentus\\MangopayBundle\\Helper\\WalletHelper"
Expand Down Expand Up @@ -51,6 +52,10 @@ services:
- @appventus_mangopay.mango_api
- @router
- "@event_dispatcher"
appventus_mangopay.bankwire_helper:
class: %appventus_mangopay.bankwire_helper.class%
arguments:
- @appventus_mangopay.mango_api

appventus_mangopay.form.card:
class: %appventus_mangopay.form.card%
Expand Down

0 comments on commit 9b931f9

Please sign in to comment.