/**
  * Sets the name of the sender, party that will be sending the money
  * @param String $senderName
  */
 public function setSenderName($senderName)
 {
     if ($this->sender == null) {
         $this->sender = new PagSeguroSender();
     }
     $this->sender->setName($senderName);
 }
 public function setSender($name, $email = null, $areaCode = null, $number = null, $documentType = null, $documentValue = null)
 {
     $param = $name;
     if (is_array($param)) {
         $this->sender = new PagSeguroSender($param);
     } elseif ($param instanceof PagSeguroSender) {
         $this->sender = $param;
     } else {
         $sender = new PagSeguroSender();
         $sender->setName($param);
         $sender->setEmail($email);
         $sender->setPhone(new PagSeguroPhone($areaCode, $number));
         $sender->addDocument($documentType, $documentValue);
         $this->sender = $sender;
     }
 }
 public static function readPreApproval($str_xml)
 {
     $parser = new PagSeguroXmlParser($str_xml);
     $data = $parser->getResult('preApproval');
     $preApproval = new PagSeguroPreApproval();
     // <transaction> <lastEventDate>
     if (isset($data["lastEventDate"])) {
         $preApproval->setLastEventDate($data["lastEventDate"]);
     }
     // <transaction> <date>
     if (isset($data["date"])) {
         $preApproval->setDate($data["date"]);
     }
     // <transaction> <code>
     if (isset($data["code"])) {
         $preApproval->setCode($data["code"]);
     }
     // <transaction> <reference>
     if (isset($data["reference"])) {
         $preApproval->setReference($data["reference"]);
     }
     // <transaction> <status>
     if (isset($data["status"])) {
         $preApproval->setStatus(new PagSeguroPreApprovalStatus($data["status"]));
     }
     if (isset($data["sender"])) {
         // <transaction> <sender>
         $sender = new PagSeguroSender();
         // <transaction> <sender> <name>
         if (isset($data["sender"]["name"])) {
             $sender->setName($data["sender"]["name"]);
         }
         // <transaction> <sender> <email>
         if (isset($data["sender"]["email"])) {
             $sender->setEmail($data["sender"]["email"]);
         }
         if (isset($data["sender"]["phone"])) {
             // <transaction> <sender> <phone>
             $phone = new PagSeguroPhone();
             // <transaction> <sender> <phone> <areaCode>
             if (isset($data["sender"]["phone"]["areaCode"])) {
                 $phone->setAreaCode($data["sender"]["phone"]["areaCode"]);
             }
             // <transaction> <sender> <phone> <number>
             if (isset($data["sender"]["phone"]["number"])) {
                 $phone->setNumber($data["sender"]["phone"]["number"]);
             }
             $sender->setPhone($phone);
         }
         // <transaction><sender><documents>
         if (isset($data["sender"]['documents']) && is_array($data["sender"]['documents'])) {
             $documents = $data["sender"]['documents'];
             if (count($documents) > 0) {
                 foreach ($documents as $document) {
                     $sender->addDocument($document['type'], $document['value']);
                 }
             }
         }
         $preApproval->setSender($sender);
     }
     return $preApproval;
 }
