Commit 67aab6e4 authored by mattwire's avatar mattwire Committed by mattwire

Fix StripeCustomer API params

parent 38eb8676
...@@ -15,8 +15,8 @@ use CRM_Stripe_ExtensionUtil as E; ...@@ -15,8 +15,8 @@ use CRM_Stripe_ExtensionUtil as E;
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/ */
function _civicrm_api3_stripe_customer_get_spec(&$spec) { function _civicrm_api3_stripe_customer_get_spec(&$spec) {
$spec['id']['title'] = ts("Stripe Customer ID"); $spec['customer_id']['title'] = ts("Stripe Customer ID");
$spec['id']['type'] = CRM_Utils_Type::T_STRING; $spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID"); $spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT; $spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['processor_id']['title'] = ts("Payment Processor ID"); $spec['processor_id']['title'] = ts("Payment Processor ID");
...@@ -25,7 +25,7 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) { ...@@ -25,7 +25,7 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) {
/** /**
* StripeCustomer.Get API * StripeCustomer.Get API
* This api will update the civicrm_stripe_customers table and add contact IDs for all known email addresses * This api will get a customer from the civicrm_stripe_customers table
* *
* @param array $params * @param array $params
* @see civicrm_api3_create_success * @see civicrm_api3_create_success
...@@ -33,10 +33,10 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) { ...@@ -33,10 +33,10 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) {
* @return array * @return array
*/ */
function civicrm_api3_stripe_customer_get($params) { function civicrm_api3_stripe_customer_get($params) {
$index = 1;
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
$index = 1;
switch ($key) { switch ($key) {
case 'id': case 'customer_id':
$where[$index] = "{$key}=%{$index}"; $where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'String']; $whereParam[$index] = [$value, 'String'];
$index++; $index++;
...@@ -61,7 +61,7 @@ function civicrm_api3_stripe_customer_get($params) { ...@@ -61,7 +61,7 @@ function civicrm_api3_stripe_customer_get($params) {
while ($dao->fetch()) { while ($dao->fetch()) {
$result = [ $result = [
'id' => $dao->id, 'customer_id' => $dao->id,
'contact_id' => $dao->contact_id, 'contact_id' => $dao->contact_id,
'processor_id' => $dao->processor_id, 'processor_id' => $dao->processor_id,
]; ];
...@@ -81,8 +81,8 @@ function civicrm_api3_stripe_customer_get($params) { ...@@ -81,8 +81,8 @@ function civicrm_api3_stripe_customer_get($params) {
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/ */
function _civicrm_api3_stripe_customer_delete_spec(&$spec) { function _civicrm_api3_stripe_customer_delete_spec(&$spec) {
$spec['id']['title'] = ts("Stripe Customer ID"); $spec['customer_id']['title'] = ts("Stripe Customer ID");
$spec['id']['type'] = CRM_Utils_Type::T_STRING; $spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID"); $spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT; $spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['processor_id']['title'] = ts("Payment Processor ID"); $spec['processor_id']['title'] = ts("Payment Processor ID");
...@@ -113,9 +113,9 @@ function civicrm_api3_stripe_customer_delete($params) { ...@@ -113,9 +113,9 @@ function civicrm_api3_stripe_customer_delete($params) {
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/ */
function _civicrm_api3_stripe_customer_create_spec(&$spec) { function _civicrm_api3_stripe_customer_create_spec(&$spec) {
$spec['id']['title'] = ts("Stripe Customer ID"); $spec['customer_id']['title'] = ts("Stripe Customer ID");
$spec['id']['type'] = CRM_Utils_Type::T_STRING; $spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['id']['api.required'] = TRUE; $spec['customer_id']['api.required'] = TRUE;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID"); $spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT; $spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['contact_id']['api.required'] = TRUE; $spec['contact_id']['api.required'] = TRUE;
...@@ -216,10 +216,10 @@ function civicrm_api3_stripe_customer_updatecontactids($params) { ...@@ -216,10 +216,10 @@ function civicrm_api3_stripe_customer_updatecontactids($params) {
} }
function _civicrm_api3_stripe_customer_updatestripemetadata_spec(&$spec) { function _civicrm_api3_stripe_customer_updatestripemetadata_spec(&$spec) {
$spec['id']['title'] = E::ts("Stripe Customer ID"); $spec['customer_id']['title'] = E::ts("Stripe Customer ID");
$spec['id']['description'] = E::ts('If set only this customer will be updated, otherwise we try and update ALL customers'); $spec['customer_id']['description'] = E::ts('If set only this customer will be updated, otherwise we try and update ALL customers');
$spec['id']['type'] = CRM_Utils_Type::T_STRING; $spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['id']['api.required'] = FALSE; $spec['customer_id']['api.required'] = FALSE;
$spec['dryrun']['api.required'] = TRUE; $spec['dryrun']['api.required'] = TRUE;
$spec['dryrun']['type'] = CRM_Utils_Type::T_BOOLEAN; $spec['dryrun']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['processor_id']['api.required'] = FALSE; $spec['processor_id']['api.required'] = FALSE;
...@@ -242,7 +242,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) { ...@@ -242,7 +242,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
throw new CiviCRM_API3_Exception('Missing required parameter dryrun'); throw new CiviCRM_API3_Exception('Missing required parameter dryrun');
} }
// Check params // Check params
if (empty($params['id'])) { if (empty($params['customer_id'])) {
// We're doing an update on all stripe customers // We're doing an update on all stripe customers
if (!isset($params['processor_id'])) { if (!isset($params['processor_id'])) {
throw new CiviCRM_API3_Exception('Missing required parameters processor_id when using without a customer id'); throw new CiviCRM_API3_Exception('Missing required parameters processor_id when using without a customer id');
...@@ -250,7 +250,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) { ...@@ -250,7 +250,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
$customerIds = CRM_Stripe_Customer::getAll($params['processor_id'], $params['options']); $customerIds = CRM_Stripe_Customer::getAll($params['processor_id'], $params['options']);
} }
else { else {
$customerIds = [$params['id']]; $customerIds = [$params['customer_id']];
} }
foreach ($customerIds as $customerId) { foreach ($customerIds as $customerId) {
$customerParams = CRM_Stripe_Customer::getParamsForCustomerId($customerId); $customerParams = CRM_Stripe_Customer::getParamsForCustomerId($customerId);
......
...@@ -156,7 +156,7 @@ function civicrm_api3_stripe_subscription_import($params) { ...@@ -156,7 +156,7 @@ function civicrm_api3_stripe_subscription_import($params) {
// Create the stripe customer in CiviCRM // Create the stripe customer in CiviCRM
$customerParams = [ $customerParams = [
'id' => CRM_Stripe_Api::getObjectParam('customer_id', $stripeSubscription), 'customer_id' => CRM_Stripe_Api::getObjectParam('customer_id', $stripeSubscription),
'contact_id' => $params['contact_id'], 'contact_id' => $params['contact_id'],
'processor_id' => (int) $params['payment_processor_id'], 'processor_id' => (int) $params['payment_processor_id'],
]; ];
......
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