Commit fcff16f1 authored by mattwire's avatar mattwire Committed by mattwire
Browse files

Catch errors processing webhooks and continue processing the list of pending webhooks

parent f7e59773
......@@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/
use Civi\Api4\PaymentprocessorWebhook;
/**
* This job performs various housekeeping actions related to the Stripe payment processor
*
......@@ -21,20 +23,20 @@
function civicrm_api3_job_process_paymentprocessor_webhooks($params) {
if ($params['delete_old'] !== 0 && !empty($params['delete_old'])) {
// Delete all locally recorded webhooks that are older than 3 months
\Civi\Api4\PaymentprocessorWebhook::delete()
PaymentprocessorWebhook::delete()
->setCheckPermissions(FALSE) // Replace with ::update(FALSE) when minversion = 5.29
->addWhere('created_date', '<', $params['delete_old'])
->execute();
}
$paymentProcessorWebhooks = \Civi\Api4\PaymentprocessorWebhook::get()
$paymentProcessorWebhooks = PaymentprocessorWebhook::get()
->setCheckPermissions(FALSE) // Replace with ::update(FALSE) when minversion = 5.29
->addWhere('processed_date', 'IS NULL')
->addWhere('status', 'IS NULL')
->execute();
$results = [];
if (!empty($paymentProcessorWebhooks->rowCount)) {
\Civi\Api4\PaymentprocessorWebhook::update()
PaymentprocessorWebhook::update()
->setCheckPermissions(FALSE) // Replace with ::update(FALSE) when minversion = 5.29
->addWhere('id', 'IN', $paymentProcessorWebhooks->column('id'))
->addValue('status', 'processing')
......@@ -45,10 +47,20 @@ function civicrm_api3_job_process_paymentprocessor_webhooks($params) {
->getById($webhook['payment_processor_id']);
switch ($paymentProcessor->getPaymentProcessor()['class_name']) {
case 'Payment_Stripe':
$results[$webhook['id']] = civicrm_api3('Stripe', 'Ipn', [
'evtid' => $webhook['event_id'],
'ppid' => $webhook['payment_processor_id']
])['values'];
try {
$results[$webhook['id']] = civicrm_api3('Stripe', 'Ipn', [
'evtid' => $webhook['event_id'],
'ppid' => $webhook['payment_processor_id']
])['values'];
}
catch (Exception $e) {
\Civi::log()->error('Error processing webhook (ID: ' . $webhook['id'] . '): ' . $e->getMessage());
PaymentprocessorWebhook::update()
->setCheckPermissions(FALSE) // Replace with ::update(FALSE) when minversion = 5.29
->addWhere('id', '=', $webhook['id'])
->addValue('status', 'error')
->execute();
}
break;
}
}
......
Markdown is supported
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