Skip to main content

PayPal Community

  • Dashboard
  • Send and Request
  • Wallet
  • Business
  • Help
Log in

Le forum de Communauté ne sera plus disponible à partir du 30 Juin 2025. Le Forum de la communauté n’est pas disponible pour les nouveaux messages ou les réponses; les articles précédents restent disponibles pour vérification. Afin de connaître les options d’assistance complètes, rendez-vous sur PayPal.com/HelpCenter

Si vous souhaitez signaler du contenu illégal et contraire au Règlement sur les services numériques de l’Union Européenne (DSA), veuillez cliquer ici.

since ‎Mar-25-2020
Country: Argentina
Type: Business
Lemonathor
Lemonathor
New Community Member
1
Post
0
Kudos
0
Solutions
Active
View all
Latest Contributions by Lemonathor
  • Topics Lemonathor has Participated In
  • Latest Contributions by Lemonathor

Setting up transaction from server doesn't work.

by Lemonathor in SDKs
‎Mar-25-2020 09:42 AM
‎Mar-25-2020 09:42 AM
This is the code taken from here: Server integration, set up transaction.       <?php namespace Sample\CaptureIntentExamples; require __DIR__ . '/vendor/autoload.php'; //1. Import the PayPal SDK client that was created in `Set up Server-Side SDK`. use Sample\PayPalClient; use PayPalCheckoutSdk\Orders\OrdersCreateRequest; class CreateOrder { // 2. Set up your server to receive a call from the client /** *This is the sample function to create an order. It uses the *JSON body returned by buildRequestBody() to create a new order. */ public static function createOrder($debug=false) { $request = new OrdersCreateRequest(); $request->prefer('return=representation'); $request->body = self::buildRequestBody(); // 3. Call PayPal to set up a transaction $client = PayPalClient::client(); $response = $client->execute($request); if ($debug) { print "Status Code: {$response->statusCode}\n"; print "Status: {$response->result->status}\n"; print "Order ID: {$response->result->id}\n"; print "Intent: {$response->result->intent}\n"; print "Links:\n"; foreach($response->result->links as $link) { print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; } // To print the whole response body, uncomment the following line // echo json_encode($response->result, JSON_PRETTY_PRINT); } // 4. Return a successful response to the client. return $response; } /** * Setting up the JSON request body for creating the order with minimum request body. The intent in the * request body should be "AUTHORIZE" for authorize intent flow. * */ private static function buildRequestBody() { return array( 'intent' => 'CAPTURE', 'application_context' => array( 'return_url' => 'https://example.com/return', 'cancel_url' => 'https://example.com/cancel' ), 'purchase_units' => array( 0 => array( 'amount' => array( 'currency_code' => 'USD', 'value' => '220.00' ) ) ) ); } } /** *This is the driver function that invokes the createOrder function to create *a sample order. */ if (!count(debug_backtrace())) { CreateOrder::createOrder(true); } ?>       The button NEVER renders. The console is full of errors:       SyntaxError: Unexpected end of JSON input Uncaught SyntaxError: Unexpected end of JSON input       What am I missing? There is no explanation on the docs page.   Also I need to ask: Is "Smart Checkout" the best option for the following case? All I need is to be able to have a button with a fixed price (that the user cannot change), and be reported (a simple POST to my back) if anyone makes a payment so I can change the user account to "premium" level.   Thanks in advance. ... View more
Paypal Logo
  • Help
  • Contact Us
  • Security
  • Fees
  • © 1999-2025 PayPal, Inc. All rights reserved.
  • Privacy
  • Legal
  • Cookies
  • Policy Updates

The money in your balance is eligible for pass-through FDIC insurance.

The PayPal Cash Mastercard is issued by The Bancorp Bank pursuant to a license by Mastercard International Incorporated. The Bancorp Bank; Member FDIC.

Powered by Khoros