title: Paypal PHP REST API
body: <p>I'm creating a Paypal checkout with PHP and this is the code so far:</p>
  
  <pre><code>$ch = curl_init();
          $clientId = "clientID";
          $secret = "secret";
  
          curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
          curl_setopt($ch, CURLOPT_HEADER, false);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
          curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
          curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
  
          $result = curl_exec($ch);
  
          if(empty($result))die("Error: No response.");
          else
          {
                  $json = json_decode($result);
                      //print_r($json-&gt;access_token);
                      if ($_POST['creditcard'] == 'paypal') {
                          $data = '{
                              "intent":"sale",
                              "redirect_urls":{
                              "return_url":"http://returnurl.com",
                              "cancel_url":"http://returnurl.com"
                              },
                              "payer":{
                              "payment_method":"paypal"
                              },
                              "transactions":[
                              {
                              "amount":{
                              "total":"' . preg_replace("/[^0-9,.]/", "", $order_price) .'",
                              "currency":"' . $currency_code .'"
                              },
                              "description":"' . ucfirst($type) . ' Logo Purchase. ' . '"
                              }
                              ]
                              }';
  
                              curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
                              curl_setopt($ch, CURLOPT_POST, true);
                              curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
                              curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                              'Content-Type:application/json',
                              "Authorization: Bearer " . $json-&gt;access_token, 
                              "Content-length: ".strlen($data))
                              );
                              print_r($data);
                              $result = curl_exec($ch);
  
                              if(empty($result))die("Error: No response.");
                              else {
                                  $json_output = json_decode($result);
                                  print_r($result);
  
                                  if(isset($json_output-&gt;{'links'}[2]-&gt;{'href'}))
                                      $_SESSION['execute_url'] = $json_output-&gt;{'links'}[2]-&gt;{'href'};
                                  if(isset($json_output-&gt;{'links'}[1]-&gt;{'href'}))
                                      header('Location:' .$json_output-&gt;{'links'}[1]-&gt;{'href'} );
                              }
  
                      }
  
                  }
  
          curl_close($ch);
  </code></pre>
  
  <p>I checkout with my test account and I am redirected to the redirect URL.  So I'm assuming everything is working fine.  Now the next part is what I can't figure out.  I'm trying to execute the payment here.</p>
  
  <p>Do I use the payment URL that I received from my previous code above?</p>
  
  <p>I tried doing this:</p>
  
  <pre><code>                            $data = '{ "payer_id" : "' .$_GET['PayerID'] . '" }';
                              curl_setopt($ch, CURLOPT_URL, $stored_execute_url;
                              curl_setopt($ch, CURLOPT_POST, true);
                              curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                              curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                              'Content-Type:application/json',
                              "Authorization: Bearer " . $_GET['token'], 
                              "Content-length: ".strlen($data))
                              );
                              print_r($data);
                              $result = curl_exec($ch);
  
                              if(empty($result))die("Error: No response.");
  </code></pre>
  
  <p>All I'm getting is the "Error: No response."</p>
  
  <p>I've been following this link <a href="https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/" rel="nofollow">https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/</a> and I was able to get by until the last part.</p>