Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. // checkout.php -> no form ao clicar no botão será redirecionado para este arquivo.
  3. // Supostamente está correto, né?!
  4. if(!isset($_POST['clientId']) || !isset($_POST['clientSecret'])) return;
  5.  
  6. use 'PayPal\Core\PayPalHttpClient';
  7. use 'PayPal\Core\SandboxEnvironment';
  8.  
  9. $clientId = $_POST['clientId'];
  10. $clientSecret = $_POST['clientSecret'];
  11.  
  12. $environment = new SandBoxEnvironment($clientId, $clientSecret);
  13. $client = new PayPalHttpClient($environment);
  14.  
  15. // Construct a request object and set desired parameters
  16. // Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
  17. use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
  18. $request = new OrdersCreateRequest();
  19. $request->prefer('return=representation');
  20. $request->body = [
  21.                      "intent" => "CAPTURE",
  22.                      "purchase_units" => [[
  23.                          "reference_id" => "test_ref_id1",
  24.                          "amount" => [
  25.                              "value" => "100.00",
  26.                              "currency_code" => "USD"
  27.                          ]
  28.                      ]],
  29.                      "application_context" => [
  30.                           "cancel_url" => "https://example.com/cancel",
  31.                           "return_url" => "https://example.com/return"
  32.                      ]
  33.                  ];
  34.  
  35. try {
  36.     // Call API with your client and get a response for your call
  37.     $response = $client->execute($request);
  38.    
  39.     // If call returns body in response, you can get the deserialized version from the result attribute of the response
  40.     print_r($response);
  41. }catch (HttpException $ex) {
  42.     echo $ex->statusCode;
  43.     print_r($ex->getMessage());
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement