Skip to content

Commit

Permalink
Merge pull request #7684 from JMAConsulting/CRM-16188-3
Browse files Browse the repository at this point in the history
CRM-16188, added order api for delete action and test
  • Loading branch information
eileenmcnaughton committed Feb 9, 2016
2 parents f15eb6c + 95c4e89 commit 1c0d8fc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/v3/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ function civicrm_api3_order_create(&$params) {
return civicrm_api3_create_success(CRM_Utils_Array::value('values', $contribution), $params, 'Order', 'create');
}

/**
* Delete a Order.
*
* @param array $params
* Input parameters.
*
* @return array
*/
function civicrm_api3_order_delete($params) {
$contribution = civicrm_api3('Contribution', 'get', array(
'return' => array('is_test'),
'id' => $params['id'],
));
if ($contribution['id'] && $contribution['values'][$contribution['id']]['is_test'] == TRUE) {
$result = civicrm_api3('Contribution', 'delete', $params);
}
else {
throw new API_Exception('Only test orders can be deleted.');
}
return civicrm_api3_create_success($result['values'], $params, 'Order', 'delete');
}

/**
* Adjust Metadata for Create action.
*
Expand Down Expand Up @@ -153,3 +175,20 @@ function _civicrm_api3_order_create_spec(&$params) {
'api.required' => TRUE,
);
}

/**
* Adjust Metadata for Delete action.
*
* The metadata is used for setting defaults, documentation & validation.
*
* @param array $params
* Array of parameters determined by getfields.
*/
function _civicrm_api3_order_delete_spec(&$params) {
$params['contribution_id'] = array(
'api.required' => TRUE,
'title' => 'Contribution ID',
'type' => CRM_Utils_Type::T_INT,
);
$params['id']['api.aliases'] = array('contribution_id');
}
23 changes: 23 additions & 0 deletions tests/phpunit/api/v3/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,27 @@ public function testAddOrderWithLineItems() {
));
}

/**
* Test delete order api
*/
public function testDeleteOrder() {
$order = $this->addOrder(FALSE, 100);
$params = array(
'contribution_id' => $order['id'],
);
try {
$this->callAPISuccess('order', 'delete', $params);
$this->fail("Missed expected exception");
}
catch (Exception $expected) {
$this->callAPISuccess('Contribution', 'create', array(
'contribution_id' => $order['id'],
'is_test' => TRUE,
));
$this->callAPISuccess('order', 'delete', $params);
$order = $this->callAPISuccess('order', 'get', $params);
$this->assertEquals(0, $order['count']);
}
}

}

0 comments on commit 1c0d8fc

Please sign in to comment.