Skip to content
Snippets Groups Projects
Commit c6218c3c authored by Samuele Masetto's avatar Samuele Masetto
Browse files

fix importcharge API for is_test support and some notices

parent 969421e2
Branches
Tags
1 merge request!171fix importcharge API for is_test support and some notices
......@@ -83,7 +83,7 @@ function civicrm_api3_stripe_importcharge($params) {
$sourceText = 'Stripe: Manual import via API';
}
$is_test = isset($paymentProcessor['is_test']) && $paymentProcessor['is_test'] ? 1 : 0;
$is_test = isset($payment_processor['is_test']) && $payment_processor['is_test'] ? 1 : 0;
// Check for a subscription.
$subscription = CRM_Stripe_Api::getObjectParam('subscription_id', $stripeInvoice);
......@@ -92,6 +92,7 @@ function civicrm_api3_stripe_importcharge($params) {
// Lookup the contribution_recur_id.
$cr_results = \Civi\Api4\ContributionRecur::get()
->addWhere('trxn_id', '=', $subscription)
->addWhere('is_test', '=', $is_test)
->setCheckPermissions(FALSE)
->execute();
$contribution_recur = $cr_results->first();
......@@ -113,7 +114,7 @@ function civicrm_api3_stripe_importcharge($params) {
// Check if a contribution already exists.
$contribution_id = NULL;
if ($params['contribution_id']) {
if (isset($params['contribution_id'])) {
// From user input.
$contribution_id = $params['contribution_id'];
}
......@@ -130,7 +131,7 @@ function civicrm_api3_stripe_importcharge($params) {
}
}
// If it exists, we update by adding the id.
// If it exists, we update by adding the id.
if ($contribution_id) {
$contributionParams['id'] = $contribution_id;
}
......@@ -150,7 +151,7 @@ function civicrm_api3_stripe_importcharge($params) {
if ($contribution_recur_id) {
$contributionParams['contribution_recur_id'] = $contribution_recur_id;
}
}
}
$contribution = civicrm_api3('Contribution', 'create', $contributionParams);
return civicrm_api3_create_success($contribution['values']);
......
......@@ -47,7 +47,7 @@ function civicrm_api3_stripe_importsubscription($params) {
}
$customer = array_pop($custresult['values']);
if ($customer['contact_id'] != $params['contact_id']) {
throw new API_Exception(E::ts("There is a mismatch between the contact id for the customer indicated by the subscription (%1) and the contact id provided via the API params (%2).", [ 1 => $customer['contact_id'], 2 => $params['contact_id']]));
throw new API_Exception(E::ts("There is a mismatch between the contact id for the customer indicated by the subscription (%1) and the contact id provided via the API params (%2).", [ 1 => $customer['contact_id'], 2 => $params['contact_id']]));
}
// Create the recur record in CiviCRM if it doesn't exist.
......@@ -73,7 +73,7 @@ function civicrm_api3_stripe_importsubscription($params) {
'is_test' => isset($paymentProcessor['is_test']) && $paymentProcessor['is_test'] ? 1 : 0,
'contribution_source' => !empty($params['contribution_source']) ? $params['contribution_source'] : '',
];
if ($params['recur_id']) {
if (isset($params['recur_id']) && $params['recur_id']) {
$contributionRecurParams['id'] = $params['recur_id'];
}
$contributionRecur = civicrm_api3('ContributionRecur', 'create', $contributionRecurParams);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment