Adventures Inwards Paypal: Missing Sum Together With Items


The sample code included hither volition enable you lot to brand a accuse through PayPal for a sure enough sum only unless you lot render a breakdown of the items beingness purchased together with then the fee beingness charged together with the items inside that accuse won't last displayed.
<?php  // http://stackoverflow.com/questions/15729167/paypal-api-with-php-and-curl // https://github.com/paypal/adaptivepayments-sdk-php/issues/24 // https://github.com/paypal/rest-api-curlsamples/blob/master/execute_all_calls.php  // http://stackoverflow.com/questions/15885742/pay-with-paypal-through-paypal-rest-api-does-not-show-up-payment-description-on // Full payment capabilities // https://developer.paypal.com/docs/integration/direct/explore-payment-capabilities/ $host = 'https://api.sandbox.paypal.com'; $clientId = 'Replace amongst your clientId'; $secret = 'Replace amongst your secret'; $token = '';  part get_access_token($url, $postdata) {  global $clientId, $clientSecret;  $curl = curl_init($url);   curl_setopt($curl, CURLOPT_POST, true);   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  curl_setopt($curl, CURLOPT_USERPWD, $clientId . ":" . $clientSecret); // curl_setopt($ch, CURLOPT_SSLVERSION, 1); // curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');  curl_setopt($curl, CURLOPT_HEADER, false);   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);   curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);   // curl_setopt($curl, CURLOPT_VERBOSE, TRUE);  $response = curl_exec( $curl );  if (empty($response)) {      // some sort of an fault happened      die(curl_error($curl));      curl_close($curl); // unopen cURL handler  } else {      $info = curl_getinfo($curl);   echo "Time took: " . $info['total_time']*1000 . "ms\n";      curl_close($curl); // unopen cURL handler   if($info['http_code'] != 200 && $info['http_code'] != 201 ) {    echo "Received error: " . $info['http_code']. "\n";    echo "Raw response:".$response."\n";    die();      }  }  // Convert the upshot from JSON format to a PHP array   $jsonResponse = json_decode( $response );  render $jsonResponse->access_token; }   part make_post_call($url, $postdata) {  global $token;  $curl = curl_init($url);   curl_setopt($curl, CURLOPT_POST, true);  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  curl_setopt($curl, CURLOPT_HEADER, false);  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  curl_setopt($curl, CURLOPT_HTTPHEADER, array(     'Authorization: Bearer '.$token,     'Accept: application/json',     'Content-Type: application/json'     ));    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);   #curl_setopt($curl, CURLOPT_VERBOSE, TRUE);  $response = curl_exec( $curl );  if (empty($response)) {      // some sort of an fault happened      die(curl_error($curl));      curl_close($curl); // unopen cURL handler  } else {      $info = curl_getinfo($curl);   echo "Time took: " . $info['total_time']*1000 . "ms\n";      curl_close($curl); // unopen cURL handler   if($info['http_code'] != 200 && $info['http_code'] != 201 ) {    echo "Received error: " . $info['http_code']. "\n";    echo "Raw response:".$response."\n";    die();      }  }   // Convert the upshot from JSON format to a PHP array   $jsonResponse = json_decode($response, TRUE);  render $jsonResponse; }  echo "\n"; echo "###########################################\n"; echo "Obtaining OAuth2 Access Token.... \n"; $url = $host.'/v1/oauth2/token';  $postArgs = 'grant_type=client_credentials'; $token = get_access_token($url,$postArgs); echo "Got OAuth Token: ".$token; echo "\n \n"; echo "###########################################\n"; echo "Initiating a Payment amongst PayPal Account... \n"; $url = $host.'/v1/payments/payment'; $payment = array(                 'intent' => 'sale',                 'payer' => array(                         'payment_method' => 'paypal'   ),                 'transactions' => array (array(                                 'amount' => array(                                         'total' => '7.47',                                         'currency' => 'USD'                                         ),                                 'description' => 'payment using a PayPal account',                                                                               'item_list' => array(                                 'items' => array(                                 array(                                 'quantity' => '1',                                 'name' => 'Book',                                 'price' => '7.47',                                 'sku' => 'ISBN96821394391231',                                 'currency' => 'USD',                                 'tax' => '0'                                                         )),                                 ))),   'redirect_urls' => array (    'return_url' => 'http://www.example.com/paypal/return.php',    'cancel_url' => 'http://www.example.com/paypal/cancel.php'   )                 ); $json = json_encode($payment); $json_resp = make_post_call($url, $json); foreach ($json_resp['links'] equally $link) {  if($link['rel'] == 'execute'){   $payment_execute_url = $link['href'];   $payment_execute_method = $link['method'];  } else  if($link['rel'] == 'approval_url'){    $payment_approval_url = $link['href'];    $payment_approval_method = $link['method'];   } } echo "Payment Created successfully: " . $json_resp['id'] ." amongst acre '". $json_resp['state']."'\n\n"; echo "Please goto <a href='".$payment_approval_url."'>link</a> inward your browser together with approve the payment amongst a PayPal Account.\n"; ?> 
of import hither is the 'item_list' together with the means it is nested. See StackOverflow together with PayPal's extended payment capabilities for farther details.

As amongst the previous post an access token is obtained together with that token is straightaway used equally a means to brand a PayPal payment. All the standalone Credit Card processes accept been stripped from PayPal's sample code along amongst the execution code, which is something that needs to last placed inside the page that is located at your return_url.

To brand this run you lot bespeak to house your ain values inside the $clientId together with $secret variables equally good supercede the generic return_url together with cancel_url inside the $payment variable.


Comments

Popular posts from this blog

Removing The Index.Php File From Url Inward Codeigniter

What Are The Main Components of a Computer System

Delete Daily Doppler E-Mail Spam From An Iphone [Fix]