Skip to content

Commit

Permalink
make new PP #498 more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Nov 6, 2018
1 parent 976e755 commit cb8830e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CRM/Core/Payment/SDD.php
Expand Up @@ -38,7 +38,15 @@ function __construct($mode, &$paymentProcessor) {
$this->_paymentProcessor = $paymentProcessor;
$this->_processorName = ts('SEPA Direct Debit', array('domain' => 'org.project60.sepa'));
$this->_creditorId = $paymentProcessor['user_name'];
$this->_creditor = civicrm_api3('SepaCreditor', 'getsingle', array('id' => $this->_creditorId));
try {
$this->_creditor = civicrm_api3('SepaCreditor', 'getsingle', array('id' => $this->_creditorId));
} catch (Exception $ex) {
// probably no creditor set, or creditor has been deleted - use default
CRM_Core_Error::debug_log_message("org.project60.sepa: creditor [{$paymentProcessor['user_name']}] not found, SDD using default/any.");
$default_creditor_id = (int) CRM_Sepa_Logic_Settings::getSetting('batching_default_creditor');
$creditors = civicrm_api3('SepaCreditor', 'get', array('id' => $default_creditor_id));
$this->_creditor = reset($creditors['values']);
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion CRM/Core/Payment/SDDNG.php
Expand Up @@ -143,7 +143,15 @@ protected function getCreditor() {
if (!$this->_creditor) {
$pp = $this->getPaymentProcessor();
$creditor_id = $pp['user_name'];
$this->_creditor = civicrm_api3('SepaCreditor', 'getsingle', array('id' => $creditor_id));
try {
$this->_creditor = civicrm_api3('SepaCreditor', 'getsingle', array('id' => $creditor_id));
} catch (Exception $ex) {
// probably no creditor set, or creditor has been deleted - use default
CRM_Core_Error::debug_log_message("org.project60.sepa: creditor [{$creditor_id}] not found, SDDNG using default/any.");
$default_creditor_id = (int) CRM_Sepa_Logic_Settings::getSetting('batching_default_creditor');
$creditors = civicrm_api3('SepaCreditor', 'get', array('id' => $default_creditor_id));
$this->_creditor = reset($creditors['values']);
}
}
return $this->_creditor;
}
Expand Down
13 changes: 13 additions & 0 deletions CRM/Sepa/Upgrader.php
Expand Up @@ -172,5 +172,18 @@ public function upgrade_1412() {

return TRUE;
}

/**
* Fixes the damages caused by SEPA-514
*
* @return TRUE on success
* @throws Exception
*/
public function upgrade_1413() {
$this->ctx->log->info('Applying update 1413');
// make sure the new payment processor is available
sepa_pp_enable();
return TRUE;
}
}

8 changes: 6 additions & 2 deletions sepa_pp_sdd.php
Expand Up @@ -70,6 +70,10 @@ function sepa_pp_buildForm ( $formName, &$form ) {
$creditors = $creditors['values'];

$test_creditors = civicrm_api3('SepaCreditor', 'get', array('category'=>'TEST'));
if (empty($test_creditors['values'])) {
// no test creditors? just offer the regular ones, selecting none is not good
$test_creditors = civicrm_api3('SepaCreditor', 'get');
}
$test_creditors = $test_creditors['values'];

// use settings
Expand Down Expand Up @@ -281,11 +285,11 @@ function sepa_pp_enable() {
}

// INSTALL NEW/NG PROCESSOR
$sdd_pp_ng = civicrm_api3('PaymentProcessorType', 'get', array('name' => 'SEPA_Direct_Debit_NG'));
$sdd_pp_ng = civicrm_api3('PaymentProcessorType', 'get', array('name' => PP_SDD_PROCESSOR_TYPE_NEW));
if (empty($sdd_pp_ng['id'])) {
// doesn't exist yet => create
$payment_processor_data = array(
"name" => "SEPA_Direct_Debit_NG",
"name" => PP_SDD_PROCESSOR_TYPE_NEW,
"title" => ts("SEPA Direct Debit (NEW)"),
"description" => ts("Refactored Payment processor for the 'Single European Payement Area' (SEPA)."),
"is_active" => 1,
Expand Down

0 comments on commit cb8830e

Please sign in to comment.