Skip to content

Commit

Permalink
Add ContributionRecur crud api
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 12, 2020
1 parent 8ff069d commit 43c0e07
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 68 deletions.
7 changes: 0 additions & 7 deletions Civi/Api4/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/


namespace Civi\Api4;

/**
Expand Down
7 changes: 0 additions & 7 deletions Civi/Api4/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/


namespace Civi\Api4;

/**
Expand Down
22 changes: 22 additions & 0 deletions Civi/Api4/ContributionRecur.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

namespace Civi\Api4;

/**
* ContributionRecur entity.
*
* @package Civi\Api4
*/
class ContributionRecur extends Generic\DAOEntity {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
* $Id$
*
*/


namespace Civi\Api4\Service\Spec\Provider;

use Civi\Api4\Service\Spec\RequestSpec;

/**
* Class ContributionCreationSpecProvider
*
* @package Civi\Api4\Service\Spec\Provider
*/
class ContributionCreationSpecProvider implements Generic\SpecProviderInterface {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/


namespace Civi\Api4\Service\Spec\Provider;

use Civi\Api4\Service\Spec\RequestSpec;

/**
* Class ContributionRecurCreationSpecProvider
*
* @package Civi\Api4\Service\Spec\Provider
*/
class ContributionRecurCreationSpecProvider implements Generic\SpecProviderInterface {

/**
* @inheritDoc
*/
public function modifySpec(RequestSpec $spec) {
$spec->getFieldByName('create_date')->setDefaultValue('now');
}

/**
* @inheritDoc
*/
public function applies($entity, $action) {
return $entity === 'ContributionRecur' && $action === 'create';
}

}
31 changes: 31 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3562,4 +3562,35 @@ protected function validateAllContributions() {
}
}

/**
* Generic create test.
*
* @param int $version
*
* @throws \CRM_Core_Exception
*/
protected function basicCreateTest($version){
$this->_apiversion = $version;
$result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
$this->getAndCheck($this->params, $result['id'], $this->_entity);
}

/**
* Generic delete test.
*
* @param int $version
*
* @throws \CRM_Core_Exception
*/
protected function basicDeleteTest($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
$deleteParams = ['id' => $result['id']];
$this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}

}
46 changes: 20 additions & 26 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
protected $params;
protected $id = 0;
protected $contactIds = [];
protected $_entity = 'contribution_page';
protected $_entity = 'ContributionPage';
protected $contribution_result = NULL;
protected $_priceSetParams = [];
protected $_membershipBlockAmount = 2;
Expand All @@ -40,8 +40,6 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
*/
protected $_ids = [];

public $DBResetRequired = TRUE;

/**
* Setup for test.
*
Expand Down Expand Up @@ -75,7 +73,6 @@ public function setUp() {
* Tear down after test.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function tearDown() {
foreach ($this->contactIds as $id) {
Expand All @@ -94,11 +91,7 @@ public function tearDown() {
* @throws \CRM_Core_Exception
*/
public function testCreateContributionPage($version) {
$this->_apiversion = $version;
$result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
$this->getAndCheck($this->params, $result['id'], $this->_entity);
$this->basicCreateTest($version);
}

/**
Expand Down Expand Up @@ -148,12 +141,7 @@ public function testGetContributionPageByAmount() {
* @throws \CRM_Core_Exception
*/
public function testDeleteContributionPage($version) {
$this->_apiversion = $version;
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
$deleteParams = ['id' => $createResult['id']];
$this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
$this->basicDeleteTest($version);
}

