/**
  * Test case for oepaypalstandarddispatcher::getExpressCheckoutDetails()
  *
  * @return null
  */
 public function testGetExpressCheckoutDetails()
 {
     // preparing session, inputs etc.
     $this->getSession()->setVariable("oepaypal-token", "111");
     $aDetails["PAYERID"] = "111";
     $oDetails = new oePayPalResponseGetExpressCheckoutDetails();
     $oDetails->setData($aDetails);
     // preparing config
     $oPayPalConfig = $this->getMock("oePayPalConfig", array("finalizeOrderOnPayPalSide"));
     $oPayPalConfig->expects($this->once())->method("finalizeOrderOnPayPalSide")->will($this->returnValue(true));
     // preparing service
     $oPayPalService = $this->getMock("oePayPalService", array("getExpressCheckoutDetails"));
     $oPayPalService->expects($this->once())->method("getExpressCheckoutDetails")->will($this->returnValue($oDetails));
     // preparing
     $oDispatcher = $this->getMock("oepaypalstandarddispatcher", array("getPayPalCheckoutService", "getPayPalConfig"));
     $oDispatcher->expects($this->once())->method("getPayPalCheckoutService")->will($this->returnValue($oPayPalService));
     $oDispatcher->expects($this->once())->method("getPayPalConfig")->will($this->returnValue($oPayPalConfig));
     // testing
     $this->assertEquals("order?fnc=execute", $oDispatcher->getExpressCheckoutDetails());
     $this->assertEquals("111", $this->getSession()->getVariable("oepaypal-payerId"));
 }
Example #2
0
 /**
  * Prepare address data array from PayPal response data.
  *
  * @param oePayPalResponseGetExpressCheckoutDetails $oDetails - PayPal data
  *
  * @return array
  */
 protected function _prepareDataPayPalAddress($oDetails)
 {
     $aAddressData = array();
     $oFullName = oxNew('oePayPalFullName', $oDetails->getShipToName());
     $aAddressData['oxfname'] = $oFullName->getFirstName();
     $aAddressData['oxlname'] = $oFullName->getLastName();
     $aStreet = $this->splitShipToStreetPayPalAddress($oDetails->getShipToStreet());
     $aAddressData['oxstreet'] = $aStreet['street'];
     $aAddressData['oxstreetnr'] = $aStreet['streetnr'];
     $aAddressData['oxcity'] = $oDetails->getShipToCity();
     $oCountry = oxNew('oxCountry');
     $sCountryId = $oCountry->getIdByCode($oDetails->getShipToCountryCode());
     $aAddressData['oxcountryid'] = $sCountryId;
     if ($oDetails->getShipToState()) {
         $oState = oxNew('oxState');
         $sStateId = $oState->getIdByCode($oDetails->getShipToState(), $sCountryId);
     }
     $aAddressData['oxstateid'] = $sStateId;
     $aAddressData['oxzip'] = $oDetails->getShipToZip();
     $aAddressData['oxfon'] = $oDetails->getShipToPhoneNumber();
     $aAddressData['oxaddinfo'] = $oDetails->getShipToStreet2();
     return $aAddressData;
 }
 /**
  * Test getting company name
  */
 public function testGetBusiness()
 {
     $oResponse = new oePayPalResponseGetExpressCheckoutDetails();
     $oResponse->setData($this->_getResponseData());
     $this->assertEquals('company', $oResponse->getBusiness());
 }
 /**
  * Test case for oePayPalAddress::createPayPalAddress()
  * Creating new address
  *
  * @dataProvider createPayPalAddress_splittingUserName_dataProvider
  *
  * @return null
  */
 public function testCreatePayPalAddress_splittingUserName($sName, $aResult)
 {
     $aPayPalData = $this->_getPayPalData();
     $oPayPalData = new oePayPalResponseGetExpressCheckoutDetails();
     $aPayPalData['PAYMENTREQUEST_0_SHIPTONAME'] = $sName;
     $oPayPalData->setData($aPayPalData);
     $oPayPalOxAddress = new oePayPalOxAddress();
     $oPayPalOxAddress->createPayPalAddress($oPayPalData, 'testUserId');
     $sAddressId = $oPayPalOxAddress->getId();
     $oAddress = new oxAddress();
     $oAddress->load($sAddressId);
     $this->assertEquals($aResult[0], $oAddress->oxaddress__oxfname->value);
     $this->assertEquals($aResult[1], $oAddress->oxaddress__oxlname->value);
 }
