Can't create demo payment on sandbox PayPal

docentovich
New Community Member

I'am using "paypal/rest-api-sdk-php": "^1.11" on "symfony/symfony": "3.2.*" (RESTapi, front on VueJs).

The moment I create the agreement (PayPal sandbox), PayPal returns to me next:

 

{
    "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.     }

something goes wrong in line 40 when creating agreement.

This is $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]

2. Agreement.php create:

/**
 * 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;
}

3. PayPalRestCall execute:

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.     }

Thet whot i'am send to PayPal sandbox server (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"
  }
}

Headers:

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"

What i receive:

{
  "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"
}

Symfony Config:

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

Please, help.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.