/**
  * Sets the Sender phone number, phone of the party that will be sending the money
  *
  * @param areaCode
  * @param number
  */
 public function setSenderPhone($areaCode, $number = null)
 {
     $param = $areaCode;
     if ($this->sender == null) {
         $this->sender = new PagSeguroSender();
     }
     if ($param instanceof PagSeguroPhone) {
         $this->sender->setPhone($param);
     } else {
         $this->sender->setPhone(new PagSeguroPhone($param, $number));
     }
 }
 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;
 }
 /**
  * @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;
 }