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' => CRM_Utils_Array::value('contribution_id', $params, $params['id']),
+ ));
+ if ($contribution['id'] && $contribution['values'][$contribution['id']]['is_test'] == TRUE) {
+ $result = civicrm_api3('Contribution', 'delete', $params);
+ }
+ else {
+ throw new API_Exception('Could not delete Order.');
+ }
+ return civicrm_api3_create_success(CRM_Utils_Array::value('values', $result), $params, 'Order', 'delete');
+}
+
/**
* Adjust Metadata for Create action.
*
'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');
+}
));
}
+ /**
+ * 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']);
+ }
+ }
+
}