Commit 38eb8676 authored by mattwire's avatar mattwire Committed by mattwire

Automatically find and link membership record if possible

parent 7e2de473
......@@ -243,6 +243,7 @@ function civicrm_api3_stripe_subscription_import($params) {
}
// Link to membership record
// By default we'll match the latest active membership, unless membership_id is passed in.
if (!empty($params['membership_id'])) {
$membershipParams = [
'id' => $params['membership_id'],
......@@ -250,6 +251,23 @@ function civicrm_api3_stripe_subscription_import($params) {
];
$membership = civicrm_api3('Membership', 'create', $membershipParams);
}
elseif (!empty($params['membership_auto'])) {
$membershipParams = [
'contact_id' => $params['contact_id'],
'options' => ['limit' => 1, 'sort' => "id DESC"],
'contribution_recur_id' => ['IS NULL' => 1],
'is_test' => !empty($paymentProcessor['is_test']) ? 1 : 0,
'active_only' => 1,
];
$membership = civicrm_api3('Membership', 'get', $membershipParams);
if (!empty($membership['id'])) {
$membershipParams = [
'id' => $membership['id'],
'contribution_recur_id' => $contributionRecur['id'],
];
$membership = civicrm_api3('Membership', 'create', $membershipParams);
}
}
$results = [
'subscription_id' => $params['subscription_id'],
......@@ -279,6 +297,9 @@ function _civicrm_api3_stripe_subscription_import_spec(&$spec) {
$spec['contribution_id']['type'] = CRM_Utils_Type::T_INT;
$spec['membership_id']['title'] = ts("Membership ID");
$spec['membership_id']['type'] = CRM_Utils_Type::T_INT;
$spec['membership_auto']['title'] = ts("Link to existing membership automatically");
$spec['membership_auto']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['membership_auto']['api.default'] = TRUE;
$spec['financial_type_id'] = [
'title' => 'Financial Type ID',
'name' => 'financial_type_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