Commit 8a06d51e authored by mattwire's avatar mattwire

Add StripeCustomer.delete to delete a customer from CiviCRM

parent 3d22e522
......@@ -161,20 +161,34 @@ class CRM_Stripe_Customer {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public static function delete($params) {
$requiredParams = ['contact_id', 'is_live', 'processor_id'];
$requiredParams = ['is_live', 'processor_id'];
foreach ($requiredParams as $required) {
if (empty($required)) {
throw new \Civi\Payment\Exception\PaymentProcessorException('Stripe Customer (delete): Missing required parameter: ' . $required);
}
}
if (empty($params['contact_id']) && empty($params['id'])) {
throw new \Civi\Payment\Exception\PaymentProcessorException('Stripe Customer (delete): Missing required parameter: contact_id or id');
}
$queryParams = [
1 => [$params['contact_id'], 'String'],
2 => [$params['is_live'] ? 1 : 0, 'Boolean'],
3 => [$params['processor_id'], 'Integer'],
];
$sql = "DELETE FROM civicrm_stripe_customers
if (!empty($params['id'])) {
$queryParams = [
1 => [$params['id'], 'String'],
2 => [$params['is_live'] ? 1 : 0, 'Boolean'],
3 => [$params['processor_id'], 'Integer'],
];
$sql = "DELETE FROM civicrm_stripe_customers
WHERE id = %1 AND is_live = %2 AND processor_id = %3";
}
else {
$queryParams = [
1 => [$params['contact_id'], 'String'],
2 => [$params['is_live'] ? 1 : 0, 'Boolean'],
3 => [$params['processor_id'], 'Integer'],
];
$sql = "DELETE FROM civicrm_stripe_customers
WHERE contact_id = %1 AND is_live = %2 AND processor_id = %3";
}
CRM_Core_DAO::executeQuery($sql, $queryParams);
}
......
......@@ -81,6 +81,41 @@ function civicrm_api3_stripe_customer_get($params) {
return civicrm_api3_create_success($results);
}
/**
* 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_delete_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['is_live']['api.required'] = TRUE;
$spec['processor_id']['title'] = ts("Payment Processor ID");
$spec['processor_id']['type'] = CRM_Utils_Type::T_INT;
$spec['processor_id']['api.required'] = TRUE;
}
/**
* StripeCustomer.delete API
* This api will delete a stripe customer from CiviCRM
*
* @param array $params
* @see civicrm_api3_create_success
*
* @throws \Civi\Payment\Exception\PaymentProcessorException
* @return array
*/
function civicrm_api3_stripe_customer_delete($params) {
CRM_Stripe_Customer::delete($params);
return civicrm_api3_create_success([]);
}
/**
* Stripe.Customer.Updatecontactids API
* This api will update the civicrm_stripe_customers table and add contact IDs for all known email addresses
......
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