Skip to content
Snippets Groups Projects
Commit 37ab0f41 authored by mattwire's avatar mattwire
Browse files

Add Mjwshared.Notificationretry API

parent 74aa8723
No related branches found
No related tags found
No related merge requests found
...@@ -23,11 +23,8 @@ function civicrm_api3_contribution_getbalance($params) { ...@@ -23,11 +23,8 @@ function civicrm_api3_contribution_getbalance($params) {
} }
/** /**
* Action payment.
*
* @param array $params * @param array $params
* *
* @return array
*/ */
function _civicrm_api3_contribution_getbalance_spec(&$params) { function _civicrm_api3_contribution_getbalance_spec(&$params) {
$idField = civicrm_api3('Contribution', 'getfield', [ $idField = civicrm_api3('Contribution', 'getfield', [
......
<?php
/**
* @param array $params
* Array of parameters determined by getfields.
*/
function _civicrm_api3_mjwpayment_notificationretry_spec(&$params) {
$params = [
'system_log_id' => [
'type' => CRM_Utils_Type::T_INT,
'title' => 'System Log ID',
],
];
}
/**
* Process incoming payment notification
*
* @param array $params
*
* @return array
*/
function civicrm_api3_mjwpayment_notificationretry($params) {
if (!empty($params['system_log_id'])) {
// lets replace params with this rather than allow altering
$logEntry = civicrm_api3('system_log', 'getsingle', ['id' => $params['system_log_id'], 'return' => ['context', 'message']]);
}
$dataRaw = $logEntry['context'];
if (substr($logEntry['message'], 0, 34) === 'payment_notification processor_id=') {
$paymentProcessorId = substr($logEntry['message'], 34);
$paymentProcessorType = civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $paymentProcessorId]);
}
else {
throw new API_Exception('Unsupported payment processor');
}
$processorClassName = "CRM_Core_{$paymentProcessorType['class_name']}";
if (!method_exists($processorClassName, 'processPaymentNotification')) {
throw new API_Exception('Unsupported payment processor');
}
$result = FALSE;
$errorMessage = 'try checking the logs for errors';
try {
$result = $processorClassName::processPaymentNotification($paymentProcessorId, $dataRaw, FALSE);
}
catch (Exception $e) {
$errorMessage = $e->getMessage();
}
if ($result) {
return civicrm_api3_create_success(1, $params, 'Mjwpayment', 'Notificationretry');
}
return civicrm_api3_create_error("Failed to process notification - {$errorMessage}");
}
# API (v3)
This extension comes with several APIs to help you troubleshoot problems. These can be run via /civicrm/api or via drush if you are using Drupal (drush cvapi Mjwpayment.XXX).
### Mjwpayment.notificationretry
For supported payment processors (ie. those that use Mjwshared) you can retry IPN notifications using this API.
#### Parameters
* `system_log_id`: The stored notification log entry to retry. Find using SystemLog.get API.
site_name: MJWShared (Extension containing shared code used by MJW extensions)
repo_url: https://lab.civicrm.org/extensions/mjwshared
theme:
name: material
markdown_extensions:
- attr_list
- admonition
- def_list
- codehilite
- toc:
permalink: true
- pymdownx.superfences
- pymdownx.inlinehilite
- pymdownx.tilde
- pymdownx.betterem
- pymdownx.mark
nav:
- Overview: index.md
- API: api.md
- Release Notes: releasenotes.md
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment