Payments with a future date taken by Stripe but not recorded in Civi
Set up a basic contribution page with a pledge block, adjusting the recurring start date to a date in the future. Then make a test pledge with this page. There will be a contribution, a recurring contribution, and a pledge all with status pending.
On the future date, Stripe will dutifully process the payment and notify Civi...
StripeIPN::processEventType()
-> case 'invoice.payment_succeeded'
-> createNextContributionForRecur()
-> repeatContribution()
-> api.Contribution.repeattransaction
...and fail because repeattransaction
is looking for a completed contribution that doesn't exist.
function hook_civicrm_webhook_eventNotMatched($type, $object, $code, &$result) {
if ($type == 'stripe' && $code == 'contribution_not_found') {
try {
$crid = $object->getContributionRecurID();
$result['contribution'] = civicrm_api3('Contribution', 'getsingle', [
'contribution_status_id' => ['IN' => ['Pending']],
'contribution_recur_id' => $crid,
'contribution_test' => CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $crid, 'is_test'),
'options' => ['limit' => 1, 'sort' => 'id DESC'],
]);
}
catch (CiviCRM_API3_Exception $e) {}
}
}
This solves for client, but feel like it actually belongs in StripeIPN::getContribution()
.