Skip to content
Snippets Groups Projects
Commit 67aab6e4 authored by mattwire's avatar mattwire Committed by mattwire
Browse files

Fix StripeCustomer API params

parent 38eb8676
Branches
Tags
1 merge request!33Implement StripeSubscription.import API
......@@ -15,8 +15,8 @@ use CRM_Stripe_ExtensionUtil as E;
* @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['customer_id']['title'] = ts("Stripe Customer ID");
$spec['customer_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['processor_id']['title'] = ts("Payment Processor ID");
......@@ -25,7 +25,7 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) {
/**
* 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
* @see civicrm_api3_create_success
......@@ -33,10 +33,10 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) {
* @return array
*/
function civicrm_api3_stripe_customer_get($params) {
$index = 1;
foreach ($params as $key => $value) {
$index = 1;
switch ($key) {
case 'id':
case 'customer_id':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'String'];
$index++;
......@@ -61,7 +61,7 @@ function civicrm_api3_stripe_customer_get($params) {
while ($dao->fetch()) {
$result = [
'id' => $dao->id,
'customer_id' => $dao->id,
'contact_id' => $dao->contact_id,
'processor_id' => $dao->processor_id,
];
......@@ -81,8 +81,8 @@ function civicrm_api3_stripe_customer_get($params) {
* @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['customer_id']['title'] = ts("Stripe Customer ID");
$spec['customer_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['processor_id']['title'] = ts("Payment Processor ID");
......@@ -113,9 +113,9 @@ function civicrm_api3_stripe_customer_delete($params) {
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/
function _civicrm_api3_stripe_customer_create_spec(&$spec) {
$spec['id']['title'] = ts("Stripe Customer ID");
$spec['id']['type'] = CRM_Utils_Type::T_STRING;
$spec['id']['api.required'] = TRUE;
$spec['customer_id']['title'] = ts("Stripe Customer ID");
$spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['customer_id']['api.required'] = TRUE;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['contact_id']['api.required'] = TRUE;
......@@ -216,10 +216,10 @@ function civicrm_api3_stripe_customer_updatecontactids($params) {
}
function _civicrm_api3_stripe_customer_updatestripemetadata_spec(&$spec) {
$spec['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['id']['type'] = CRM_Utils_Type::T_STRING;
$spec['id']['api.required'] = FALSE;
$spec['customer_id']['title'] = E::ts("Stripe Customer ID");
$spec['customer_id']['description'] = E::ts('If set only this customer will be updated, otherwise we try and update ALL customers');
$spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['customer_id']['api.required'] = FALSE;
$spec['dryrun']['api.required'] = TRUE;
$spec['dryrun']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['processor_id']['api.required'] = FALSE;
......@@ -242,7 +242,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
throw new CiviCRM_API3_Exception('Missing required parameter dryrun');
}
// Check params
if (empty($params['id'])) {
if (empty($params['customer_id'])) {
// We're doing an update on all stripe customers
if (!isset($params['processor_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) {
$customerIds = CRM_Stripe_Customer::getAll($params['processor_id'], $params['options']);
}
else {
$customerIds = [$params['id']];
$customerIds = [$params['customer_id']];
}
foreach ($customerIds as $customerId) {
$customerParams = CRM_Stripe_Customer::getParamsForCustomerId($customerId);
......
......@@ -156,7 +156,7 @@ function civicrm_api3_stripe_subscription_import($params) {
// Create the stripe customer in CiviCRM
$customerParams = [
'id' => CRM_Stripe_Api::getObjectParam('customer_id', $stripeSubscription),
'customer_id' => CRM_Stripe_Api::getObjectParam('customer_id', $stripeSubscription),
'contact_id' => $params['contact_id'],
'processor_id' => (int) $params['payment_processor_id'],
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment