Answers.Body: <p>I seem to have found a partial solution in this thread: <a href="https://forum.civicrm.org/index.php%3Ftopic=13921.0.html" rel="nofollow noreferrer">https://forum.civicrm.org/index.php%3Ftopic=13921.0.html</a></p>
  <p>I fixed the issue by changing the Pending status' weight so that it appears further down the list (as in the default settings). However, I am still having an issue with Expired memberships not having their end date changed after an order is created and a payment is passed.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-26T20:32:46.843Z
Answers.Text: do you have the required Scheduled Job running?
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-28T19:51:55.713Z
Answers.Text: @petednz-fuzion Yes, I ran it manually and it works for every other type of membership status change.
Answers.UserDisplayName: lapmir
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-28T22:20:12.000Z
Answers.Text: is it working as expected if you use pure Civi UI rather than your custom plugin? (I don't know WP well so can't guess why you need a custom plugin.)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-26T19:59:19.800Z
Answers.LastActivityDate: 2022-06-26T19:59:19.800Z
Answers.UserDisplayName: lapmir
Body: <p>I am building a custom plugin to handle Memberships in Wordpress (CiviCRM version 5.50.1). I am using the Order and Payment APIs (version 3 - there doesn't seem to be anything in version 4?) to do this.</p>
  <p>My code looks like this for the Order:</p>
  <pre><code>$params = [
    'membership_type_id' =&gt; $price_field_value[0]['membership_type_id'],
    'contact_id' =&gt; $contact_id,
    'status_id' =&gt; 'Pending',
    'source' =&gt; ...,
  ];
  
  $order_data = [
    'contact_id' =&gt; $contact_id,
    'total_amount' =&gt; $total_amount,
    'financial_type_id' =&gt; $settings['civicrm_contribution_financial_type'],
    'payment_instrument_id' =&gt; $settings['civicrm_contribution_payment_instrument'],
    'receive_date' =&gt; $date-&gt;format('Y-m-d H:i:s'),
    'contribution_page_id' =&gt; $contribution_page_id,
    'contribution_status_id' =&gt; 'Pending',
    'contribution_source' =&gt; ...,
    'line_items' =&gt; [
        [
            'params' =&gt; $params,
            'line_item' =&gt; [
                [
                    'entity_table' =&gt; 'civicrm_membership',
                    'price_field_id' =&gt; $price_field_value[0]['price_field_id'],
                    'price_field_value_id' =&gt; $price_field_value[0]['id'],
                    'qty' =&gt; '1',
                    'unit_price' =&gt; $total_amount,
                    'line_total' =&gt; $total_amount,
                ]
            ]
        ]
    ]
  ];
  
  $order = civicrm_api3('Order', 'create', $order_data);
  </code></pre>
  <p>And like this for the payment:</p>
  <pre><code>return civicrm_api3('Payment', 'create', [
    'contribution_id' =&gt; $contribution_id,
    'total_amount' =&gt; $total_amount,
    'trxn_id' =&gt; $trxn_id,
    'trxn_date' =&gt; $date-&gt;format('Y-m-d H:i:s'),
    'receipt_date' =&gt; $date-&gt;format('Y-m-d H:i:s'),
    'payment_instrument_id' =&gt; $settings['civicrm_contribution_payment_instrument'],
    'is_send_contribution_notification' =&gt; 0,
  ]);
  </code></pre>
  <p>Once the payment is passed, I can see the completed Contribution linked to the Membership, but the Membership remains as Pending. Am I missing something?</p>
  <p>I am having similar difficulties with updating Memberships: when I enter an existing membership in the params array, it stays as expired after payment. Could it be that both problems are related?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-15T22:10:49.580Z
Comments.Text: Can you confirm if contribution is linked with membership? Do you see related contribution when viewing membership?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-16T20:39:04.470Z
Comments.Text: @PradeepNayak Yes, and it indicates that the contribution is paid.
Comments.UserDisplayName: lapmir
Tags: <wordpress><civimember><payment>
Title: Membership stays on Pending after Payment
ThreadText: # Membership stays on Pending after Payment
  
  (Asked by: username_0 on 2022-06-15)
  
  I am building a custom plugin to handle Memberships in Wordpress (CiviCRM version 5.50.1). I am using the Order and Payment APIs (version 3 - there doesn't seem to be anything in version 4?) to do this.
  
  My code looks like this for the Order:
  
  ```
  $params = [
    'membership_type_id' => $price_field_value[0]['membership_type_id'],
    'contact_id' => $contact_id,
    'status_id' => 'Pending',
    'source' => ...,
  ];
  
  $order_data = [
    'contact_id' => $contact_id,
    'total_amount' => $total_amount,
    'financial_type_id' => $settings['civicrm_contribution_financial_type'],
    'payment_instrument_id' => $settings['civicrm_contribution_payment_instrument'],
    'receive_date' => $date->format('Y-m-d H:i:s'),
    'contribution_page_id' => $contribution_page_id,
    'contribution_status_id' => 'Pending',
    'contribution_source' => ...,
    'line_items' => [
        [
            'params' => $params,
            'line_item' => [
                [
                    'entity_table' => 'civicrm_membership',
                    'price_field_id' => $price_field_value[0]['price_field_id'],
                    'price_field_value_id' => $price_field_value[0]['id'],
                    'qty' => '1',
                    'unit_price' => $total_amount,
                    'line_total' => $total_amount,
                ]
            ]
        ]
    ]
  ];
  
  $order = civicrm_api3('Order', 'create', $order_data);
  
  ```
  
  And like this for the payment:
  
  ```
  return civicrm_api3('Payment', 'create', [
    'contribution_id' => $contribution_id,
    'total_amount' => $total_amount,
    'trxn_id' => $trxn_id,
    'trxn_date' => $date->format('Y-m-d H:i:s'),
    'receipt_date' => $date->format('Y-m-d H:i:s'),
    'payment_instrument_id' => $settings['civicrm_contribution_payment_instrument'],
    'is_send_contribution_notification' => 0,
  ]);
  
  ```
  
  Once the payment is passed, I can see the completed Contribution linked to the Membership, but the Membership remains as Pending. Am I missing something?
  
  I am having similar difficulties with updating Memberships: when I enter an existing membership in the params array, it stays as expired after payment. Could it be that both problems are related?
  
  **Tags:** wordpress, civimember, payment
  
  > **Comments:**
  > **username_1**: Can you confirm if contribution is linked with membership? Do you see related contribution when viewing membership?  
  > **username_0**: @username_1 Yes, and it indicates that the contribution is paid.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-06-26. Score: 0
  
  I seem to have found a partial solution in this thread: <https://forum.civicrm.org/index.php%3Ftopic=13921.0.html>
  
  I fixed the issue by changing the Pending status' weight so that it appears further down the list (as in the default settings). However, I am still having an issue with Expired memberships not having their end date changed after an order is created and a payment is passed.
  
  > **Comments:**
  > **username_2**: do you have the required Scheduled Job running?  
  > **username_0**: @username_2 Yes, I ran it manually and it works for every other type of membership status change.  
  > **username_2**: is it working as expected if you use pure Civi UI rather than your custom plugin? (I don't know WP well so can't guess why you need a custom plugin.)  
  
  ---
  
  