return civicrm_api3_create_success($result['values'], $params, 'Order', 'delete');
}
+/**
+ * Cancel a Order.
+ *
+ * @param array $params
+ * Input parameters.
+ *
+ * @return array
+ */
+function civicrm_api3_order_cancel($params) {
+ $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
+ $params['contribution_status_id'] = array_search('Cancelled', $contributionStatuses);
+ $result = civicrm_api3('Contribution', 'create', $params);
+ if (!CRM_Utils_Array::value('is_error', $result)) {
+ CRM_Contribute_BAO_Contribution::transitionComponents($params);
+ }
+ return civicrm_api3_create_success(CRM_Utils_Array::value('values', $result), $params, 'Order', 'cancel');
+}
+
+/**
+ * Adjust Metadata for Cancel action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ * Array of parameters determined by getfields.
+ */
+function _civicrm_api3_order_cancel_spec(&$params) {
+ $params['contribution_id'] = array(
+ 'api.required' => 1 ,
+ 'title' => 'Contribution ID',
+ 'type' => CRM_Utils_Type::T_INT,
+ );
+}
+
/**
* Adjust Metadata for Create action.
*
}
}
+ /**
+ * Test cancel order api
+ */
+ public function testCancelOrder() {
+ $contribution = $this->addOrder(FALSE, 100);
+ $params = array(
+ 'contribution_id' => $contribution['id'],
+ );
+ $this->callAPISuccess('order', 'cancel', $params);
+ $order = $this->callAPISuccess('Order', 'get', $params);
+ $expectedResult = array(
+ $contribution['id'] => array(
+ 'total_amount' => 100,
+ 'contribution_id' => $contribution['id'],
+ 'contribution_status' => 'Cancelled',
+ 'net_amount' => 100,
+ ),
+ );
+ $this->checkPaymentResult($order, $expectedResult);
+ $this->callAPISuccess('Contribution', 'Delete', array(
+ 'id' => $contribution['id'],
+ ));
+ }
+
}