Example #5
0
 /**
  * Prepare address data array from PayPal response data.
  *
  * @param oePayPalResponseGetExpressCheckoutDetails $oPayPalData PayPal data.
  *
  * @return array
  */
 protected function _prepareDataPayPalUser($oPayPalData)
 {
     $aUserData = array();
     $oFullName = oxNew('oePayPalFullName', $oPayPalData->getShipToName());
     $aUserData['oxfname'] = $oFullName->getFirstName();
     $aUserData['oxlname'] = $oFullName->getLastName();
     $aStreet = $this->_splitShipToStreetPayPalUser($oPayPalData->getShipToStreet());
     $aUserData['oxstreet'] = $aStreet['street'];
     $aUserData['oxstreetnr'] = $aStreet['streetnr'];
     $aUserData['oxcity'] = $oPayPalData->getShipToCity();
     $oCountry = oxNew('oxCountry');
     $sCountryId = $oCountry->getIdByCode($oPayPalData->getShipToCountryCode());
     $aUserData['oxcountryid'] = $sCountryId;
     $sStateId = '';
     if ($oPayPalData->getShipToState()) {
         $oState = oxNew('oxState');
         $sStateId = $oState->getIdByCode($oPayPalData->getShipToState(), $sCountryId);
     }
     $aUserData['oxstateid'] = $sStateId;
     $aUserData['oxzip'] = $oPayPalData->getShipToZip();
     $aUserData['oxfon'] = $oPayPalData->getShipToPhoneNumber();
     $aUserData['oxaddinfo'] = $oPayPalData->getShipToStreet2();
     $aUserData['oxsal'] = $oPayPalData->getSalutation();
     $aUserData['oxcompany'] = $oPayPalData->getBusiness();
     return $aUserData;
 }
 /**
  * Test case for oepaypalexpresscheckoutdispatcher::_initializeUserData() - Logged in shop user, paypal returns user email
  * that  exists in shop and has same address. No new user address should be created.
  *
  * @return null
  */
 public function testInitializeUserData_loggedUser_sameAddress()
 {
     $aUserDetails["EMAIL"] = "testUserEmail";
     $oDetails = new oePayPalResponseGetExpressCheckoutDetails();
     $oDetails->setData($aUserDetails);
     $this->getSession()->setVariable("deladrid", "testDelId");
     $this->assertEquals("testDelId", $this->getSession()->getVariable("deladrid"));
     $oUser = $this->getMock("oxUser", array("isRealPayPalUser", "isSamePayPalUser", "isSameAddressPayPalUser", 'isSameAddressUserPayPalUser'));
     $oUser->expects($this->once())->method("isRealPayPalUser")->with($this->equalTo("testLoggedUserEmail"))->will($this->returnValue("testLoggedUserId"));
     $oUser->expects($this->once())->method("isSameAddressPayPalUser")->with($this->equalTo($oDetails))->will($this->returnValue(true));
     $oUser->expects($this->once())->method("isSameAddressUserPayPalUser")->with($this->equalTo($oDetails))->will($this->returnValue(true));
     $oUser->expects($this->never())->method("isSamePayPalUser");
     $oUser->oxuser__oxusername = new oxField("testLoggedUserEmail");
     oxTestModules::addModuleObject('oxUser', $oUser);
     // preparing
     $oDispatcher = $this->getMock("oepaypalexpresscheckoutdispatcher", array("_createUserAddress", "getUser"));
     $oDispatcher->expects($this->never())->method("_createUserAddress");
     $oDispatcher->expects($this->once())->method("getUser")->will($this->returnValue($oUser));
     // testing
     $oDispatcher->UNITinitializeUserData($oDetails);
     // delivery address id storred in session should be deleted
     $this->assertNull($this->getSession()->getVariable("deladrid"));
 }
 /**
  * Test case for oePayPalOxUser::isSamePayPalUser()
  *
  * @return null
  */
 public function testIsSameAddressPayPalUser_decoding_html()
 {
     $aPayPalData = $this->_getPayPalData();
     $oDetails = new oePayPalResponseGetExpressCheckoutDetails();
     $oDetails->setData($aPayPalData);
     oxTestModules::addModuleObject('oxAddress', new oePayPalOxAddress());
     $oUser = new oePayPalOxUser();
     $oUser->createPayPalUser($oDetails);
     // by default single quote ' will be convrted to '
     $oUser->oxuser__oxstreet = new oxField("test'StreetName");
     $oUser->oxuser__oxstreetnr = new oxField("5");
     $oUser->oxuser__oxcity = new oxField("test'City");
     $aPayPalData['PAYMENTREQUEST_0_SHIPTOSTREET'] = "test'StreetName 5";
     $aPayPalData["PAYMENTREQUEST_0_SHIPTOCITY"] = "test'City";
     $oDetails->setData($aPayPalData);
     $this->assertTrue($oUser->isSamePayPalUser($oDetails));
 }
 /**
  * Creates new or returns session user
  *
  * @param oePayPalResponseGetExpressCheckoutDetails $oDetails
  *
  * @throws oxException
  * @return oxUser
  */
 protected function _initializeUserData($oDetails)
 {
     $sUserEmail = $oDetails->getEmail();
     $oLoggedUser = $this->getUser();
     if ($oLoggedUser) {
         $sUserEmail = $oLoggedUser->oxuser__oxusername->value;
     }
     $oUser = oxNew("oxUser");
     if ($sUserId = $oUser->isRealPayPalUser($sUserEmail)) {
         // if user exist
         $oUser->load($sUserId);
         if (!$oLoggedUser) {
             if (!$oUser->isSamePayPalUser($oDetails)) {
                 /**
                  * @var $oEx oxException
                  */
                 $oEx = oxNew('oxException');
                 $oEx->setMessage('OEPAYPAL_ERROR_USER_ADDRESS');
                 throw $oEx;
             }
         } elseif (!$oUser->isSameAddressUserPayPalUser($oDetails) || !$oUser->isSameAddressPayPalUser($oDetails)) {
             // user has selected different address in PayPal (not equal with usr shop address)
             // so adding PayPal address as new user address to shop user account
             $this->_createUserAddress($oDetails, $sUserId);
         } else {
             // removing custom shipping address ID from session as user uses billing
             // address for shipping
             $this->getSession()->deleteVariable('deladrid');
         }
     } else {
         $oUser->createPayPalUser($oDetails);
     }
     $this->getSession()->setVariable('usr', $oUser->getId());
     return $oUser;
 }