dourao3960 2017-01-09 02:29
浏览 103

Paypal API不会完全加载到服务器上,而是加载到localhost上

I'm having this problem where ther Paypal API is not loading on my server but it loads completely normal on my localhost. I really don't know what and where it went wrong. Everything is the same as I upload files from my localhost to the server, nothing change and it's exactly the same files.

When making a payment using Paypal REST API, I had this error on my server but not on my localhost.

Fatal error: Class 'PayPal\Api\item' not found in /var/www/test.my-domain.com/public_html/controllers/credits.php on line 24

My code as below:

require_once('./inc/lib/paypal/autoload.php');
$apiContext = new \PayPal\Rest\ApiContext(
            new \PayPal\Auth\OAuthTokenCredential(
                'hidden-clientid',// ClientID
                'hidden-secret'// ClientSecret
            )
        );

        if (isset($_POST['checkout'])) {
            $payer = new \PayPal\Api\Payer();
            $payer->setPaymentMethod('paypal');

            $item = new \PayPal\Api\item();
            $item->setName('Top Up')
                    ->setDescription('My account.')
                    ->setCurrency('USD')
                    ->setQuantity(1)
                    ->setTax(0)
                    ->setPrice(10);

            $itemList = new \PayPal\Api\itemList();
            $itemList->setItems(array($item));

            $details = new \PayPal\Api\details();
            $details->setShipping("0")
                    ->setTax("0")
                    ->setSubtotal(10);

            $amount = new \PayPal\Api\amount();
            $amount->setCurrency("USD")
                   ->setTotal(10)
                   ->setDetails($details);

            $transaction = new \PayPal\Api\transaction();
            $transaction->setAmount($amount)
                ->setItemList($itemList)
                ->setDescription("Top up account")
                ->setInvoiceNumber(uniqid());

            $redirectUrls = new \PayPal\Api\RedirectUrls();
            $redirectUrls->setReturnUrl("http://".$_SERVER["HTTP_HOST"].$web_path."credits/done?status=success");
            $redirectUrls->setCancelUrl("http://".$_SERVER["HTTP_HOST"].$web_path."credits/done?status=cancel");

            $payment = new \PayPal\Api\Payment();
            $payment->setIntent('sale');
            $payment->setPayer($payer);
            $payment->setRedirectUrls($redirectUrls);
            $payment->setTransactions(array($transaction));

            $response = $payment->create($apiContext);
            $redirectUrl = $response->links[1]->href;

            header( "Location: $redirectUrl" );

The weird part is that it goes through $payer->setPaymentMethod('paypal'); But it does not pass at $item = new \PayPal\Api\item();

All code are the same as my localhost and it works on my localhost. The Paypal API is also uploaded on my server on the exact location (/inc/lib/paypal/).

  • 写回答

2条回答 默认 最新

  • dongyi2993 2017-01-09 02:35
    关注

    What does the autoload contain. Try and use the full path EX: /var/www/test.my-domain.com/public_html when using the autoload or

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