Commit ca4e19a9 authored by capo's avatar capo
Browse files

Fix #8: can't change billing details

parent 3e1ec15e
......@@ -1152,7 +1152,7 @@ UPDATE " . CRM_Smartdebit_Base::TABLENAME . " SET
// Update the cached mandate
$params = [
'trxn_id' => $smartDebitParams['reference_number'],
'trxn_id' => $smartDebitParams['variable_ddi[reference_number]'],
'refresh' => TRUE,
];
CRM_Smartdebit_Mandates::getbyReference($params);
......
......@@ -211,7 +211,7 @@ class CRM_Smartdebit_Api {
case 'PUT':
$options[CURLOPT_CUSTOMREQUEST] = 'PUT';
$url .= '?' . $data;
$options[CURLOPT_POSTFIELDS] = $data;
// curl_setopt($curlSession, CURLOPT_POSTFIELDS, http_build_query($data));
break;
}
......
......@@ -239,3 +239,64 @@ function _civicrm_api3_smartdebit_clearcache_spec(&$spec) {
$spec['collections']['title'] = 'Clear cached collections';
$spec['collections']['type'] = CRM_Utils_Type::T_BOOLEAN;
}
/**
* Populates the processor_id field if its empty. It fills the field
* with the value of the trxn_id.
*
* @see https://lab.civicrm.org/extensions/smartdebit/-/issues/8
*/
function civicrm_api3_smartdebit_populate_processor_id($params) {
$processors = civicrm_api3('PaymentProcessor', 'get', [
'payment_processor_type_id' => 'Smart_Debit',
'return' => ['id'],
]);
$paymentProcessorIds = array_column($processors['values'], 'id');
$contributions = civicrm_api3('ContributionRecur', 'get', [
'payment_processor_id' => $paymentProcessorIds,
'processor_id' => ['IS NULL' => 1],
'trxn_id' => ['IS NOT NULL' => 1],
'return' => ['trxn_id'],
]);
if ($contributions['count'] == 0) {
return civicrm_api3_create_success(
[
'payment_processor_ids' => $paymentProcessorIds,
'fixable_count' => 0,
'fixed_ids' => [],
'fixed_count' => 0,
],
$params,
'Smartdebit',
'populate_processor_id'
);
}
$fixedIds = [];
foreach ($contributions['values'] as $contribution) {
$fixed = civicrm_api3('ContributionRecur', 'create', [
'id' => $contribution['id'],
'processor_id' => $contribution['trxn_id'],
]);
if ($fixed['is_error'] == 0) {
$fixedIds[] = $fixed['id'];
}
}
return civicrm_api3_create_success(
[
'payment_processor_ids' => $paymentProcessorIds,
'fixable_count' => $contributions['count'],
'fixed_ids' => $fixedIds,
'fixed_count' => count($fixedIds),
],
$params,
'Smartdebit',
'populate_processor_id'
);
}
\ No newline at end of file
......@@ -49,3 +49,10 @@ Get the number of collections in the database.
#### Smartdebit.retrievecollectionreports
Retrieve collection reports from Smartdebit.
#### Smartdebit.populate_processor_id
Populates the processor_id field if its empty. It fills the field
with the value of the trxn_id.
As described in [#8](https://lab.civicrm.org/extensions/smartdebit/-/issues/8).
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment