paypal live - 获取响应代码400 PERMISSION_DENIED with RestAPI

时间:2015-06-04 10:09:43

标签: php symfony paypal

编辑:我们似乎遇到了商业帐户问题。有谁知道如何为RestApi设置商业帐户?

我使用paypal rest-api sdk在symfony中进行了RestApi付款。一切都在沙盒中正常工作,但它在实时失败。

  • PayPal帐户已启用
  • 为网站付款标准设置的帐户付款解决方案
  • Api客户端和密钥已更改为实时凭据
  • Api上下文模式也已更改为实时

以下是代码:

$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);

然后我获得了approval_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
    }
}

我得到"失败2",日志如下:

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 个答案:

答案 0 :(得分:0)

这不是代码。 PayPal不支持那种我们希望生活的商业帐户的爱情网站。