Paypal PHP REST服务-“访问令牌没有必需的范围" [英] Paypal PHP REST service - "access token does not have required scope"

查看:100
本文介绍了Paypal PHP REST服务-“访问令牌没有必需的范围"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Paypal REST SDK在PHP中进行编码.我已将沙盒帐户设置为使用AUD.在意识到我的初始交易以美元计价并且交易被保留后,我进行了计算.

I'm coding in PHP using the Paypal REST SDK. I've set up my Sandbox account to use AUD. I worked this out after realising that my initial transactions were in USD and the transactions were getting held.

使用修改后的代码,我尝试创建付款-我假设我将获得一个URL,该URL可使我重定向用户以批准付款.

Using my revised code I'm trying to create payment - I assume I'll get back a URL which will allow me to redirect the user to approve the payment.

我收到一条消息,提示:

I'm getting a message which says:

例外:访问 https://api.sandbox.paypal时,获得了Http响应代码403 .com/v1/payments/payment .重试0次. 字符串(215)"{"名称:" REQUIRED_SCOPE_MISSING,"消息:"访问令牌没有必需的范围," information_link:"

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 =新的ApiContext(新的OAuthTokenCredential( 'xxxxxx', 'xxxxxx'));

My code is: $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);
    }

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

Any thoughts as to what this message means. It would seem that direct credit card payments are not supported by Paypal in Australia, but I don't think that's the problem.

推荐答案

在您的Paypal开发人员帐户中,在我的应用">"[您的应用]"下,确保在应用设置"部分中启用了您要使用的功能.

In your Paypal developer account, under My Apps > [Your App], make sure the feature you are trying to use is enabled in the APP SETTINGS section.

这篇关于Paypal PHP REST服务-“访问令牌没有必需的范围"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