1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How fix paypal error with response code 400

Discussion in 'PayPal' started by mstdmstd, Jul 10, 2019.

  1. #1
    Hello,
    Implementing paypal in my laravel 5.8 app
    I got error :
    Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAYID-NNNNNNNNNN/execute.
    Code (markup):
    My control :
        public function paypal_payment_execute()
        {
            // After Step 1
            $apiContext = new \PayPal\Rest\ApiContext(
                new \PayPal\Auth\OAuthTokenCredential(
                    'NNNNN',     // ClientID
                    'NNNNN'      // ClientSecret
                )
            );
            $paymentId = request('paymentId');
            $PayerID = request('PayerID');
            $payment = Payment::get($paymentId, $apiContext);
            $execution = new PaymentExecution();
            $execution->setPayerId( $PayerID);
            $transaction = new Transaction();
            $amount = new Amount();
            $details = new Details();
            $details->setShipping(1.2)
                    ->setTax(1.3)
                    ->setSubtotal(17.50); //
            $amount->setCurrency('USD');
            $total_sum= 20; // I check this sum is setShipping + setTax + setSubtotal
            $amount->setTotal( (integer)$total_sum);
            $amount->setDetails($details);
            $transaction->setAmount($amount);
            $execution->addTransaction( [ $transaction ] );  // !!! I found that here must be an array?
            try {
                $result = $payment->execute($execution, $apiContext);  // Number of error points at this line
            } catch (Exception $pce) {
                echo '<pre>::'.print_r( json_decode($pce->getData()) );
                die("-1 XXZ  app/Http/Controllers/PaymentController.php");
            }
            return $result;
        } 
    PHP:
    I my browse I see output : https://prnt.sc/od3b6v
    1) Can somebody say which kind of error is it ?
    2) I see lines like :
     $this->logger->info
    PHP:
    Is it some logging ? Where can I look into it ?
    3) That was very strange that error line was shown and not pre output in try catch block:
    I expected to see pce->getData output:
            } catch (Exception $pce) {
                echo '<pre>::'.print_r( json_decode($pce->getData()) );
                die("-1 XXZ  app/Http/Controllers/PaymentController.php");
            }
    PHP:
    4) Searching I net I checked that making payment With JS code I set the same total and return urls, like :
    SEMrush
    <div id="paypal-button"></div>
    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
    <script>
       let total_sum= 20
       alert( "-123  total_sum::"+(total_sum) )
       paypal.Button.render({
          // Configure environment
          env: 'sandbox',
          client: {
             sandbox: 'NNNNN',
             production: 'demo_production_client_id'
          },
          locale: 'en_US',
          style: {
             size: 'small',
             color: 'blue',
             shape: 'pill',
          },
          commit: true,
          payment: function(data, actions) {
             var payment = actions.payment.create({
                "note_to_payer": "Contact us for any questions on your order.",
                "intent": "sale",
                "payer": {
                   "payment_method": "paypal"
                },
                redirect_urls : { //redirect_urls
                   return_url : '...paypal_payment',
                   cancel_url : '.../paypal_payment_cancel'
                },
              
                transactions: [{
                   amount: {
                      total:  Number( total_sum ),
                      currency: 'USD'
                   }
                }]
             });
             return payment;
            
          },
          onAuthorize: function(data, actions) {
             return actions.payment.execute().then(function() {
                return actions.redirect();
             });
          }
       }, '#paypal-button');
    </script>
    Code (JavaScript):
    On error in apps log I found :
     
    2019-07-10 11:12:44] local.ERROR: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LUS4QGI75E1056086596714T/execute. {"exception":"[object] (PayPal\\Exception\\PayPalConnectionException(code: 400): Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LUS4QGI75E1056086596714T/execute. at /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:207)
    [stacktrace]
    #0 /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(78): PayPal\\Core\\PayPalHttpConnection->execute('{\"payer_id\":\"Z9...')
    #1 /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(104): PayPal\\Transport\\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{\"payer_id\":\"Z9...', Array)
    #2 /var/www/html/votes/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/Payment.php(650): PayPal\\Common\\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{\"payer_id\":\"Z9...', NULL, Object(PayPal\\Rest\\ApiContext), Object(PayPal\\Transport\\PayPalRestCall))
    #3 /var/www/html/votes/app/Http/Controllers/PaymentController.php(102): PayPal\\Api\\Payment->execute(Object(PayPal\\Api\\PaymentExecution), Object(PayPal\\Rest\\ApiContext))
    #4 [internal function]: App\\Http\\Controllers\\PaymentController->paypal_payment_execute()
    #5 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
    #6 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('paypal_payment_...', Array)
    #7 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\PaymentController), 'paypal_payment_...')
    #8 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
    #9 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\\Routing\\Route->run()
    #10 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #11 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #12 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #13 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #14 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(75): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #15 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #16 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #17 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #18 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #19 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #20 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #21 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #22 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #23 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #24 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #25 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #26 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #27 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #28 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #29 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #30 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
    #31 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
    #32 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
    #33 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
    #34 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
    #35 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
    #36 /var/www/html/votes/vendor/proengsoft/laravel-jsvalidation/src/RemoteValidationMiddleware.php(53): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #37 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Proengsoft\\JsValidation\\RemoteValidationMiddleware->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #38 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #39 /var/www/html/votes/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(65): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #40 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #41 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #42 /var/www/html/votes/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #43 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #44 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #45 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #46 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #47 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #48 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #49 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #50 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #51 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #52 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #53 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #54 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #55 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #56 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #57 /var/www/html/votes/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkMiddleware.php(29): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #58 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Clockwork\\Support\\Laravel\\ClockworkMiddleware->handle(Object(Illuminate\\Http\\Request), Object(Closure))
    #59 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
    #60 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
    #61 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
    #62 /var/www/html/votes/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
    #63 /var/www/html/votes/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
    #64 {main}  
    Code (markup):
    How fix it ?
    composer.json :
        "type": "project",
        "require": {
            "php": "^7.1.3",
            ...
            "laravel/framework": "5.8.*",
            "paypal/rest-api-sdk-php": "*",
    Code (markup):
     
    mstdmstd, Jul 10, 2019 IP
    SEMrush