paypal / PayPal-PHP-SDK

PHP SDK for PayPal RESTful APIs
https://developer.paypal.com/docs/api/
Other
26 stars 98 forks source link

"$payer = new Payer();" Causing HTTP ERROR 500 #825

Closed SDCore closed 7 years ago

SDCore commented 7 years ago

General information

Issue description

I have a local Windows WAMP Server using the PHP SDK. It uses the API to send off a few things of data, you pay for it, and it's done.

On the WAMP Server, it's fine. But yesterday, just to test on a live sandbox before I deploy to production, I put it on a Digital Ocean Ubuntu 14.04 server. I narrowed it down to $payer = new Payer(); causing the issue.

Is there any help I could get with this? Thank you.

Edit:

When I get these errors, they're not from the API. The whole page seems to break.

On Chrome:

This page isn’t working

159.203.15.127 is currently unable to handle this request.

HTTP ERROR 500

And on Opera:

This page isn’t working

159.203.15.127 is currently unable to handle this request.
xiaoleih41 commented 7 years ago

Do you have PHP SDK installed on your Ubuntu server? It will be helpful if you can provide a debug_ID and the specific call you are trying to make and the steps you've taken to reproduce this error. Please help provide more detail information for us to understand the issue.

SDCore commented 7 years ago

I would assume it's installed. I copied the files directly from the WAMP server directory, including the composer.json and composer.lock, and all the files in vendor as well. Are there any other steps I need to take to install it? Does it not stay installed when moving files from a local machine to a server?

And I'm unable to get a debug ID since I can't even get any information from Paypal at all. If it's something with the installation, I could try and fix that and if I'm still getting the error I can provide it.

I've copied all the files from my machine (includes the composer files and vendor folder).

The code below illustrates the beginning of the checkout file that the form posts to, which redirects to the paypal payment page.

<?php
    use PayPal\Api\Payer;
    use PayPal\Api\Item;
    use PayPal\Api\ItemList;
    use PayPal\Api\Details;
    use PayPal\Api\Amount;
    use PayPal\Api\Transaction;
    use PayPal\Api\RedirectUrls;
    use PayPal\Api\Payment;

    require 'app/start.php';

    $product = "productName";
    $price = $_POST['inputPriceHidden'];
    $shipping = 0.00;

    $total = $price; // Just temporary, can be changed later

    $payer = new Payer();
    $payer->setPaymentMethod('paypal');

I went through line by line and once I get to $payer = new Payer(); the HTTP 500 error shows up, so either it's not installed or I'm doing something wrong.

jaypatel512 commented 7 years ago

I am assuming from the code, you are including vendor/autoload.php inside app/start.php.

If that is the case, can you try putting require 'app/start.php' at the top immediately after <?php.

<?php
    require 'app/start.php';

    use PayPal\Api\Payer;
    use PayPal\Api\Item;
    use PayPal\Api\ItemList;
    use PayPal\Api\Details;
    use PayPal\Api\Amount;
    use PayPal\Api\Transaction;
    use PayPal\Api\RedirectUrls;
    use PayPal\Api\Payment;

    $product = "productName";
    $price = $_POST['inputPriceHidden'];
    $shipping = 0.00;

    $total = $price; // Just temporary, can be changed later

    $payer = new Payer();
    $payer->setPaymentMethod('paypal');
SDCore commented 7 years ago

Just tried that, it still throws the 500 error.

SDCore commented 7 years ago

I got it to work. I installed the SDK manually and checked the error in apache's error logs, turns it out just wasn't able to find the right directories for the files.

molhamch commented 6 years ago

@SDCore can you please explain how did you get it to work , because i am running with the exact problem , thank you

SDCore commented 6 years ago

@molhamch I don't remember exactly right off hand (as this was nearly 7 months ago) but I remember I had to either change the directories themselves (some of the backend files that came with the SDK) or I just had to create a few folders.

If you're able to view your Apache Error Logs, take a look at that. They should tell you the exact missing files or directories that you need followed by a 500 error.