【问题标题】:paypal live - getting response code 400 PERMISSION_DENIED with RestAPIpaypal live - 使用 Rest API 获取响应代码 400 PERMISSION_DENIED
【发布时间】:2015-08-18 21:31:02
【问题描述】:

已编辑:我们的企业帐户似乎有问题。有谁知道如何为 RestApi 设置企业帐户?

我在 symfony 中使用 paypal rest-api sdk 进行了 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"}

【问题讨论】:

  • 根据错误链接,“支付状态不允许这种请求。”。当您尝试执行付款时,付款的状态是什么?
  • @JohnCartwright 表示付款状态为“已创建”
  • 对不起。一切对我来说似乎都是正确的。自从我使用 paypal 以来已经太久了(假设您的 payer_id 是有效的)。
  • @JohnCartwright 没有任何商业帐户设置可以避免我的注意吗?谢谢,顺便说一句。 :)

标签: php symfony paypal


【解决方案1】:

不是代码。 PayPal 不支持那种带有我们想要上线的商业账户的爱情网站。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 2011-03-02
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    相关资源
    最近更新 更多