Skip to content
Snippets Groups Projects
Commit a5f385de authored by mattwire's avatar mattwire
Browse files

Add StripeCustomer.get API, move customercontactids to StripeCustomer.updatecontactids

parent 052c1f6e
No related branches found
No related tags found
No related merge requests found
...@@ -378,7 +378,7 @@ class CRM_Stripe_Upgrader extends CRM_Stripe_Upgrader_Base { ...@@ -378,7 +378,7 @@ class CRM_Stripe_Upgrader extends CRM_Stripe_Upgrader_Base {
} }
$this->ctx->log->info('Applying Stripe update 5010. Getting Contact IDs for civicrm_stripe_customers.'); $this->ctx->log->info('Applying Stripe update 5010. Getting Contact IDs for civicrm_stripe_customers.');
civicrm_api3('Stripe', 'customercontactids', []); civicrm_api3('StripeCustomer', 'updatecontactids', []);
return TRUE; return TRUE;
} }
......
...@@ -6,7 +6,86 @@ ...@@ -6,7 +6,86 @@
*/ */
/** /**
* Stripe.Customer_Contactids API * StripeCustomer.Get API specification
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_stripe_customer_get_spec(&$spec) {
$spec['id']['title'] = ts("Stripe Customer ID");
$spec['id']['type'] = CRM_Utils_Type::T_STRING;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['is_live']['title'] = ts("Is live processor");
$spec['is_live']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['processor_id']['title'] = ts("Payment Processor ID");
$spec['processor_id']['type'] = CRM_Utils_Type::T_INT;
}
/**
* StripeCustomer.Get API
* This api will update the civicrm_stripe_customers table and add contact IDs for all known email addresses
*
* @param array $params
* @see civicrm_api3_create_success
*
* @return array
*/
function civicrm_api3_stripe_customer_get($params) {
foreach ($params as $key => $value) {
$index = 1;
switch ($key) {
case 'id':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'String'];
$index++;
break;
case 'contact_id':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'Integer'];
$index++;
break;
case 'is_live':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'Boolean'];
$index++;
break;
case 'processor_id':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'Integer'];
$index++;
break;
}
}
$query = "SELECT * FROM civicrm_stripe_customers ";
if (count($where)) {
$whereClause = implode(' AND ', $where);
$query .= "WHERE {$whereClause}";
}
$dao = CRM_Core_DAO::executeQuery($query, $whereParam);
while ($dao->fetch()) {
$result = [
'id' => $dao->id,
'contact_id' => $dao->contact_id,
'is_live' => $dao->is_live,
'processor_id' => $dao->processor_id,
];
if ($dao->email) {
$result['email'] = $dao->email;
}
$results[] = $result;
}
return civicrm_api3_create_success($results);
}
/**
* Stripe.Customer.Updatecontactids API
* This api will update the civicrm_stripe_customers table and add contact IDs for all known email addresses * This api will update the civicrm_stripe_customers table and add contact IDs for all known email addresses
* *
* @param array $params * @param array $params
...@@ -14,7 +93,7 @@ ...@@ -14,7 +93,7 @@
* *
* @return array * @return array
*/ */
function civicrm_api3_stripe_customercontactids($params) { function civicrm_api3_stripe_customer_updatecontactids($params) {
$dao = CRM_Core_DAO::executeQuery('SELECT email, id FROM civicrm_stripe_customers WHERE contact_id IS NULL'); $dao = CRM_Core_DAO::executeQuery('SELECT email, id FROM civicrm_stripe_customers WHERE contact_id IS NULL');
$counts = [ $counts = [
'updated' => 0, 'updated' => 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment