diff --git a/api/v3/Order.php b/api/v3/Order.php index 19b4eaefe206..88236aa0113a 100644 --- a/api/v3/Order.php +++ b/api/v3/Order.php @@ -117,6 +117,9 @@ function civicrm_api3_order_create($params) { } } $contributionParams = $params; + // If this is nested we need to set sequential to 0 as sequential handling is done + // in create_success & id will be miscalculated... + $contributionParams['sequential'] = 0; foreach ($contributionParams as $key => $value) { // Unset chained keys so the code does not attempt to do this chaining twice. // e.g if calling 'api.Payment.create' We want to finish creating the order first. diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 273c243b184b..eec92dfb82ac 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2461,10 +2461,10 @@ public function setupRecurringPaymentProcessorTransaction($recurParams = [], $co 'payment_processor_id' => $this->_paymentProcessorID, // processor provided ID - use contact ID as proxy. 'processor_id' => $this->_contactID, - 'api.contribution.create' => $contributionParams, - ], $recurParams)); + 'api.Order.create' => $contributionParams, + ], $recurParams))['values'][0]; $this->_contributionRecurID = $contributionRecur['id']; - $this->_contributionID = $contributionRecur['values']['0']['api.contribution.create']['id']; + $this->_contributionID = $contributionRecur['api.Order.create']['id']; $this->ids['Contribution'][0] = $this->_contributionID; } @@ -2496,7 +2496,6 @@ public function setupMembershipRecurringPaymentProcessorTransaction($params = [] 'receive_date' => '2019-07-25 07:34:23', ]); } - $this->setupRecurringPaymentProcessorTransaction($recurParams); $this->ids['membership'] = $this->callAPISuccess('membership', 'create', [ 'contact_id' => $this->_contactID, @@ -2505,32 +2504,33 @@ public function setupMembershipRecurringPaymentProcessorTransaction($params = [] 'format.only_id' => TRUE, 'source' => 'Payment', ]); - //CRM-15055 creates line items we don't want so get rid of them so we can set up our own line items - CRM_Core_DAO::executeQuery("TRUNCATE civicrm_line_item"); - - $this->callAPISuccess('line_item', 'create', [ - 'entity_table' => 'civicrm_membership', - 'entity_id' => $this->ids['membership'], - 'contribution_id' => $this->_contributionID, - 'label' => 'General', - 'qty' => 1, - 'unit_price' => 200, - 'line_total' => 200, - 'financial_type_id' => 1, - 'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', [ - 'return' => 'id', - 'label' => 'Membership Amount', - 'options' => ['limit' => 1, 'sort' => 'id DESC'], - ]), - 'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', [ - 'return' => 'id', - 'label' => 'General', - 'options' => ['limit' => 1, 'sort' => 'id DESC'], - ]), - ]); - $this->callAPISuccess('membership_payment', 'create', [ - 'contribution_id' => $this->_contributionID, - 'membership_id' => $this->ids['membership'], + $this->setupRecurringPaymentProcessorTransaction($recurParams, [ + 'line_items' => [ + [ + 'line_item' => [ + [ + 'entity_table' => 'civicrm_membership', + 'entity_id' => $this->ids['membership'], + 'contribution_id' => $this->_contributionID, + 'label' => 'General', + 'qty' => 1, + 'unit_price' => 200, + 'line_total' => 200, + 'financial_type_id' => 1, + 'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', [ + 'return' => 'id', + 'label' => 'Membership Amount', + 'options' => ['limit' => 1, 'sort' => 'id DESC'], + ]), + 'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', [ + 'return' => 'id', + 'label' => 'General', + 'options' => ['limit' => 1, 'sort' => 'id DESC'], + ]), + ], + ], + ], + ], ]); }