return $clients;
}
+
+ /**
+ * Get options for a given case field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param String $fieldName
+ * @param String $context: @see CRM_Core_DAO::buildOptionsContext
+ * @param Array $props: whatever is known about this dao object
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $className = __CLASS__;
+ $params = array();
+ switch ($fieldName) {
+ // This field is not part of this object but the api supports it
+ case 'medium_id':
+ $className = 'CRM_Activity_BAO_Activity';
+ break;
+ }
+ return CRM_Core_PseudoConstant::get($className, $fieldName, $params, $context);
+ }
}
self::deleteContribution($contribution->id);
}
}
+
+ /**
+ * Get options for a given contribution field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param String $fieldName
+ * @param String $context: @see CRM_Core_DAO::buildOptionsContext
+ * @param Array $props: whatever is known about this dao object
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $className = __CLASS__;
+ $params = array();
+ switch ($fieldName) {
+ // This field is not part of this object but the api supports it
+ case 'payment_processor':
+ $className = 'CRM_Contribute_BAO_ContributionPage';
+ // Filter results by contribution page
+ if (!empty($props['contribution_page_id'])) {
+ $page = civicrm_api('contribution_page', 'getsingle', array('version' => 3, 'id' => ($props['contribution_page_id'])));
+ $types = (array) CRM_Utils_Array::value('payment_processor', $page, 0);
+ $params['condition'] = 'id IN (' . implode(',', $types) . ')';
+ }
+ }
+ return CRM_Core_PseudoConstant::get($className, $fieldName, $params, $context);
+ }
}
+
+
return array();
}
+/**
+ * Adjust Metadata for Transact action
+ *
+ * The metadata is used for setting defaults, documentation & validation
+ * @param array $params array or parameters determined by getfields
+ */
+function _civicrm_api3_contribution_transact_spec(&$params) {
+ // This function calls create, so should inherit create spec
+ _civicrm_api3_contribution_create_spec($params);
+ $params['receive_date']['api.default'] = 'now';
+}
+
/**
* Process a transaction and record it against the contact.
*
*
*/
function civicrm_api3_contribution_transact($params) {
- $required = array('amount');
- foreach ($required as $key) {
- if (!isset($params[$key])) {
- return civicrm_api3_create_error("Missing parameter $key: civicrm_contribute_transact() requires a parameter '$key'.");
- }
- }
-
- // allow people to omit some values for convenience
- // 'payment_processor_id' => NULL /* we could retrieve the default processor here, but only if it's missing to avoid an extra lookup */
- $defaults = array(
- 'payment_processor_mode' => 'live',
- );
- $params = array_merge($defaults, $params);
-
- // clean up / adjust some values which
- if (!isset($params['total_amount'])) {
- $params['total_amount'] = $params['amount'];
- }
+ // Set some params specific to payment processing
+ $params['payment_processor_mode'] = empty($params['is_test']) ? 'live' : 'test';
+ $params['amount'] = $params['total_amount'];
if (!isset($params['net_amount'])) {
$params['net_amount'] = $params['amount'];
}
- if (!isset($params['receive_date'])) {
- $params['receive_date'] = date('Y-m-d');
- }
if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
$params['invoiceID'] = $params['invoice_id'];
}
- $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor_id'], $params['payment_processor_mode']);
+ $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor'], $params['payment_processor_mode']);
if (civicrm_error($paymentProcessor)) {
return $paymentProcessor;
}
- $payment = &CRM_Core_Payment::singleton($params['payment_processor_mode'], $paymentProcessor);
+ $payment = CRM_Core_Payment::singleton($params['payment_processor_mode'], $paymentProcessor);
if (civicrm_error($payment)) {
return $payment;
}
// but actually, $payment->doDirectPayment() doesn't return a
// CRM_Core_Error by itself
- if (get_class($transaction) == 'CRM_Core_Error') {
+ if (is_object($transaction) && get_class($transaction) == 'CRM_Core_Error') {
$errs = $transaction->getErrors();
if (!empty($errs)) {
$last_error = array_shift($errs);
}
}
- $contribution = civicrm_api('contribution', 'create', $params);
- return $contribution['values'];
+ return civicrm_api('contribution', 'create', $params);
}
/**
* Send a contribution confirmation (receipt or invoice)