doudai8083 2015-06-04 10:09
浏览 141
已采纳

paypal live - 使用Rest API获取响应代码400 PERMISSION_DENIED

Edited: It seems we having a trouble with the business account. Does anyone know how to set up a business account for RestApi?

I did a RestApi payment in symfony with paypal rest-api sdk. Everything works properly in sandbox but it fails in live.

  • The PayPal account is actived
  • Account payment solution setted for Website Payments Standard
  • Api Client and Secret key changed to live credentials
  • Api context mode also changed to live

Here is the code:

$clientId = $this->container->getParameter('paypal_client_id');
$secret = $this->container->getParameter('paypal_secret');
$paypalMode = $this->container->getParameter('paypal_mode'); // live
$oauthCredential = new OAuthTokenCredential($clientId, $secret);
$apiContext = new ApiContext($oauthCredential);
$apiContext->setConfig(
    [
        'log.LogEnabled' => true,
        'log.FileName' => $logDir.'/PayPal.log',
        'log.LogLevel' => 'FINE',
        'mode' => $paypalMode,
    ]
);

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

$item = new Item();
$item->setName($subTl->getName())
    ->setDescription($subTl->getDescription())
    ->setCurrency('EUR')
    ->setQuantity('1')
    ->setTax('0')
    ->setPrice($subPrice);

$items[] = $item;
$sumPrice = 0;
/** @var Item $item */
foreach ($items as $item) {
    $sumPrice += (int)$item->getPrice();
}

$itemList = new ItemList();
$itemList->setItems([$item]);

$details = new Details();
$details->setShipping('0')
    ->setTax('0')
    ->setSubtotal($subPrice);

$amount = new Amount();
$amount->setCurrency("EUR")
    ->setTotal($sumPrice)
    ->setDetails($details);

$transaction = new Transaction();
$transaction
    ->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription("Payment description");

$urls = new RedirectUrls();
$urls
    ->setCancelUrl($baseUrl . $this->cancelUrl)
    ->setReturnUrl($baseUrl . $this->successUrl);

$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($payer)
    ->setTransactions([$transaction])
    ->setRedirectUrls($urls);

$payment->create($apiContext);

Then I got the approval_url, redirecting the user to that. After the pay it returns me to my callback url.

$clientId = $this->container->getParameter('paypal_client_id');
$secret = $this->container->getParameter('paypal_secret');
$oauthCredential = new OAuthTokenCredential($clientId, $secret);
$apiContext = new ApiContext($oauthCredential);
$logDir = $this->createLogDir();
$apiContext->setConfig(
    [
        'log.LogEnabled' => true,
        'log.FileName' => $logDir.'/PayPal.log',
        'log.LogLevel' => 'FINE',
        'mode' => $paypalMode,
    ]
);

$query = $request->query->all();
if (isset($query['success']) && $query['success'] == 'true') {
    $paymentId = $query['paymentId'];
    $payment = Payment::get($paymentId, $apiContext);
    $execution = new PaymentExecution();
    $execution->setPayerId($query['PayerID']);

    try {
        $payment->execute($execution, $apiContext);

        try {
            $payment = Payment::get($paymentId, $apiContext);
        } catch (PayPalConnectionException $ex) {
            // fail 1
        }
    } catch (PayPalConnectionException $ex) {
        // fail 2
    }
    if ($payment->getState() == 'approved') {
        // EVERYTHING IS OK
    }
}

Im getting "fail 2", and the log is the following:

PayPal\Core\PayPalHttpConnection: ERROR: Got Http response code 400 when accessing https://api.paypal.com/v1/payments/payment/PAY-66T29544VN4574806KVYBFFA/execute. {"name":"PERMISSION_DENIED","message":"No permission for the requested operation","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#PERMISSION_DENIED","debug_id":"976cbb71b5e10"}
  • 写回答

1条回答 默认 最新

  • duanchi6397 2015-06-29 09:42
    关注

    It wasn't the code. PayPal does not support that kind of love site with business accounts which we wanted to be live.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集