Skip to content

Commit

Permalink
Merge pull request #547 from Mangopay/feature/payout_features
Browse files Browse the repository at this point in the history
Feature/payout features
  • Loading branch information
SoloJr authored Mar 31, 2022
2 parents 1457e97 + 4e112d0 commit 44d9064
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 1 deletion.
12 changes: 12 additions & 0 deletions MangoPay/ApiPayOuts.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public function Create($payOut, $idempotencyKey = null)
return $this->CreateObject('payouts_' . $paymentKey . '_create', $payOut, '\MangoPay\PayOut', null, null, $idempotencyKey);
}

/**
* This method is used to check whether or not the destination bank is eligible for instant payout.
* @param PayOutEligibilityRequest $payOutEligibility
* @param $idempotencyKey
* @return \MangoPay\PayOutEligibilityResponse Object returned for the API
*/
public function CheckInstantPayoutEligibility($payOutEligibility, $idempotencyKey = null)
{
return $this->CreateObject('payouts_check_eligibility', $payOutEligibility,
'\MangoPay\PayOutEligibilityResponse', null, null, $idempotencyKey);
}

/**
* Get pay-out object
* @param string $payOutId PayOut identifier
Expand Down
16 changes: 16 additions & 0 deletions MangoPay/InstantPayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MangoPay;

class InstantPayout
{
/**
* @var boolean
*/
public $IsReachable;

/**
* @var FallbackReason
*/
public $UnreachableReason;
}
1 change: 1 addition & 0 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ protected function getLogger()
'payouts_bankwire_create' => ['/payouts/bankwire/', RequestType::POST],
'payouts_bankwire_get' => ['/payouts/bankwire/%s', RequestType::GET],
'payouts_get' => ['/payouts/%s', RequestType::GET],
'payouts_check_eligibility' => ['/payouts/reachability/', RequestType::POST],

'refunds_get' => ['/refunds/%s', RequestType::GET],
'refunds_get_for_repudiation' => ['/repudiations/%s/refunds', RequestType::GET],
Expand Down
53 changes: 53 additions & 0 deletions MangoPay/PayOutEligibilityRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace MangoPay;

use MangoPay\Libraries\Dto;

class PayOutEligibilityRequest extends Dto
{
/**
* A user's ID
* @var string
*/
public $AuthorId;

/**
* Information about the funds that are being debited
* @var Money
*/
public $DebitedFunds;

/**
* Information about the fees that were taken by the client for this transaction (and were hence transferred to the Client's platform wallet)
* @var Money
*/
public $Fees;

/**
* An ID of a Bank Account
* @var string
*/
public $BankAccountId;

/**
* The ID of the wallet that was debited
* @var string
*/
public $DebitedWalletId;

/**
* A custom reference you wish to appear on the user’s bank statement (your Client Name is already shown). We advise you not to add more than 12 characters.
* @var string
*/
public $BankWireRef;

/**
* Payout mode requested. May take one of the following values:
* STANDARD (value by default if no parameter is sent): a standard bank wire is requested and the processing time of the funds is about 48 hours;
* INSTANT_PAYMENT: an instant payment bank wire is requested and the processing time is within 25 seconds (subject to prerequisites);
* INSTANT_PAYMENT_ONLY: an instant payment bank wire is requested and the processing time is within 25 seconds, but if any prerequisite is not met or another problem occurs, there is no fallback: the wallet is automatically refunded and the payout is not completed.
* @var string
*/
public $PayoutModeRequested;
}
14 changes: 14 additions & 0 deletions MangoPay/PayOutEligibilityResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace MangoPay;

use MangoPay\Libraries\Dto;

class PayOutEligibilityResponse extends Dto
{
/**
* @var InstantPayout
*/
public $InstantPayout;
}

3 changes: 2 additions & 1 deletion MangoPay/PayOutPaymentDetailsBankWire.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class PayOutPaymentDetailsBankWire extends Libraries\Dto implements PayOutPaymen
public $BankWireRef;

/**
* The new parameter "PayoutModeRequested" can take two different values : "INSTANT_PAYMENT" or "STANDARD"
* The parameter "PayoutModeRequested" can take 3 different values : "STANDARD", "INSTANT_PAYMENT", "INSTANT_PAYMENT_ONLY"
*
* @var string
*/
public $PayoutModeRequested;
Expand Down
27 changes: 27 additions & 0 deletions tests/Cases/PayOutsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace MangoPay\Tests\Cases;

use MangoPay\CurrencyIso;
use MangoPay\Money;
use MangoPay\PayOutEligibilityRequest;

/**
* Tests methods for pay-outs
*/
Expand All @@ -16,6 +20,29 @@ public function test_PayOut_Create()
$this->assertInstanceOf('\MangoPay\PayOutPaymentDetailsBankWire', $payOut->MeanOfPaymentDetails);
}

public function test_PayOut_CheckEligibility()
{
$payOut = $this->getJohnsPayOutForCardDirect();

$eligibility = new PayOutEligibilityRequest();
$eligibility->AuthorId = $payOut->AuthorId;
$eligibility->DebitedFunds = new Money();
$eligibility->DebitedFunds->Amount = 10;
$eligibility->DebitedFunds->Currency = CurrencyIso::EUR;
$eligibility->PayoutModeRequested = "INSTANT_PAYMENT";
$eligibility->BankAccountId = $payOut->MeanOfPaymentDetails->BankAccountId;
$eligibility->DebitedWalletId = $payOut->DebitedWalletId;

$result = $this->_api->PayOuts->CheckInstantPayoutEligibility($eligibility);

$this->assertTrue($payOut->Id > 0);
$this->assertSame(\MangoPay\PayOutPaymentType::BankWire, $payOut->PaymentType);
$this->assertInstanceOf('\MangoPay\PayOutPaymentDetailsBankWire', $payOut->MeanOfPaymentDetails);

$this->assertNotNull($result);
$this->assertInstanceOf('\MangoPay\PayOutEligibilityResponse', $result);
}

public function test_PayOut_Get()
{
$payOut = $this->getJohnsPayOutForCardDirect();
Expand Down

0 comments on commit 44d9064

Please sign in to comment.