From aa14632e562497e9f1862b5a3ff482eb6555cf54 Mon Sep 17 00:00:00 2001 From: drastik <jwjoshuawalker@gmail.com> Date: Mon, 12 Jan 2015 11:38:01 -0600 Subject: [PATCH] * More graceful search for the 'email' field on a contribution. * Fall back to looking up the contact ID, apparent issue on Wordpress backend contribs. * Catch error & display clear message when no email was found, instead of trying to query empty value. --- CRM/Core/Payment/Stripe.php | 48 +++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/CRM/Core/Payment/Stripe.php b/CRM/Core/Payment/Stripe.php index dd672237..1bde568d 100644 --- a/CRM/Core/Payment/Stripe.php +++ b/CRM/Core/Payment/Stripe.php @@ -236,20 +236,44 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { } // Check for existing customer, create new otherwise. - if (!empty($params['email'])) { - $email = $params['email']; - } - elseif (!empty($params['email-5'])) { - $email = $params['email-5']; + // Possible email fields. + $email_fields = array( + 'email', + 'email-5', + 'email-Primary', + ); + + // Possible contact ID fields. + $contact_id_fields = array( + 'contact_id', + 'contactID', + ); + + // Find out which email field has our yummy value. + foreach ($email_fields as $email_field) { + if (!empty($params[$email_field])) { + $email = $params[$email_field]; + break; + } } - elseif (!empty($params['email-Primary'])) { - $email = $params['email-Primary']; + + // We didn't find an email, but never fear - this might be a backend contrib. + // We can look for a contact ID field and get the email address. + if (empty($email)) { + foreach ($contact_id_fields as $cid_field) { + if (!empty($params[$cid_field])) { + $email = civicrm_api3('Contact', 'getvalue', array( + 'id' => $params[$cid_field], + 'return' => 'email', + )); + break; + } + } } - elseif (!empty($params['contact_id'])){ - $email = civicrm_api3('Contact', 'getvalue', array( - 'id' => $params['contact_id'], - 'return' => 'email', - )); + + // We still didn't get an email address?! /ragemode on + if (empty($email)) { + CRM_Core_Error::fatal(ts('No email address found. Please report this issue.')); } // Prepare escaped query params. -- GitLab