Skip to content
Snippets Groups Projects
Commit 6a324107 authored by Jamie McClelland's avatar Jamie McClelland Committed by mattwire
Browse files

new api method to retry all charges that are not updated in Civi

parent bf2c6e90
No related branches found
No related tags found
1 merge request!1526.6 to master
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This api retries all non-processed webhooks for a given payment processor.
*
/**
* Stripe.Ipn API specification
*
* @param array $spec description of fields supported by this API call
*/
function _civicrm_api3_stripe_Retryall_spec(&$spec) {
$spec['ppid']['title'] = ts("The payment processor to use.");
$spec['ppid']['required'] = TRUE;
$spec['limit']['title'] = ts("Limit the number of unprocessed events to retry.");
$spec['limit']['api.default'] = 25;
}
/**
* Stripe.Retryall API
*
* @param array $params
*
* @return array
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_stripe_Retryall($params) {
$limit = $params['limit'];
$ppid = $params['ppid'];
$params = [
'ppid' => $ppid,
'limit' => $limit,
'filter_processed' => 1,
'source' => 'systemlog'
];
$values = [];
$results = civicrm_api3('Stripe', 'ListEvents', $params);
foreach($results['values'] as $value) {
if (!isset($value['system_log_id'])) {
$values[] = 'system_log_id is not set for charge: ' . $value['charge'];
}
else {
$params = [
'ppid' => $ppid,
'id' => $value['system_log_id'],
'suppressreceipt' => 1,
];
$ipn_results = civicrm_api3('Stripe', 'Ipn', $params);
if ($ipn_results['is_error'] == 0) {
$values[] = 'Successfully processed charge: ' . $value['charge'];
}
else {
$values[] = 'Failed to process charge: ' . $value['charge'] . 'Results follows. ' . print_r($ipn_results, TRUE);
}
}
}
return civicrm_api3_create_success($values);
}
......@@ -25,6 +25,10 @@ The api commands are:
* `ppid` - Use the given Payment Processor ID. By default, uses the saved, live Stripe payment processor and throws an error if there is more than one.
* `noreceipt` - Set to 1 if you want to suppress the generation of receipts or set to 0 or leave out to send receipts normally.
* `Stripe.Retryall`: Attempt to replay all charges for a given payment processor that are completed in Stripe but not completed in CiviCRM.
* `ppid` - Use the given Payment Processor ID. By default, uses the saved, live Stripe payment processor and throws an error if there is more than one.
* `limit` - Limit number of results (25 is default).
* `Stripe.Cleanup`: Cleanup and remove old database tables/fields that are no longer required.
### Import related.
......
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