Sukh
Sukh

Reputation: 361

PayPal PHP Rest SDK Buyers Address PPOpenIdAddress

I have been using the PHP Rest SDK, I have been able to login / logout and gather all the user information possible but if I change the scope to include 'address', or just leave the array empty so it defaults to the sdks defaults, I get the following error:

Fatal error: Class 'PPOpenIdAddress' not found in /Users//Sites//framework.**.dev/private/modules/paypal/vendor/paypal/sdk-core-php/lib/PayPal/Common/PPModel.php on line 51

If I remove the address field from the scope and then everything is running smooth.

Scope before adding address:

public function createLogin(){
    try {
        $_array = array('openid', 'email', 'profile', 'phone', 'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout');
        return PPOpenIdSession::getAuthorizationUrl(PAYPALURL, $_array, $this->_clientid,  $this->getApiContext());
    } catch (PayPal\Exception\PPConnectionException $_exception) {
        $this->_errormsg = $_exception->getMessage();
        $this->_errordata = $_exception->getData();

        return false;
    }
}

Scope after adding address:

public function createLogin(){
    try {
        $_array = array('openid', 'email', 'profile', 'address', 'phone', 'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout');
        return PPOpenIdSession::getAuthorizationUrl(PAYPALURL, $_array, $this->_clientid,  $this->getApiContext());
    } catch (PayPal\Exception\PPConnectionException $_exception) {
        $this->_errormsg = $_exception->getMessage();
        $this->_errordata = $_exception->getData();

        return false;
    }
}

not sure whats going wrong

Upvotes: 0

Views: 249

Answers (2)

user3768623
user3768623

Reputation: 1

Replace function on PayPal\Common\PPModel.php on line 45, with this one below.

public function fromArray($arr) {

    foreach($arr as $k => $v) {
        if(is_array($v)) {
            $clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k);


            if($clazz == 'PPOpenIdAddress'){
                $clazz = 'PayPal\Auth\Openid\PPOpenIdAddress';
            }
            if(PPArrayUtil::isAssocArray($v)) {
                $o = new $clazz();
                $o->fromArray($v);
                $this->__set($k, $o);
            } else {
                $arr =  array();        
                foreach($v as $nk => $nv) {
                    if(is_array($nv)) {
                        $o = new $clazz();
                        $o->fromArray($nv);
                        $arr[$nk] = $o;
                    } else {
                        $arr[$nk] = $nv;
                    }
                }
                $this->__set($k, $arr);
            } 
        }else {
            $this->$k = $v;
        }
    }
}

Upvotes: 0

Andrej Mohar
Andrej Mohar

Reputation: 985

Found a solution. Seems that the implemented reflection here uses the PHPDOC to retrieve the class names. It was enough for me to locate the getter method getAddress() in PPOpenIdUserinfo.php. I changed the @return PPOpenIdAddress to @return PayPal\Auth\Openid\PPOpenIdAddress, (I basically added the namespace alongside the class). I hope some of the experts in PayPal api can confirm this.

Upvotes: 2

Related Questions