Commit dfd88148 authored by Rich's avatar Rich
Browse files

Add correction script for ills caused by issue 44

parent 9aff529a
......@@ -8,7 +8,9 @@ Note that when you upgrade you may end up with duplicate webhooks in Stripe with
* Fix Stripe create customer in test mode.
* Fix offline (live) event payments for Wordpress.
* If payment fails and we have no contribution don't crash when trying to create a note.
* Fix null dates returning as December 31, 1969.
* Fix null dates returning as December 31, 1969 or 1 Jan 1970 (depending on your
timezone) - also see the commandline script in `utils/fix-issue-44.php` to
correct your Contributions data.
* Support Drupal 8 Webform.
* Automatically manage and create webhooks.
......@@ -89,4 +91,4 @@ Make sure you run the extension upgrades immediately after updating the code. T
### Highlights:
* Fix all known "Stripe.js token was not passed".
* Tested support for Drupal 7 / Wordpress / Joomla for contributions/event payments.
* Improvements to recurring payments (though you will want to upgrade to 5.2 if using recurring payments as recurring payments has had a major rewrite for 5.2).
\ No newline at end of file
* This script will look for stripe recurring contributions with a date <2 Jan
* 1970 and will try to obtain a proper charge date for them and correct the
* Contribution records.
* Drupal users can run it like
* drush scr <scriptname>
* Limitations: it does not correct the financial records. There be dragons.
* You should have a read through the code and determine if it's what you want
* before running it.
* @see
use Stripe\Stripe;
use Stripe\Charge;
exit; // ***REMOVE THIS LINE*** but don't run this until you have understood what it does.
// This is NOT to be run from a web browser.
// Fail with 404 if not called from CLI.
if (isset($_SERVER['HTTP_PROTOCOL'])) {
header("$_SERVER[HTTP_PROTOCOL] 404 Not Found");
echo "booted ok\n";
$result = civicrm_api3('PaymentProcessor', 'get', [ 'class_name' => 'Payment_Stripe', 'is_active' => 1, ]);
$payment_processors = $result['values'];
if (empty($payment_processors)) {
echo "Failed to find payment processors\n";
$dao = CRM_Core_DAO::executeQuery('
SELECT, c.contact_id, c.total_amount, c.trxn_id, c.contribution_recur_id, cr.payment_processor_id
FROM civicrm_contribution c
INNER JOIN civicrm_contribution_recur cr ON c.contribution_recur_id =
WHERE c.contribution_status_id = 1 AND c.is_test = 0 AND c.receive_date < 19700102');
while ($dao->fetch()) {
echo "Contribution $dao->id (contact $dao->contact_id): ";
$paymentProcessor = $payment_processors[$dao->payment_processor_id] ?? NULL;
if (!$paymentProcessor) {
echo "Failed to find a stripe payment processor for recurring contrib $dao->contribution_recur_id\n";
try {
$results = Charge::retrieve(['id' => $dao->trxn_id]);
//print json_encode($results, JSON_PRETTY_PRINT);
if (empty($results->created)) {
echo " Failed to retrieve a charge created date\n";
$d = date('Y-m-d H:i:s', $results->created);
// Update database
print "Updating Contribution to date $d\n";
civicrm_api3('Contribution', 'create', [
'id' => $dao->id,
'receive_date' => $d,
} catch (Exception $e) {
echo "Failed to load Stripe charge $dao->trxn_id \n" . $e->getMessage();
echo "Done\n";
Markdown is supported
0% or .
Finish editing this message first!
Please register or to comment