访问 https://api.sandbox.paypal.com/v1/payments/billing-plans/ 时得到 Http 响应代码 403

Got Http response code 403 when accessing https://api.sandbox.paypal.com/v1/payments/billing-plans/

我正在整合贝宝账单api。但收到 HTTP 403 错误代码。

我调用了 createPlan() 方法。 我在 caklling api 时收到 HTTP 403 状态。 我还实现了完美的 experess 结帐,但我不知道它会导致错误。

请查看以下内容link,了解有关此电话的更多信息。

<?php
namespace App\Http\Controllers;

use Request as Requests;
use DB;
use Illuminate\Http\Request;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Redirect;

use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\PaymentDefinition;
use PayPal\Api\Currency;
use PayPal\Api\Plan;
use PayPal\Api\MerchantPreferences;
use PayPal\Api\ChargeModel;



class SubscriptionPlan extends PaypalPaymentController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Create subscription plan
     * @param $planInfo array
     * return $plan object
     */ 

    public function plan($planInfo=array())
    {
        $plan = new Plan();
        $plan->setName($planInfo['planName'])
        ->setDescription($planInfo['planDesc'])
        ->setType($planInfo['planType']);

        return $plan;
    }

    /**
     * Billing cycle 
     * @param $planInfo array
     * 
     */ 

    public function paymentDefinition($paymentDefination=array())
    {
        $paymentDefinition = new PaymentDefinition();
        $paymentDefinition->setName($paymentDefination['name'])
        ->setType($paymentDefination['type'])
        ->setFrequency($paymentDefination['frequency'])
        ->setFrequencyInterval($paymentDefination['interval'])
        ->setCycles($paymentDefination['cycle'])
        ->setAmount(new Currency(array('value' => $paymentDefination['amount'], 'currency' => $paymentDefination['currency'])));

        return $paymentDefinition;
    }


    /**
     * Billing cycle 
     * @param $charge deatails array
     * 
     */ 

    public function charge($charge=array())
    {
        $chargeModel = new ChargeModel();
        $chargeModel->setType($charge['type'])
                    ->setAmount(new Currency(array('value' => $charge['amount'], 'currency' => $charge['currency'])));
        return array($chargeModel);            
    }

    /**
     * Set merchant preferences 
     * @param $merchantPref deatails array
     * 
     */ 

    public function merchantPreferences($merchantPref=array())
    {
        $merchantPreferences = new MerchantPreferences();

        $merchantPreferences->setReturnUrl($merchantPref['successUrl'])
        ->setCancelUrl($merchantPref['failUrl'])
        ->setAutoBillAmount($merchantPref['autoBillAmount'])
        ->setInitialFailAmountAction($merchantPref['initialFailAmountAction'])
        ->setMaxFailAttempts($merchantPref['maxFailAttempts'])
        ->setSetupFee(new Currency(array('value' => $merchantPref['amount'], 'currency' => $merchantPref['currency'])));

        return $merchantPreferences;


    }

    /**
     * Create subscription Plan
     * @param $palnDetails
     * return
     */ 

    public function createPlan()
    {

        $palnDetails['planInfo'] = array('planName'=>"Silver Plan",
                                        'planDesc'=>"Taskenator silver plan ",
                                        'planType'=>"INFINITE"
                                      );

        $palnDetails['paymentDefination'] = array('name'=>'Taskenator Plan Payment',
                                               'type'=>'REGULAR',
                                               'frequency'=>'MONTH',
                                               'interval'=>1,
                                               'cycle'=>0,
                                               'amount'=>10,
                                               'currency'=>'USD'
                                               );
        //$palnDetails['charge']=array();
        $palnDetails['merchantPref']    = array('successUrl'=>'https://www.example.com/subscription/true',
                                          'failUrl'=>'https://www.example.com/subscription/false',
                                          'autoBillAmount'=>'yes',
                                          'initialFailAmountAction'=>'CONTINUE',
                                          'maxFailAttempts'=>0,
                                          'amount'=>0,
                                          'currency'=>'USD'
                                          );



        $plan              = $this->plan($palnDetails['planInfo']); 
        $paymentDefinition = $this->paymentDefinition($palnDetails['paymentDefination']);
        //$charge          = $this->charge($palnDetails['charge']);
        //$paymentDefinition->setChargeModels($charge);

        $merchantPreferences = $this->merchantPreferences($palnDetails['merchantPref']);
        $plan->setPaymentDefinitions(array($paymentDefinition));
        $plan->setMerchantPreferences($merchantPreferences);

        //preDump($this->_api_context,true);

        $request = clone $plan;

        try {
                $output = $plan->create($this->_api_context);
            } catch (Exception $ex) {
                ResultPrinter::printError("Created Plan", "Plan", null, $request, $ex);
                exit(1);
            }

        ResultPrinter::printResult("Created Plan", "Plan", $output->getId(), $request, $output);

        return $output;    

    }

    public function listPlans()
    {
        try{
            $params = array('page_size' => '10');
            $planList = Plan::all($params, $this->_api_context);
        } catch (Exception $ex) {
            ResultPrinter::printError("List of Plans", "Plan", null, $params, $ex);
            exit(1);
        }
        ResultPrinter::printResult("List of Plans", "Plan", null, $params, $planList);
        return $planList;

    }

    public function testPlan()
    {
        $plan = new Plan();
        $plan->setName('T-Shirt of the Month Club Plan')
            ->setDescription('Template creation.')
            ->setType('fixed');

        $paymentDefinition = new PaymentDefinition();

        $paymentDefinition->setName('Regular Payments')
            ->setType('REGULAR')
            ->setFrequency('Month')
            ->setFrequencyInterval("2")
            ->setCycles("12")
            ->setAmount(new Currency(array('value' => 100, 'currency' => 'USD')));

        $chargeModel = new ChargeModel();
        $chargeModel->setType('SHIPPING')
            ->setAmount(new Currency(array('value' => 10, 'currency' => 'USD')));

        $paymentDefinition->setChargeModels(array($chargeModel));

        $merchantPreferences = new MerchantPreferences();
        $baseUrl = "https://www.testtaskenator.com";

        $merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true")
            ->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false")
            ->setAutoBillAmount("yes")
            ->setInitialFailAmountAction("CONTINUE")
            ->setMaxFailAttempts("0")
            ->setSetupFee(new Currency(array('value' => 1, 'currency' => 'USD')));


        $plan->setPaymentDefinitions(array($paymentDefinition));
        $plan->setMerchantPreferences($merchantPreferences);
        //create plan
        try {
                $createdPlan = $plan->create($apiContext);
                $patch = new Patch();
                $value = new PayPalModel('{"state":"ACTIVE"}');
                $patch->setOp('replace')
                  ->setPath('/')
                  ->setValue($value);
                $patchRequest = new PatchRequest();
                $patchRequest->addPatch($patch);
                $createdPlan->update($patchRequest, $apiContext);
                $plan = Plan::get($createdPlan->getId(), $apiContext);

                // Output plan id
                echo $plan->getId();
            } catch (PayPal\Exception\PayPalConnectionException $ex) {
                    echo $ex->getCode();
                    echo $ex->getData();
                    die($ex);
            } catch (Exception $ex) {
                    die($ex);
            } catch (PayPal\Exception\PayPalConnectionException $ex) {
                  echo $ex->getCode();
                  echo $ex->getData();
                  die($ex);
            } catch (Exception $ex) {
                  die($ex);
            }
    }


}


<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Redirect;

use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api;
use Request as Requests;
use DB;

class PaypalPaymentController extends Controller
{

    public function __construct()
    {
        session_start();
        /** PayPal api context **/
        $paypal_conf = \Config::get('paypal');
        $this->_api_context = new ApiContext(new OAuthTokenCredential(
            $paypal_conf['client_id'],
            $paypal_conf['secret'])
        );

        $this->_api_context->setConfig($paypal_conf['settings']);

    }
  }

您没有此权限API