$this->is_test ? 'test' : 'live'
);
$ids['paymentProcessor'] = $paymentProcessorID;
- $this->_relatedObjects['paymentProcessor'] = &$paymentProcessor;
+ $this->_relatedObjects['paymentProcessor'] = $paymentProcessor;
}
elseif ($required) {
throw new Exception("Could not find payment processor for contribution record: " . $this->id);
public function recur(&$input, &$ids, &$objects, $first) {
$this->_isRecurring = TRUE;
$recur = &$objects['contributionRecur'];
+ $paymentProcessorObject = $objects['contribution']->_relatedObjects['paymentProcessor']['object'];
// do a subscription check
if ($recur->processor_id != $input['subscription_id']) {
$objects['contribution']->total_amount = $input['amount'];
$objects['contribution']->trxn_id = $input['trxn_id'];
- // since we have processor loaded for sure at this point,
- // check and validate gateway MD5 response if present
- $this->checkMD5($ids, $input);
+ $this->checkMD5($paymentProcessorObject, $input);
if ($input['response_code'] == 1) {
// Approved
}
/**
- * @param $ids
- * @param $input
+ * Check and validate gateway MD5 response if present.
+ *
+ * @param CRM_Core_Payment_AuthorizeNet $paymentObject
+ * @param array $input
*
* @return bool
*/
- public function checkMD5($ids, $input) {
- $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ids['paymentProcessor'],
- $input['is_test'] ? 'test' : 'live'
- );
- $paymentObject = $paymentProcessor['object'];
-
+ public function checkMD5($paymentObject, $input) {
if (!$paymentObject->checkMD5($input['MD5_Hash'], $input['trxn_id'], $input['amount'], TRUE)) {
CRM_Core_Error::debug_log_message("MD5 Verification failed.");
echo "Failure: Security verification failed<p>";
* @return array
* array of all payment processors
*/
- public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
+ public static function paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
$condition = "is_test = ";
$condition .= ($test) ? '1' : '0';
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
*/
/**
);
CRM_Financial_BAO_FinancialTypeAccount::add($values);
}
+ Civi\Payment\System::singleton()->flushProcessors();
return $processor;
}
$testDAO->delete();
$dao->delete();
+ Civi\Payment\System::singleton()->flushProcessors();
}
/**
*/
public function flushProcessors() {
$this->cache = array();
+ \CRM_Financial_BAO_PaymentProcessor::getAllPaymentProcessors(NULL, TRUE);
+ \CRM_Financial_BAO_PaymentProcessor::getAllPaymentProcessors('test', TRUE);
}
}
public function setUp() {
parent::setUp();
- $this->_paymentProcessorID = $this->paymentProcessorCreate(array(
- 'payment_processor_type_id' => 'AuthNet',
- ));
+ $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate();
$this->_contactID = $this->individualCreate();
$contributionPage = $this->callAPISuccess('contribution_page', 'create', array(
'title' => "Test Contribution Page",
public function setUp() {
parent::setUp();
- $this->paymentProcessor = new AuthorizeNet();
- $this->processorParams = $this->paymentProcessor->create();
+ $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate();
- $paymentProcessor = array(
- 'user_name' => $this->processorParams->user_name,
- 'password' => $this->processorParams->password,
- 'url_recur' => $this->processorParams->url_recur,
- 'signature' => '',
- );
-
- $this->processor = new CRM_Core_Payment_AuthorizeNet('Contribute', $paymentProcessor);
+ $this->processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
$this->_financialTypeId = 1;
// for some strange unknown reason, in batch mode this value gets set to null
'invoice_id' => $invoiceID,
'contribution_status_id' => 2,
'is_test' => 1,
- 'payment_processor_id' => $this->processorParams->id,
+ 'payment_processor_id' => $this->_paymentProcessorID,
);
$recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams);
'from_email_address' => "{$firstName}.{$lastName}@example.com",
'receive_date' => date('Ymd'),
'receipt_date_time' => '',
- 'payment_processor_id' => $this->processorParams->id,
+ 'payment_processor_id' => $this->_paymentProcessorID,
'price_set_id' => '',
'total_amount' => $amount,
'currency' => 'USD',
// turn verifySSL off
CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
- $this->processor->doDirectPayment($params);
+ $this->processor->doPayment($params);
// turn verifySSL on
CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
+++ /dev/null
-<?php
-
-/**
- * Class AuthorizeNet
- */
-class AuthorizeNet extends PHPUnit_Framework_Testcase {
- /**
- * Helper function to create
- * a payment processor of type Authorize.net
- * @return CRM_Financial_DAO_PaymentProcessor
- */
- public function create() {
-
- $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
- $paymentParams = array(
- 'name' => 'Authorize',
- 'domain_id' => CRM_Core_Config::domainID(),
- 'payment_processor_type' => 'AuthNet',
- 'is_active' => 1,
- 'is_default' => 0,
- 'is_test' => 1,
- 'user_name' => '4y5BfuW7jm',
- 'password' => '4cAmW927n8uLf5J8',
- 'url_site' => 'https://test.authorize.net/gateway/transact.dll',
- 'url_recur' => 'https://apitest.authorize.net/xml/v1/request.api',
- 'class_name' => 'Payment_AuthorizeNet',
- 'billing_mode' => 1,
- );
- $paymentProcessor->copyValues($paymentParams);
- $paymentProcessor->save();
- return $paymentProcessor;
- }
-
- /**
- * Helper function to delete a PayPal Pro
- * payment processor
- * @param int $id
- * Id of the PayPal Pro payment processor.
- * to be deleted
- * @return bool
- * true if payment processor deleted, false otherwise
- */
- public function delete($id) {
- $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
- $paymentProcessor->id = $id;
- if ($paymentProcessor->find(TRUE)) {
- $result = $paymentProcessor->delete();
- }
- return $result;
- }
-
-}
return $result['id'];
}
+ /**
+ * Create test Authorize.net instance.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function paymentProcessorAuthorizeNetCreate($params = array()) {
+ $params = array_merge(array(
+ 'name' => 'Authorize',
+ 'domain_id' => CRM_Core_Config::domainID(),
+ 'payment_processor_type_id' => 'AuthNet',
+ 'title' => 'AuthNet',
+ 'is_active' => 1,
+ 'is_default' => 0,
+ 'is_test' => 1,
+ 'is_recur' => 1,
+ 'user_name' => '4y5BfuW7jm',
+ 'password' => '4cAmW927n8uLf5J8',
+ 'url_site' => 'https://test.authorize.net/gateway/transact.dll',
+ 'url_recur' => 'https://apitest.authorize.net/xml/v1/request.api',
+ 'class_name' => 'Payment_AuthorizeNet',
+ 'billing_mode' => 1,
+ ), $params);
+
+ $result = $this->callAPISuccess('payment_processor', 'create', $params);
+ return $result['id'];
+ }
+
/**
* Create Participant.
*
/**
* Create contribution.
*
- * @param int $cID
- * Contact_id.
+ * @param int|array $params
+ * Array of parameters or Contact_id (legacy) .
* @param int $cTypeID
* Id of financial type.
* @param int $invoiceID
* @return int
* id of created contribution
*/
- public function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) {
- $params = array(
+ public function contributionCreate($params, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID
+ = 1, $isFee = TRUE) {
+ if (!is_array($params)) {
+ $params = array('contact_id' => $params);
+ }
+ $params = array_merge(array(
'domain_id' => 1,
- 'contact_id' => $cID,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
- 'financial_type_id' => empty($cTypeID) ? 1 : $cTypeID,
+ 'financial_type_id' => $cTypeID,
'payment_instrument_id' => empty($paymentInstrumentID) ? 1 : $paymentInstrumentID,
'non_deductible_amount' => 10.00,
'trxn_id' => $trxnID,
'invoice_id' => $invoiceID,
'source' => 'SSF',
'contribution_status_id' => 1,
- // 'note' => 'Donating for Nobel Cause', *Fixme
- );
+ ), $params);
if ($isFee) {
$params['fee_amount'] = 5.00;
'contact_id' => $this->_contactID,
'contribution_page_id' => $this->_contributionPageID,
'payment_processor_id' => $this->_paymentProcessorID,
+ 'is_test' => 1,
),
));
$this->_contributionRecurID = $contributionRecur['id'];
public function setupMembershipRecurringPaymentProcessorTransaction() {
$this->ids['membership_type'] = $this->membershipTypeCreate();
//create a contribution so our membership & contribution don't both have id = 1
- $this->contributionCreate($this->_contactID, 1, 'abcd', '345j');
+ $this->contributionCreate(array(
+ 'contact_id' => $this->_contactID,
+ 'is_test' => 1),
+ 1, 'abcd', '345j');
$this->setupRecurringPaymentProcessorTransaction();
$this->ids['membership'] = $this->callAPISuccess('membership', 'create', array(