Exemple #4
0
 /**
  * Generate PagSeguro Sender Data
  * @return \PagSeguroSender
  */
 private function _generatepagSeguroSenderDataObject()
 {
     $sender = new PagSeguroSender();
     $sender->setEmail(str_replace(' ', '', $this->_order_info['email']));
     $sender->setName($this->_order_info['firstname'] . ' ' . $this->_order_info['lastname']);
     return $sender;
 }
 /**
  * @param $str_xml
  * @return PagSeguroTransaction
  */
 public static function readTransaction($str_xml)
 {
     // Parser
     $parser = new PagSeguroXmlParser($str_xml);
     // <transaction>
     $data = $parser->getResult('transaction');
     $transaction = new PagSeguroTransaction();
     // <transaction> <lastEventDate>
     if (isset($data["lastEventDate"])) {
         $transaction->setLastEventDate($data["lastEventDate"]);
     }
     // <transaction> <date>
     if (isset($data["date"])) {
         $transaction->setDate($data["date"]);
     }
     // <transaction> <code>
     if (isset($data["code"])) {
         $transaction->setCode($data["code"]);
     }
     // <transaction> <reference>
     if (isset($data["reference"])) {
         $transaction->setReference($data["reference"]);
     }
     // <transaction> <type>
     if (isset($data["type"])) {
         $transaction->setType(new PagSeguroTransactionType($data["type"]));
     }
     // <transaction> <status>
     if (isset($data["status"])) {
         $transaction->setStatus(new PagSeguroTransactionStatus($data["status"]));
     }
     if (isset($data["paymentMethod"]) && is_array($data["paymentMethod"])) {
         // <transaction> <paymentMethod>
         $paymentMethod = new PagSeguroPaymentMethod();
         // <transaction> <paymentMethod> <type>
         if (isset($data["paymentMethod"]['type'])) {
             $paymentMethod->setType(new PagSeguroPaymentMethodType($data["paymentMethod"]['type']));
         }
         // <transaction> <paymentMethod> <code>
         if (isset($data["paymentMethod"]['code'])) {
             $paymentMethod->setCode(new PagSeguroPaymentMethodCode($data["paymentMethod"]['code']));
         }
         $transaction->setPaymentMethod($paymentMethod);
     }
     // <transaction> <grossAmount>
     if (isset($data["grossAmount"])) {
         $transaction->setGrossAmount($data["grossAmount"]);
     }
     // <transaction> <discountAmount>
     if (isset($data["discountAmount"])) {
         $transaction->setDiscountAmount($data["discountAmount"]);
     }
     // <transaction> <feeAmount>
     if (isset($data["feeAmount"])) {
         $transaction->setFeeAmount($data["feeAmount"]);
     }
     // <transaction> <netAmount>
     if (isset($data["netAmount"])) {
         $transaction->setNetAmount($data["netAmount"]);
     }
     // <transaction> <extraAmount>
     if (isset($data["extraAmount"])) {
         $transaction->setExtraAmount($data["extraAmount"]);
     }
     // <transaction> <installmentCount>
     if (isset($data["installmentCount"])) {
         $transaction->setInstallmentCount($data["installmentCount"]);
     }
     if (isset($data["items"]['item']) && is_array($data["items"]['item'])) {
         $items = array();
         $i = 0;
         if (isset($data["items"]['item'][0])) {
             foreach ($data["items"]['item'] as $key => $value) {
                 $item = self::parseTransactionItem($value);
                 $items[$i] = $item;
                 $i++;
             }
         } else {
             $items[0] = self::parseTransactionItem($data["items"]['item']);
         }
         // <transaction> <items>
         $transaction->setItems($items);
     }
     if (isset($data["sender"])) {
         // <transaction> <sender>
         $sender = new PagSeguroSender();
         // <transaction> <sender> <name>
         if (isset($data["sender"]["name"])) {
             $sender->setName($data["sender"]["name"]);
         }
         // <transaction> <sender> <email>
         if (isset($data["sender"]["email"])) {
             $sender->setEmail($data["sender"]["email"]);
         }
         if (isset($data["sender"]["phone"])) {
             // <transaction> <sender> <phone>
             $phone = new PagSeguroPhone();
             // <transaction> <sender> <phone> <areaCode>
             if (isset($data["sender"]["phone"]["areaCode"])) {
                 $phone->setAreaCode($data["sender"]["phone"]["areaCode"]);
             }
             // <transaction> <sender> <phone> <number>
             if (isset($data["sender"]["phone"]["number"])) {
                 $phone->setNumber($data["sender"]["phone"]["number"]);
             }
             $sender->setPhone($phone);
         }
         // <transaction><sender><documents>
         if (isset($data['sender']['documents']) && is_array($data['sender']['documents'])) {
             $documents = $data['sender']['documents'];
             if (count($documents) > 0) {
                 foreach ($documents as $document) {
                     $sender->addDocument($document['type'], $document['value']);
                 }
             }
         }
         $transaction->setSender($sender);
     }
     if (isset($data["shipping"]) && is_array($data["shipping"])) {
         // <transaction> <shipping>
         $shipping = new PagSeguroShipping();
         // <transaction> <shipping> <type>
         if (isset($data["shipping"]["type"])) {
             $shipping->setType(new PagSeguroShippingType($data["shipping"]["type"]));
         }
         // <transaction> <shipping> <cost>
         if (isset($data["shipping"]["cost"])) {
             $shipping->setCost($data["shipping"]["cost"]);
         }
         if (isset($data["shipping"]["address"]) && is_array($data["shipping"]["address"])) {
             // <transaction> <shipping> <address>
             $address = new PagSeguroAddress();
             // <transaction> <shipping> <address> <street>
             if (isset($data["shipping"]["address"]["street"])) {
                 $address->setStreet($data["shipping"]["address"]["street"]);
             }
             // <transaction> <shipping> <address> <number>
             if (isset($data["shipping"]["address"]["number"])) {
                 $address->setNumber($data["shipping"]["address"]["number"]);
             }
             // <transaction> <shipping> <address> <complement>
             if (isset($data["shipping"]["address"]["complement"])) {
                 $address->setComplement($data["shipping"]["address"]["complement"]);
             }
             // <transaction> <shipping> <address> <city>
             if (isset($data["shipping"]["address"]["city"])) {
                 $address->setCity($data["shipping"]["address"]["city"]);
             }
             // <transaction> <shipping> <address> <state>
             if (isset($data["shipping"]["address"]["state"])) {
                 $address->setState($data["shipping"]["address"]["state"]);
             }
             // <transaction> <shipping> <address> <district>
             if (isset($data["shipping"]["address"]["district"])) {
                 $address->setDistrict($data["shipping"]["address"]["district"]);
             }
             // <transaction> <shipping> <address> <postalCode>
             if (isset($data["shipping"]["address"]["postalCode"])) {
                 $address->setPostalCode($data["shipping"]["address"]["postalCode"]);
             }
             // <transaction> <shipping> <address> <country>
             if (isset($data["shipping"]["address"]["country"])) {
                 $address->setCountry($data["shipping"]["address"]["country"]);
             }
             $shipping->setAddress($address);
         }
         // <transaction> <shipping>
         $transaction->setShipping($shipping);
     }
     return $transaction;
 }
 /**
  * Customer information that are sent
  * @return PagSeguroSender
  */
 private function getSenderInformation()
 {
     $PagSeguroSender = new PagSeguroSender();
     $PagSeguroSender->setEmail($this->order['customer_email']);
     $PagSeguroSender->setName($this->order['customer_firstname'] . ' ' . $this->order['customer_lastname']);
     return $PagSeguroSender;
 }
 /**
  *  Generates sender data to PagSeguro transaction
  * 
  *  @return PagSeguroSender
  */
 private function _generateSenderData()
 {
     $sender = new PagSeguroSender();
     if (isset($this->context->customer) && !is_null($this->context->customer)) {
         $sender->setEmail($this->context->customer->email);
         $name = $this->_generateName($this->context->customer->firstname) . ' ' . $this->_generateName($this->context->customer->lastname);
         $sender->setName(Tools::truncate($name, 50));
     }
     return $sender;
 }
 /**
  *  Generates sender data to PagSeguro transaction
  *  @return PagSeguroSender
  */
 private function _generateSenderData($order)
 {
     $pagSeguroSender = new PagSeguroSender();
     $app = JFactory::getApplication();
     $cart = hikashop_get('class.cart');
     $user = hikashop_loadUser(true);
     $address = $app->getUserState(HIKASHOP_COMPONENT . '.shipping_address');
     if (!empty($address)) {
         $cart->loadAddress($order->cart, $address, 'object', 'shipping');
         $pagSeguroSender->setEmail($user->user_email);
         $pagSeguroSender->setName(@$order->cart->shipping_address->address_firstname . ' ' . @$order->cart->shipping_address->address_lastname);
     }
     return $pagSeguroSender;
 }
 /**
  *  Generates sender data to PagSeguro transaction
  *  @return PagSeguroSender
  */
 private function _generateSenderData($sender)
 {
     $pagSeguroSender = new PagSeguroSender();
     if (isset($sender) && !is_null($sender)) {
         $pagSeguroSender->setEmail($sender->email);
         $pagSeguroSender->setName($sender->first_name . ' ' . $sender->last_name);
     }
     return $pagSeguroSender;
 }