* @param array $params
* Input parameters.
*
- * @throws API_Exception
* @return array
* Api result array
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws API_Exception
*/
function civicrm_api3_order_create($params) {
-
+ civicrm_api3_verify_one_mandatory($params, NULL, ['line_items', 'total_amount']);
$entity = NULL;
$entityIds = [];
if (!empty($params['line_items']) && is_array($params['line_items'])) {
$params['total_amount'] = [
'name' => 'total_amount',
'title' => 'Total Amount',
- 'api.required' => TRUE,
];
$params['financial_type_id'] = [
'name' => 'financial_type_id',
protected $_individualId;
protected $_financialTypeId = 1;
- protected $_apiversion;
public $debug = 0;
/**
* Setup function.
+ *
+ * @throws \CRM_Core_Exception
*/
public function setUp() {
parent::setUp();
/**
* Clean up after each test.
+ *
+ * @throws \CRM_Core_Exception
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
/**
* Test create order api for membership
+ *
+ * @throws \CRM_Core_Exception
*/
public function testAddOrderForMembership() {
$membershipType = $this->membershipTypeCreate();
$p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
- 'total_amount' => 200,
'financial_type_id' => 'Event Fee',
'contribution_status_id' => 1,
];
/**
* Test create order api for participant
+ *
+ * @throws \CRM_Core_Exception
*/
public function testAddOrderForParticipant() {
$event = $this->eventCreate();
}
/**
- * @expectedException CiviCRM_API3_Exception
- * @expectedExceptionMessage Line item total doesn't match with total amount.
+ * Test an exception is thrown if line items do not add up to total_amount, no tax.
*/
public function testCreateOrderIfTotalAmountDoesNotMatchLineItemsAmountsIfNoTaxSupplied() {
$params = [
],
];
- civicrm_api3('Order', 'create', $params);
+ $this->callAPIFailure('Order', 'create', $params, 'Line item total doesn\'t match with total amount');
}
/**
- * @expectedException CiviCRM_API3_Exception
- * @expectedExceptionMessage Line item total doesn't match with total amount.
+ * Test an exception is thrown if line items do not add up to total_amount, with tax.
*/
public function testCreateOrderIfTotalAmountDoesNotMatchLineItemsAmountsIfTaxSupplied() {
$params = [
],
];
- civicrm_api3('Order', 'create', $params);
+ $this->callAPIFailure('Order', 'create', $params, 'Line item total doesn\'t match with total amount.');
}
public function testCreateOrderIfTotalAmountDoesMatchLineItemsAmountsAndTaxSupplied() {
],
];
- $order = civicrm_api3('Order', 'create', $params);
+ $order = $this->callAPISuccess('Order', 'create', $params);
$this->assertEquals(1, $order['count']);
}