paypal / PayPal-PHP-SDK

PHP SDK for PayPal RESTful APIs
https://developer.paypal.com/docs/api/
Other
25 stars 94 forks source link

Class "String" not found in PPModel in REST API with work with Invoices #141

Closed lobster-tm closed 9 years ago

lobster-tm commented 9 years ago

Good day, the problem in the next 21 October at 02:00 when creating accounts began to appear the error:

PHP Fatal error: Class 'string' not found in /vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PPModel.php on line 159

Logs were correct at the same time Experiments have shown that the problem was in the class Api / Address

 / **
  * Phone number in E.123 format.
  *
  *
  *param String $ phone
  *
  *return $ This
  * /
 public function setPhone ($ phone)
 {
     $ this-> phone = $ phone;
     return $ this;
 }

 / **
  * Phone number in E.123 format.
  *
  *return String
  * /
 public function getPhone ()
 {
     return $ this-> phone;
 }

in PPModel research was carried out of this class, in particular parameter phone, which was in rezltate type "string" and the SDK was trying to create an instance non-existent class. $ clazz = PPReflectionUtil :: getPropertyClass (get_class ($ this), $ k); if (PPArrayUtil :: isAssocArray ($ v)) { / *var Self $ o \ / $ o = new $ clazz (); $ o-> fromArray ($ v); $ this-> assignValue ($ k, $ o); }

Corrected very simply by replacing annotation in Api / Address the following: / * * Phone number of the merchant. param PayPal \ Api \ Phone $ phone \ / public function setPhone ($ phone) { $ this-> phone = $ phone; return $ this; }

 / **
  * Phone number of the merchant.
  *
  *return PayPal \ Api \ Phone
  * /
 public function getPhone ()
 {
     return $ this-> phone;
 }

I do not know how much is true my decision, but in my case it worked. Such strange behavior apparently started after changing the format of the data sent in:

"address": {"line1": "Unitmobile LLC","city":"Russia","state":"Voronezh","postal_code":"394018","country_code":"RU","phone":{"country_code":"7","national_number":"9056581407"}}

jaypatel512 commented 9 years ago

@stalesha You are correct. The phone returned is an object, and it should be annotated as PayPal\Api\Phone. I will soon make the changes, and make the pull request.

Thank you for your detailed observation. It really helped.

jaypatel512 commented 9 years ago

https://github.com/paypal/rest-api-sdk-php/commit/1de60858574725d852ff3f76186eeedfbb265217 Fixed in this commit. Should be released soon.