Example #1
0
 /**
  * Call create new customer token API
  *
  * @param Varien_Object $billing
  * @param Varien_Object $infoInstance
  * @return Eway_Rapid31_Model_Request_Token
  */
 public function createNewToken(Varien_Object $billing, Varien_Object $infoInstance)
 {
     // Empty Varien_Object's data
     $this->unsetData();
     $customerParam = Mage::getModel('ewayrapid/field_customer');
     $customerParam->setTitle($billing->getPrefix())->setFirstName($billing->getFirstname())->setLastName($billing->getLastname())->setCompanyName($billing->getCompany())->setJobDescription($billing->getJobDescription())->setStreet1($billing->getStreet1())->setStreet2($billing->getStreet2())->setCity($billing->getCity())->setState($billing->getRegion())->setPostalCode($billing->getPostcode())->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))->setEmail($billing->getEmail())->setPhone($billing->getTelephone())->setMobile($billing->getMobile())->setComments('')->setFax($billing->getFax())->setUrl('');
     $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
     $cardDetails->setName($infoInstance->getCcOwner())->setNumber($infoInstance->getCcNumber())->setExpiryMonth($infoInstance->getCcExpMonth())->setExpiryYear($infoInstance->getCcExpYear())->setCVN($infoInstance->getCcCid())->setStartMonth($infoInstance->getStartMonth())->setStartYear($infoInstance->getStartYear())->setIssueNumber($infoInstance->getIssueNumber());
     $customerParam->setCardDetails($cardDetails);
     $this->setCustomer($customerParam);
     $response = $this->_doRapidAPI('Customer');
     if ($response->isSuccess()) {
         $customerReturn = $response->getCustomer();
         $cardDetails = $customerReturn['CardDetails'];
         unset($customerReturn['CardDetails']);
         $customerReturn['RegionId'] = !$billing->getRegion() && $billing->getRegionId() ? $billing->getRegionId() : '';
         $tokenInfo = array('Token' => $response->getTokenCustomerID(), 'Card' => substr_replace($cardDetails['Number'], '******', 6, 6), 'Owner' => $infoInstance->getCcOwner(), 'ExpMonth' => $infoInstance->getCcExpMonth(), 'ExpYear' => $infoInstance->getCcExpYear(), 'Type' => $infoInstance->getCcType(), 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn));
         Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
         return $this;
     } else {
         Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)', $response->getMessage()));
     }
 }