fork download
  1. <?php
  2. print_r($_REQUEST);
  3.  
  4. include '../app/autoload.php';
  5. include '../app/Core/Library/PayPalCheckout/vendor/autoload.php';
  6.  
  7. use PayPalCheckoutSdk\Core\PayPalHttpClient;
  8. use PayPalCheckoutSdk\Core\SandboxEnvironment;
  9.  
  10. $clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  11. $clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  12.  
  13.  
  14. $environment = new SandboxEnvironment($clientId, $clientSecret);
  15. $client = new PayPalHttpClient($environment);
  16.  
  17. use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
  18. $request = new OrdersCaptureRequest($_GET['token']);
  19. $request->prefer('return=representation');
  20.  
  21. try {
  22. $response = $client->execute($request);
  23. if ($response->statusCode == 201) {
  24. print "<h1>Captured Successfully</h1>";
  25. print "Status Code: {$response->statusCode}<br />";
  26. print "Status: {$response->result->status}<br />";
  27. print "Order ID: {$response->result->id}<br />";
  28. print "Links:<br />";
  29. for ($i = 0; $i < count($response->result->links); ++$i){
  30. $link = $response->result->links[$i];
  31. print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}<br /><br>";
  32. }
  33.  
  34. foreach($response->result->purchase_units as $purchase_unit) {
  35. foreach($purchase_unit->payments->captures as $capture) {
  36. $captureId = $capture->id;
  37. }
  38. }
  39. foreach ($response->result->purchase_units[0]->items as $items) {
  40. echo "Item: {$items->name}<br>";
  41. echo "Price: {$items->unit_amount->value}<br>";;
  42. }
  43.  
  44. $arr= json_encode($response, JSON_PRETTY_PRINT);
  45. } else {
  46. exit(1);
  47. }
  48. } catch (HttpException $ex) {
  49. echo $ex->statusCode;
  50. print_r($ex->getMessage());
  51. }
  52.  
  53. ?>
Runtime error #stdin #stdout #stderr 0.02s 25804KB
stdin
Standard input is empty
stdout
Array
(
)
stderr
PHP Warning:  include(../app/autoload.php): failed to open stream: No such file or directory in /home/DhiJxa/prog.php on line 4
PHP Warning:  include(): Failed opening '../app/autoload.php' for inclusion (include_path='.:/usr/share/php') in /home/DhiJxa/prog.php on line 4
PHP Warning:  include(../app/Core/Library/PayPalCheckout/vendor/autoload.php): failed to open stream: No such file or directory in /home/DhiJxa/prog.php on line 5
PHP Warning:  include(): Failed opening '../app/Core/Library/PayPalCheckout/vendor/autoload.php' for inclusion (include_path='.:/usr/share/php') in /home/DhiJxa/prog.php on line 5
PHP Fatal error:  Uncaught Error: Class 'PayPalCheckoutSdk\Core\SandboxEnvironment' not found in /home/DhiJxa/prog.php:14
Stack trace:
#0 {main}
  thrown in /home/DhiJxa/prog.php on line 14