Skip to content

Commit

Permalink
Merge pull request #616 from Mangopay/feature/handle-partial-refund
Browse files Browse the repository at this point in the history
feature/ Handle partial refund
  • Loading branch information
silvianagh authored Nov 9, 2023
2 parents 333ebfd + fda05c8 commit 66e15dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/Cases/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,26 @@ protected function getNewRefundForPayIn($payIn)
return $this->_api->PayIns->CreateRefund($payIn->Id, $refund);
}

/**
* Creates refund object for PayIn
* @return \MangoPay\Refund
*/
protected function getPartialRefundForPayIn($payIn)
{
$user = $this->getJohn();

$refund = new \MangoPay\Refund();
$refund->AuthorId = $user->Id;
$refund->DebitedFunds = new \MangoPay\Money();
$refund->DebitedFunds->Amount = 100;
$refund->DebitedFunds->Currency = $payIn->DebitedFunds->Currency;
$refund->Fees = new \MangoPay\Money();
$refund->Fees->Amount = 10;
$refund->Fees->Currency = $payIn->Fees->Currency;

return $this->_api->PayIns->CreateRefund($payIn->Id, $refund);
}

/**
* Creates card registration object
* @return \MangoPay\CardRegistration
Expand Down
16 changes: 16 additions & 0 deletions tests/Cases/PayInsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ public function test_PayIns_CreateRefund_CardDirect()
$this->assertInstanceOf('\MangoPay\RefundReasonDetails', $refund->RefundReason);
}

public function test_PayIns_CreatePartialRefund_CardDirect()
{
$payIn = $this->getNewPayInCardDirect();
$wallet = $this->getJohnsWalletWithMoney();
$walletBefore = $this->_api->Wallets->Get($wallet->Id);

$refund = $this->getPartialRefundForPayIn($payIn);
$walletAfter = $this->_api->Wallets->Get($wallet->Id);

$this->assertTrue($refund->Id > 0);
$this->assertEquals($walletAfter->Balance->Amount, $walletBefore->Balance->Amount - $refund->DebitedFunds->Amount);
$this->assertEquals('PAYOUT', $refund->Type);
$this->assertEquals('REFUND', $refund->Nature);
$this->assertInstanceOf('\MangoPay\RefundReasonDetails', $refund->RefundReason);
}

public function test_PayIns_PreAuthorizedDirect()
{
$cardPreAuthorization = $this->getJohnsCardPreAuthorization();
Expand Down

0 comments on commit 66e15dd

Please sign in to comment.