From b87ee4c15920f1d8f0959029490404cfd162de17 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 9 Jan 2020 18:08:17 +0530 Subject: [PATCH] Unit test for #16148 --- tests/phpunit/api/v3/PaymentTest.php | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 9fd996d667..661fe921d6 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -484,6 +484,43 @@ class api_v3_PaymentTest extends CiviUnitTestCase { $this->validateAllPayments(); } + /** + * Test negative payment using create API. + */ + public function testRefundPayment() { + $result = $this->callAPISuccess('Contribution', 'create', [ + 'financial_type_id' => "Donation", + 'total_amount' => 100, + 'contact_id' => $this->_individualId, + ]); + $contributionID = $result['id']; + + //Refund a part of the main amount. + $this->callAPISuccess('Payment', 'create', [ + 'contribution_id' => $contributionID, + 'total_amount' => -10, + ]); + + $contribution = $this->callAPISuccessGetSingle('Contribution', [ + 'return' => ["contribution_status_id"], + 'id' => $contributionID, + ]); + //Still we've a status of Completed after refunding a partial amount. + $this->assertEquals($contribution['contribution_status'], 'Completed'); + + //Refund the complete amount. + $this->callAPISuccess('Payment', 'create', [ + 'contribution_id' => $contributionID, + 'total_amount' => -90, + ]); + $contribution = $this->callAPISuccessGetSingle('Contribution', [ + 'return' => ["contribution_status_id"], + 'id' => $contributionID, + ]); + //Assert if main contribution status is updated to "Refunded". + $this->assertEquals($contribution['contribution_status'], 'Refunded Label**'); + } + /** * Test cancel payment api * -- 2.25.1