/**
Expand Down Expand Up @@ -183,6 +171,8 @@ public function testSubmit() {

/**
* Test form submission with basic price set.
*
* @throws \CRM_Core_Exception
*/
public function testSubmitZeroDollar() {
$this->setUpContributionPage();
Expand Down Expand Up @@ -247,6 +237,8 @@ public function testSubmitNewBillingNameData() {
/**
* Test form submission with billing first & last name where the contact does
* otherwise have one and should not be overwritten.
*
* @throws \CRM_Core_Exception
*/
public function testSubmitNewBillingNameDoNotOverwrite() {
$this->setUpContributionPage();
Expand Down Expand Up @@ -582,10 +574,7 @@ public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() {
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', [
'return' => ["id"],
'name' => "Pending",
]);
$pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['return' => ['id'], 'name' => 'Pending']);
$this->assertEquals($membership['status_id'], $pendingStatus['id']);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
}
Expand Down Expand Up @@ -904,6 +893,8 @@ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantP
* processor (IATS style - denoted by returning trxn_id)
* - the first creates a new membership, completed contribution, in progress recurring. Check these
* - create another - end date should be extended
*
* @throws \CRM_Core_Exception
*/
public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentMonth() {
$this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'month', 'recur_frequency_unit' => 'month']);
Expand Down Expand Up @@ -1387,7 +1378,7 @@ public function testSubmitMembershipIsSeparatePaymentNotRecur() {
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
$dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);

//Sumbit payment with recur disabled.
//Submit payment with recur disabled.
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
Expand Down Expand Up @@ -1851,7 +1842,7 @@ public function testSubmitPledgePayment() {

$this->assertEquals(100.00, $contribution['total_amount']);
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
$this->assertEquals($pledgePayment['values'][2]['status_id'], 1, "This pledge payment should have been completed");
$this->assertEquals($pledgePayment['values'][2]['status_id'], 1, 'This pledge payment should have been completed');
$this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']);
}

Expand Down Expand Up @@ -1891,7 +1882,7 @@ public function testSubmitContributionPageWithPriceSet($thousandSeparator) {
$this->assertEquals(3, $lineItems['count']);
$totalLineAmount = 0;
foreach ($lineItems['values'] as $lineItem) {
$totalLineAmount = $totalLineAmount + $lineItem['line_total'];
$totalLineAmount += $lineItem['line_total'];
}
$this->assertEquals(80, $totalLineAmount);
}
Expand Down Expand Up @@ -1946,7 +1937,7 @@ public function testSubmitContributionPageWithPriceSetQuantity($thousandSeparato
$financialType = $this->createFinancialType();
$financialTypeId = $financialType['id'];
// This function sets the Tax Rate at 10% - it currently has no way to pass Tax Rate into it - so let's work with 10%
$this->relationForFinancialTypeWithFinancialAccount($financialType['id'], 5);
$this->relationForFinancialTypeWithFinancialAccount($financialType['id']);

$this->setUpContributionPage();
$submitParams = [
Expand All @@ -1966,7 +1957,7 @@ public function testSubmitContributionPageWithPriceSetQuantity($thousandSeparato
'label' => 'Printing Rights',
'html_type' => 'Text',
]);
$priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
$this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Printing Rights',
Expand Down Expand Up @@ -2019,6 +2010,8 @@ public function testValidate() {
*
* For example Paypal Checkout will replace the confirm button with it's own but we are able to validate
* before paypal launches it's modal. In this case the $_REQUEST is post but we need validation to succeed.
*
* @throws \CRM_Core_Exception
*/
public function testValidatePost() {
$_SERVER['REQUEST_METHOD'] = 'POST';
Expand All @@ -2030,6 +2023,8 @@ public function testValidatePost() {

/**
* Test that an error is generated if required fields are not submitted.
*
* @throws \CRM_Core_Exception
*/
public function testValidateOutputOnMissingRecurFields() {
$this->params['is_recur_interval'] = 1;
Expand Down Expand Up @@ -2075,14 +2070,13 @@ public function hook_civicrm_alterPaymentProcessorParams($paymentObj, &$rawParam
protected function getBasicSubmitParams() {
$priceFieldID = reset($this->_ids['price_field']);
$priceFieldValueID = reset($this->_ids['price_field_value']);
$submitParams = [
return [
'price_' . $priceFieldID => $priceFieldValueID,
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'priceSetId' => $this->_ids['price_set'][0],
'payment_processor_id' => 0,
];
return $submitParams;
}

}
Loading

0 comments on commit 43c0e07

Please sign in to comment.