无法在沙盒PayPal上创建模拟付款

时间:2018-08-14 14:10:00

标签: php symfony paypal paypal-sandbox

我在“ symfony / symfony”上使用“ paypal / rest-api-sdk-php”:“ ^ 1.11”:“ 3.2。*”(RESTapi,位于VueJs的前面)。

在我创建协议(PayPal沙箱)的那一刻,PayPal再次返回给我:

{
    "name": "BUSINESS_VALIDATION_ERROR",
    "details": [
        {
        "field": "validation_error",
        "issue": "Incorrect Plan Id."
        }
    ],
    "message": "Validation Error.",
    "information_link": "https://developer.paypal.com/docs/api/payments.billing-agreements#errors",
    "debug_id": "xxxxxxxxxxxx"
}
  1. PayPalService createAgreement:

    1. public function createAgreement($planId, $startDate = null)
    2.     {
    3.         $agreement = new Agreement();
    4.
    5.         $startDate = $startDate ?: new \DateTime('+1 hour');
    6.
    7.         if ($startDate < new \DateTime()) {
    8.             $startDate = new \DateTime('+1 hour');
    9.         }
    10.
    11.         $agreement->setName('Base Agreement')
    12.             ->setDescription('Basic Agreement')
    13.             ->setStartDate($startDate->format('c'));
    14.
    15.         // Add Plan ID
    16.         // Please note that the plan Id should be only set in this case.
    17.         $plan = new Plan();
    18.         $plan->setId($planId);
    19.         $agreement->setPlan($plan);
    20.
    21.         // Add Payer
    22.         $payer = new Payer();
    23.         $payer->setPaymentMethod('paypal');
    24.         $agreement->setPayer($payer);
    25.
    26.         // Add Shipping Address
    27.         //        $shippingAddress = new ShippingAddress();
    28.         //        $shippingAddress->setLine1('111 First Street')
    29.         //            ->setCity('Saratoga')
    30.         //            ->setState('CA')
    31.         //            ->setPostalCode('95070')
    32.         //            ->setCountryCode('US');
    33.         //        $agreement->setShippingAddress($shippingAddress);
    34.
    35.
    36.         // ### Create Agreement
    37.         try {
    38.             // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
    39.             $temp = $this->getApiContext();
    40.             $agreement = $agreement->create( $temp );
    41.
    42.         } catch (Exception $ex) {
    43.             throw $ex;
    44.         }
    45.
    46.         return $agreement;
    47.     }
    

第40行建立协议时出了点问题。

这是$ temp:

    $temp = {PayPal\Rest\ApiContext} [2]
        requestId = null
        credential = {PayPal\Auth\OAuthTokenCredential} [11]
            CACHE_PATH = "/../../../var/auth.cache"
            AUTH_HANDLER = "PayPal\Handler\OauthHandler"
            expiryBufferTime = 120
            credential = null
            clientId = "xxxx"
            clientSecret = "xxxx"
            accessToken = null
            tokenExpiresIn = null
            tokenCreateTime = null
            cipher = {PayPal\Security\Cipher} [1]
                secretKey = "xxxx"
            *PayPal\Common\PayPalModel*_propMap = {array} [0]
  1. Agreement.php创建:

     /**
     * Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON.
     *
     * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
     * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
     * @return Agreement
     */
    public function create($apiContext = null, $restCall = null)
    {
        $payLoad = $this->toJSON();
        $json = self::executeCall(
            "/v1/payments/billing-agreements/",
            "POST",
            $payLoad,
            null,
            $apiContext,
            $restCall
        );
        $this->fromJson($json);
        return $this;
    }
    
  2. PayPalRestCall执行:

    1.      /**
    2.      * @param array  $handlers Array of handlers
    3.      * @param string $path     Resource path relative to base service endpoint
    4.      * @param string $method   HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
    5.      * @param string $data     Request payload
    6.      * @param array  $headers  HTTP headers
    7.      * @return mixed
    8.      * @throws \PayPal\Exception\PayPalConnectionException
    9.      */
    10.     public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
    11.     {
    12.         $config = $this->apiContext->getConfig();
    13.         $httpConfig = new PayPalHttpConfig(null, $method, $config);
    14.         $headers = $headers ? $headers : array();
    15.         $httpConfig->setHeaders($headers +
    16.             array(
    17.                 'Content-Type' => 'application/json'
    18.             )
    19.         );
    20.
    21.         // if proxy set via config, add it
    22.         if (!empty($config['http.Proxy'])) {
    23.             $httpConfig->setHttpProxy($config['http.Proxy']);
    24.         }
    25.
    26.         /** @var \Paypal\Handler\IPayPalHandler $handler */
    27.         foreach ($handlers as $handler) {
    28.             if (!is_object($handler)) {
    29.                 $fullHandler = "\\" . (string)$handler;
    30.                 $handler = new $fullHandler($this->apiContext);
    31.             }
    32.             $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
    33.         }
    34.         $connection = new PayPalHttpConnection($httpConfig, $config);
    35.         $response = $connection->execute($data);
    36.
    37.         return $response;
    38.     }
    

我将其发送到PayPal沙箱服务器(POST https://api.sandbox.paypal.com/v1/payments/billing-agreements/):

    {
      "name": "Base Agreement",
      "description": "Basic Agreement",
      "start_date": "2018-08-14T17:01:25+03:00",
      "plan": {
        "id": "P-03R665271A787135CPIXIURI"
      },
      "payer": {
        "payment_method": "paypal"
      }
    }

标题:

    Content-Type = "application/json"
    Expect = null
    User-Agent = "PayPalSDK/PayPal-PHP-SDK 1.13.0 (platform-ver=7.1.12; bit=32; os=Windows_NT_10.0; machine=i586; crypto-lib-ver=1.0.2m; curl=7.56.0)"
    Authorization = "Bearer LONG-LONG-TOCKEN"

我很生气:

    {
      "name": "BUSINESS_VALIDATION_ERROR",
      "details": [
        {
          "field": "validation_error",
          "issue": "Incorrect Plan Id."
        }
      ],
      "message": "Validation Error.",
      "information_link": "https://developer.paypal.com/docs/api/payments.billing-agreements#errors",
      "debug_id": "3e4eadccf0d9"
    }

Symfoni配置:

    paypal:
        clientId: "xxxx"
        clientSecret: "xxxxx"
        mode: "sandbox"
        LogEnabled: true
        LogFileName: "%kernel.root_dir%/../var/logs/payPal.log"
        LogLevel: "DEBUG" # PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
        cache_enabled: false

请帮助。

0 个答案:

没有答案