Answers.Body: <p>Ok, I think I have <em>finally</em> got to the bottom of this.</p>
  
  <p>Firstly, one of the problems was that I had not got the payment notifications set up in PayPal (mea culpa).  </p>
  
  <p>However, even with this fixed, the notifications were not being processed.  I narrowed this down to the handlePaymentExpress() method in PayPalProIPN.php.  There are two errors here, both related to the "is test" status.  At line 578, it attempts to get the Contribution record.  However the call:</p>
  
  <pre><code>   $result = civicrm_api3('contribution', 'getsingle', array('invoice_id' =&gt; $input['invoice']));
  </code></pre>
  
  <p>only works for live contributions, it doesn't find test contributions.</p>
  
  <p>The other error is at line 597:</p>
  
  <pre><code>    $paymentProcessorID = self::getPayPalPaymentProcessorID();
  </code></pre>
  
  <p>Again, this only works for live, not test.</p>
  
  <p>I'd love to log the issue on the CiviCRM website, but two requests for an account have been ignored.  Oh well.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T02:07:31.540Z
Answers.Text: Can you ping me (@bgm) on https://chat.civicrm.org, with your email/username on civicrm.org?
Answers.UserDisplayName: bgm
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-26T11:32:39.717Z
Answers.Text: I did manage to get a logon to the issues board and raise the issue, but I have been unable to login since
Answers.UserDisplayName: user2430147
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T19:53:17.893Z
Answers.LastActivityDate: 2018-04-23T19:53:17.893Z
Answers.UserDisplayName: user2430147
Body: <p>I have set up a test PayPay Express payment processor and created a contribution page that allows the user to create a recurring donation.</p>
  
  <p>When I use this page, I get the "PayPal Checkout" button appears and takes me to PayPal.  Everything proceeds as expected with the PayPal screens and I get taken back to my site, where I am told I need to click the "Make Contribution" button.  I do that and get back a page that says:</p>
  
  <pre><code>Notice: Undefined index: returnURL in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 372 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: cancelURL in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 373 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: installments in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 380 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: transactionid in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 399 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: amt in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 400 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: feeamt in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 401 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: settleamt in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 402 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: paymentstatus in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 406 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: pendingreason in CRM_Core_Payment_PayPalImpl-&gt;createRecurringPayments() (line 407 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: payment_status_id in CRM_Contribute_BAO_Contribution_Utils::processConfirm() (line 198 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Contribute/BAO/Contribution/Utils.php).
  </code></pre>
  
  <p>It also says that the payment was successful, but when I look at it in CiviCRM, it has a status of "Pending" and my PayPal account shows no notification was sent.</p>
  
  <p>I have done some digging.  After the "Make Contribution" button is pressed, the application ends up in PayPalImpl.php, createRecurringPayments(...).  This never sets the $param['payment_status_id'].  Later on, the application gets to Confirm.php, completeTransaction(), which looks for $result['payment_status_id'] of 1.  Only if this is true does the transaction get marked as completed.</p>
  
  <p>So, the question is, should createRecurringPayments() set the payment_status_id, and to what?</p>
  
  <p>Note that if I try with a single donation, it works ok (i.e. the transaction is marked as complete).</p>
  
  <p>Thanks</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-17T21:08:19.270Z
Comments.Text: The code implies that it should be pending as it is not completed in realtime?
  
  ```
      if (!empty($params['is_recur'])) {
        // See comment block.
        $params['payment_status_id'] = array_search('Pending', $statuses);
      }
      else {
        $params['payment_status_id'] = array_search('Completed', $statuses);
      }
  ```
Comments.UserDisplayName: user4278
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-19T08:10:23.567Z
Comments.Text: To be honest, having looked at the code in more detail, I am not sure how much of it actually works.  For example, if you are setting up a recurring payment using the PayPal Standard payment processor, it sets up the agreement and takes the first payment.  However, the Express payment processor doesn't (it should be setting the "INITAMT" parameter to do that), however the code seems to be expecting that it will.  Unfortunately, I don't know enough about CiviContribute or PayPal to say whether or not what it is doing is correct in terms of setting up the recurring payment.
Comments.UserDisplayName: user2430147
Tags: <civicontribute><paypal>
Title: Bug in CiviContribute - PayPal Express not working for recurring contributions
ThreadText: # Bug in CiviContribute - PayPal Express not working for recurring contributions
  
  (Asked by: username_0 on 2018-04-16)
  
  I have set up a test PayPay Express payment processor and created a contribution page that allows the user to create a recurring donation.
  
  When I use this page, I get the "PayPal Checkout" button appears and takes me to PayPal. Everything proceeds as expected with the PayPal screens and I get taken back to my site, where I am told I need to click the "Make Contribution" button. I do that and get back a page that says:
  
  ```
  Notice: Undefined index: returnURL in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 372 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: cancelURL in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 373 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: installments in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 380 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: transactionid in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 399 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: amt in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 400 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: feeamt in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 401 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: settleamt in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 402 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: paymentstatus in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 406 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: pendingreason in CRM_Core_Payment_PayPalImpl->createRecurringPayments() (line 407 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Core/Payment/PayPalImpl.php).
  Notice: Undefined index: payment_status_id in CRM_Contribute_BAO_Contribution_Utils::processConfirm() (line 198 of /var/www/html/SOTS/sites/all/modules/civicrm/CRM/Contribute/BAO/Contribution/Utils.php).
  
  ```
  
  It also says that the payment was successful, but when I look at it in CiviCRM, it has a status of "Pending" and my PayPal account shows no notification was sent.
  
  I have done some digging. After the "Make Contribution" button is pressed, the application ends up in PayPalImpl.php, createRecurringPayments(...). This never sets the $param['payment\_status\_id']. Later on, the application gets to Confirm.php, completeTransaction(), which looks for $result['payment\_status\_id'] of 1. Only if this is true does the transaction get marked as completed.
  
  So, the question is, should createRecurringPayments() set the payment\_status\_id, and to what?
  
  Note that if I try with a single donation, it works ok (i.e. the transaction is marked as complete).
  
  Thanks
  
  **Tags:** civicontribute, paypal
  
  > **Comments:**
  > **username_1**: The code implies that it should be pending as it is not completed in realtime?  ```     if (!empty($params['is_recur'])) {       // See comment block.       $params['payment_status_id'] = array_search('Pending', $statuses);     }     else {       $params['payment_status_id'] = array_search('Completed', $statuses);     } ```  
  > **username_0**: To be honest, having looked at the code in more detail, I am not sure how much of it actually works.  For example, if you are setting up a recurring payment using the PayPal Standard payment processor, it sets up the agreement and takes the first payment.  However, the Express payment processor doesn't (it should be setting the "INITAMT" parameter to do that), however the code seems to be expecting that it will.  Unfortunately, I don't know enough about CiviContribute or PayPal to say whether or not what it is doing is correct in terms of setting up the recurring payment.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-04-23. Score: 1
  
  Ok, I think I have *finally* got to the bottom of this.
  
  Firstly, one of the problems was that I had not got the payment notifications set up in PayPal (mea culpa).
  
  However, even with this fixed, the notifications were not being processed. I narrowed this down to the handlePaymentExpress() method in PayPalProIPN.php. There are two errors here, both related to the "is test" status. At line 578, it attempts to get the Contribution record. However the call:
  
  ```
     $result = civicrm_api3('contribution', 'getsingle', array('invoice_id' => $input['invoice']));
  
  ```
  
  only works for live contributions, it doesn't find test contributions.
  
  The other error is at line 597:
  
  ```
      $paymentProcessorID = self::getPayPalPaymentProcessorID();
  
  ```
  
  Again, this only works for live, not test.
  
  I'd love to log the issue on the CiviCRM website, but two requests for an account have been ignored. Oh well.
  
  > **Comments:**
  > **username_2**: Can you ping me (@username_2) on https://chat.civicrm.org, with your email/username on civicrm.org?  
  > **username_0**: I did manage to get a logon to the issues board and raise the issue, but I have been unable to login since  
  
  ---
  
  