/** * Takes a bunch of params that are needed to match certain criteria and * retrieves the relevant objects. Typically the valid params are only * contact_id. We'll tweak this function to be more full featured over a period * of time. This is the inverse function of create. It also stores all the retrieved * values in the default array * * @param array $params (reference ) an assoc array of name/value pairs * @param array $defaults (reference ) an assoc array to hold the flattened values * * @return object CRM_Core_BAO_LocaationType object on success, null otherwise * @access public * @static */ static function retrieve(&$params, &$defaults) { $paymentProcessorType = new CRM_Core_DAO_PaymentProcessorType(); $paymentProcessorType->copyValues($params); if ($paymentProcessorType->find(true)) { CRM_Core_DAO::storeValues($paymentProcessorType, $defaults); return $paymentProcessorType; } return null; }
/** * Function to add the payment-processor type in the db * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Core_DAO_PaymentProcessorType * @access public * @static * */ static function create(&$params) { $paymentProcessorType = new CRM_Core_DAO_PaymentProcessorType(); $paymentProcessorType->copyValues($params); /* // adapted from CRM_Core_Extensions_Payment::install foreach (array( 'class_name', 'title', 'name', 'description', 'user_name_label', 'password_label', 'signature_label', 'subject_label', 'url_site_default', 'url_api_default', 'url_recur_default', 'url_site_test_default', 'url_api_test_default', 'url_recur_test_default', 'url_button_default', 'url_button_test_default', 'billing_mode', 'is_recur', 'payment_type' ) as $trimmable) { if (isset($paymentProcessorType->{$trimmable})) { $paymentProcessorType->{$trimmable} = trim($paymentProcessorType->{$trimmable}); } } */ if (isset($paymentProcessorType->billing_mode)) { // ugh unidirectional manipulation if (!is_numeric($paymentProcessorType->billing_mode)) { $billingModes = array_flip(CRM_Core_PseudoConstant::billingMode()); if (array_key_exists($paymentProcessorType->billing_mode, $billingModes)) { $paymentProcessorType->billing_mode = $billingModes[$paymentProcessorType->billing_mode]; } } if (!array_key_exists($paymentProcessorType->billing_mode, CRM_Core_PseudoConstant::billingMode())) { throw new Exception("Unrecognized billing_mode"); } } // FIXME handle is_default if (!empty($paymentProcessorType->id)) { $ppByName = self::getAllPaymentProcessorTypes('name'); if (array_key_exists($paymentProcessorType->name, $ppByName)) { if ($ppByName[$paymentProcessorType->name] != $paymentProcessorType->id) { CRM_Core_Error::fatal('This payment processor type already exists.'); } } } return $paymentProcessorType->save(); }