diff --git a/api/v3/Stripe/Retryall.php b/api/v3/Stripe/Retryall.php new file mode 100644 index 0000000000000000000000000000000000000000..196895b308c6926d4fd743402de89101a6f5834b --- /dev/null +++ b/api/v3/Stripe/Retryall.php @@ -0,0 +1,70 @@ +<?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); +} diff --git a/docs/api.md b/docs/api.md index da15176d4433ed4bc8ed7ad82f9cfee7759dfd01..8f25d9111ea7f101b0a9727c1698266c540a9b3d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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.