Commit 542a0f05 authored by Jamie McClelland's avatar Jamie McClelland Committed by mattwire

provide additional information about stripe events

At some point it would be nice to offer a web ui for users
to review recent events and try to "repair" any that did not
go through properly using the import apis. This is a pre-cursor
to that, which provides additional information on which parts
of the event did not get properly added to Civi.
parent 2c7e1939
......@@ -228,17 +228,49 @@ function civicrm_api3_stripe_Listevents($params) {
$item['subscription'] = $data['data']['object']->subscription;
$item['total'] = $data['data']['object']->total;
// Check if this is in the contributions table.
// We will populate several additional fields based on whether any
// of this data has been entered into CiviCRM.
$item['contact_id'] = NULL;
$item['contribution_recur_id'] = NULL;
$item['contribution_recur_status_id'] = NULL;
$item['contribution_id'] = NULL;
$item['contribution_status_id'] = NULL;
$item['processed'] = 'no';
// Check if the customer is in the stripe customer table.
$results = civicrm_api3('StripeCustomer', 'get', [ 'id' => $data['data']['object']->customer]);
if ($results['count'] == 1) {
$value = array_pop($results['values']);
$item['contact_id'] = $value['contact_id'];
}
// Check if recurring contribution can be found.
$results = civicrm_api3('ContributionRecur', 'get', ['trxn_id' => $item['subscription']]);
if ($results['count'] > 0) {
$item['contribution_recur_id'] = $results['id'];
$contribution_recur = array_pop($results['values']);
$status_id = $contribution_recur['contribution_status_id'];
$item['contribution_recur_status_id'] = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $status_id);
}
// Check if charge is in the contributions table.
$contribution = NULL;
$results = civicrm_api3('Contribution', 'get', ['trxn_id' => $item['charge']]);
if ($results['count'] > 0) {
$item['processed'] = 'yes';
$contribution = array_pop($results['values']);
}
else {
// From 6.0 we store the Stripe Invoice ID in the Contribution.trxn_id if available (ie it's a recur).
// Otherwise we continue to store the Stripe Charge ID.
$results = civicrm_api3('Contribution', 'get', ['trxn_id' => $item['invoice']]);
if ($results['count'] > 0) {
$contribution = array_pop($results['values']);
}
}
if ($contribution) {
$item['contribution_id'] = $contribution['id'];
$status_id = $contribution['contribution_status_id'];
$item['contribution_status_id'] = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $status_id);
if ($contribution['contribution_status_id'] == 1) {
$item['processed'] = 'yes';
}
}
......
......@@ -19,6 +19,7 @@ Where:
* Map customer to contact ID in IPN
* Handle invoice.paid, invoice.finalized IPN events - we now create the new contribution once we receive the invoice.finalized event. It will then be transitioned to Completed by invoice.paid/invoice.payment_succeeded
* Record refund against the already recorded payment in CiviCRM so we update financial items correctly
* API3 Stripe.Listevents [!117](https://lab.civicrm.org/extensions/stripe/-/merge_requests/117) Provide additional information about stripe events.
## Release 6.4.2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment