php - Paypal PHP REST 服务 - "access token does not have required scope"

标签 php rest paypal

我正在使用 Paypal REST SDK 在 PHP 中进行编码。我已将我的 Sandbox 帐户设置为使用 AUD。在意识到我的初始交易以美元为单位并且交易被保留后,我解决了这个问题。

使用我修改后的代码,我正在尝试创建付款 - 我假设我会取回一个 URL,该 URL 将允许我重定向用户以批准付款。

我收到一条消息说:

Exception: Got Http response code 403 when accessing https://api.sandbox.paypal.com/v1/payments/payment. Retried 0 times. string(215) "{"name":"REQUIRED_SCOPE_MISSING","message":"Access token does not have required scope","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#REQUIRED_SCOPE_MISSING","debug_id":"34683601f5dcd"}"

我的代码是: $apiContext = new ApiContext(new OAuthTokenCredential( 'xxxxxx', 'xxxxxx'));

    //### FundingInstrument
    // A resource representing a Payer's funding instrument.
    // For direct credit card payments, set the CreditCard
    // field on this object.
    $fi = new FundingInstrument();
    $creditCardToken = new CreditCardToken();
    $creditCardToken->setCreditCardId($creditcard->cardToken);
    $fi->setCreditCardToken($creditCardToken);

    // ### Payer
    // A resource representing a Payer that funds a payment
    // For direct credit card payments, set payment method
    // to 'credit_card' and add an array of funding instruments.
    $payer = new Payer();
    $payer->setPaymentMethod("credit_card")
        ->setFundingInstruments(array($fi));

    // ### Itemized information
    // (Optional) Lets you specify item wise
    // information
    $paymentItems=Yii::app()->session['paymentitems'];
    $items=array();
    $total=0;
    foreach ($paymentItems as $item)
    {
        $pp_item = new Item();
        $pp_item->setName("Donation to ".$item->organisation->organisationName)
            ->setCurrency('AUD')
            ->setQuantity(1)
            ->setPrice($item->amount);
        array_push($items,$pp_item);
        $total+=(float)$item->amount;
    }
    $itemList = new ItemList();
    $itemList->setItems($items);        
    // ### Amount
    // Lets you specify a payment amount.
    // You can also specify additional details
    // such as shipping, tax.
    $amount = new Amount();
    $amount->setCurrency("AUD")
        ->setTotal($total);

    // ### Transaction
    // A transaction defines the contract of a
    // payment - what is the payment for and who
    // is fulfilling it. 
    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setItemList($itemList)
        ->setDescription("Payment description");

    // ### Payment
    // A Payment Resource; create one using
    // the above types and intent set to sale 'sale'
    $payment = new Payment();
    $payment->setIntent("sale")
        ->setPayer($payer)
        ->setTransactions(array($transaction));
    // ### Create Payment
    // Create a payment by calling the payment->create() method
    // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) href

    // The return object contains the state.
    try {
        $response=$payment->create($apiContext);
        var_dump($response);
        //$this->redirect($response->links[0]->href);
    } catch (PayPal\Exception\PPConnectionException $ex) {
        echo "Exception: " . $ex->getMessage() . PHP_EOL;
        var_dump($ex->getData());
        exit(1);
    }

关于此消息的含义的任何想法。 Paypal 在澳大利亚似乎不支持直接信用卡付款,但我认为这不是问题所在。

最佳答案

在您的 Paypal 开发者帐户中,在“我的应用”>“[您的应用]”下,确保您尝试使用的功能已在“应用设置”部分中启用。

Example App Settings

关于php - Paypal PHP REST 服务 - "access token does not have required scope",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21642571/

相关文章:

javascript - JavaScript 中 document.cookie 的替代方案

javascript - angularjs http.post() 未收到响应

从一个 docker 容器到另一个容器的 REST 请求失败

javascript - 调用 MVC Controller 操作以返回 Wordpress 网站的 View

php - 购物车商品总金额与 Paypal 快速结帐订单金额不符

php - 根据MySQL中的条件删除所有行

php - 尽管使用 PHP 具有适当的权限,但权限被拒绝

rest - Jenkins REST buildWithParameters 覆盖默认参数值的 JSON 格式是什么

javascript - PayPal Oauth 上的 return_uri 无效

android - 我如何使用测试帐户进入 Android 中的 Paypal 沙箱?