title: My PayPal cart upload code was working, but broke last week. Has something changed?
body: <p>I built a third party shopping cart for a client. When a customer checks out, the contents of their cart are uploaded to PayPal for payment processing. This had been working for a couple of months, but last week checkout became nonfunctional.</p>
  
  <p>After some debugging I found that the information returned from posting the cart data seemed to have changed. Formerly, the post returned a small message containing a link that can be used to display PayPal's review page:</p>
  
  <pre><code>Found. Redirecting to https://www.sandbox.paypal.com/webapps/hermes?token=#################&amp;useraction=commit&amp;mfid=###########################
  </code></pre>
  
  <p>Now, however, what gets returned looks like the contents of the entire target page before it has been processed. I can sort of display the page in a browser, but it contains many references to PayPal-specific modules that can't be found because they exist at PayPal, not on my system. All I see is a spinner that spins forever.</p>
  
  <p>Here is a simplified version of the code I used to upload the cart and extract the URL for redirection:</p>
  
  <pre><code>&lt;?php
  
  $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
  
  $fields = [
      'cmd' =&gt; '_cart',
      'upload' =&gt; '1',
      'business' =&gt; 'account@domain.com',
      'item_name_1' =&gt; 'Pack',
      'amount_1' =&gt; '1.00',
      'shipping_1' =&gt; '0.09',
  ];
  
  $query = http_build_query($fields);
  
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
  
  $result = curl_exec($ch);
  
  $redirectUrl = getRedirectUrl($result);
  curl_close($ch);
  
  if ($redirectUrl) {
      $returnArray = ['success' =&gt; true,
          'data' =&gt; $redirectUrl];
  }
  else {
      $returnArray = ['success' =&gt; false,
          'data' =&gt; $result];
  }
  
  echo json_encode($returnArray);
  
  function getRedirectUrl($returnedString) {
      $pattern = '/Found\. Redirecting to (.*)$/';
      $matches = [];
      $match = preg_match($pattern, $returnedString, $matches);
  
      if ($match) {
          return $matches[1];
      }
  
      return NULL;
  }
  </code></pre>
  
  <p>I would like to find out if something changed at PayPal last week that made this stop working or, barring that, if anyone has a suggestion as to how I might modify this code so that I can post and then open the PayPal review page in a second window.</p>
  
  <p>Thanks!</p>