public static function getData($authorization) { $data = null; // Reference if ($authorization->getReference() != null) { $data['reference'] = $authorization->getReference(); } // RedirectURL if ($authorization->getRedirectURL() != null) { $data['redirectURL'] = $authorization->getRedirectURL(); } // NotificationURL if ($authorization->getNotificationURL() != null) { $data['notificationURL'] = $authorization->getNotificationURL(); } // Permissions if ($authorization->getPermissions()->getPermissions() != null) { $data['permissions'] = implode(',', $authorization->getPermissions()->getPermissions()); } // parameter if (count($authorization->getParameter()->getItems()) > 0) { foreach ($authorization->getParameter()->getItems() as $item) { if ($item instanceof PagSeguroParameterItem) { if (!PagSeguroHelper::isEmpty($item->getKey()) && !PagSeguroHelper::isEmpty($item->getValue())) { if (!PagSeguroHelper::isEmpty($item->getGroup())) { $data[$item->getKey() . '' . $item->getGroup()] = $item->getValue(); } else { $data[$item->getKey()] = $item->getValue(); } } } } } return $data; }
/** * Get from webservice installments for direct payment. * @param PagSeguroCredentials $credentials * @param $amount * @param $cardBrand * @param $maxInstallmentNoInterest * @return bool|PagSeguroInstallment * @throws Exception * @throws PagSeguroServiceException */ public static function getInstallments(PagSeguroCredentials $credentials, $amount, $cardBrand = null, $maxInstallmentNoInterest = null) { $amount = PagSeguroHelper::decimalFormat($amount); LogPagSeguro::info("PagSeguroInstallmentService.getInstallments(" . $amount . ") - begin"); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildInstallmentURL(self::$connectionData, $amount, $cardBrand, $maxInstallmentNoInterest), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse()); LogPagSeguro::info("PagSeguroInstallmentService.getInstallments() - end "); break; case 'BAD_REQUEST': $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage()); throw $e; break; } return isset($installments) ? $installments : false; } catch (PagSeguroServiceException $e) { throw $e; } catch (Exception $e) { LogPagSeguro::error("Exception: " . $e->getMessage()); throw $e; } }
/** * @param null $group * @param null $name */ public function __construct($group = null, $name = null) { if (isset($name) && !PagSeguroHelper::isEmpty($name)) { $this->setName($name); } if (isset($group) && !PagSeguroHelper::isEmpty($group)) { $this->setGroup($group); } }
public function __construct(array $data = null) { if ($data) { if (isset($data['type']) && isset($data['value'])) { $this->setType($data['type']); $this->setValue(PagSeguroHelper::getOnlyNumbers($data['value'])); } } }
public function addItem(PagSeguroParameterItem $parameterItem) { if (!PagSeguroHelper::isEmpty($parameterItem->getKey())) { if (!PagSeguroHelper::isEmpty($parameterItem->getValue())) { $this->items[] = $parameterItem; } else { die('requered parameterValue.'); } } else { die('requered parameterKey.'); } }
public function __construct($key, $value, $group = null) { if (isset($key) && !PagSeguroHelper::isEmpty($key)) { $this->setKey($key); } if (isset($value) && !PagSeguroHelper::isEmpty($value)) { $this->setValue($value); } if (isset($group) && !PagSeguroHelper::isEmpty($group)) { $this->setGroup($group); } }
/** * Normalize metadata item value * @param string $parameterValue * @return string */ private function _normalizeParameter($parameterValue) { $parameterValue = PagSeguroHelper::formatString($parameterValue, 100, ''); switch ($this->getKey()) { case PagSeguroMetaDataItemKeys::getItemKeyByDescription('CPF do passageiro'): $parameterValue = PagSeguroHelper::getOnlyNumbers($parameterValue); break; case PagSeguroMetaDataItemKeys::getItemKeyByDescription('Tempo no jogo em dias'): $parameterValue = PagSeguroHelper::getOnlyNumbers($parameterValue); break; case PagSeguroMetaDataItemKeys::getItemKeyByDescription('Celular de recarga'): break; default: break; } return $parameterValue; }
/** * Sets the sender name * @param String $name */ public function setName($name) { $this->name = PagSeguroHelper::formatString($name, 50, ''); }
/** * @param PagSeguroCredentials $credentials * @param $pageNumber * @param $maxPageResults * @param $initialDate * @param null $finalDate * @return null|PagSeguroParserData * @throws Exception * @throws PagSeguroServiceException */ public static function searchByReference(PagSeguroCredentials $credentials, $pageNumber, $maxPageResults, $initialDate, $finalDate = null, $reference) { //Logging $log['text'] = "PagSeguroPreApprovalService.FindByReference(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ", reference=" . $reference . "begin"; LogPagSeguro::info($log['text']); self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $params = self::buildParams($pageNumber, $maxPageResults, $initialDate, $finalDate, $reference); try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildFindByReferenceUrl(self::$connectionData, $params), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset()); self::$service = "FindByReference"; return self::getResult($connection); } catch (PagSeguroServiceException $err) { //Logging LogPagSeguro::error("PagSeguroServiceException: " . $err->getMessage()); //Exception throw $err; } catch (Exception $err) { //Logging LogPagSeguro::error("Exception: " . $err->getMessage()); //Exception throw $err; } }
/** * Check if notification post is empty * @param array $notification_data * @return boolean */ public static function isNotificationEmpty(array $notification_data) { $isEmpty = true; if (isset($notification_data['notificationCode']) && isset($notification_data['notificationType'])) { $isEmpty = PagSeguroHelper::isEmpty($notification_data['notificationCode']) || PagSeguroHelper::isEmpty($notification_data['notificationType']); } return $isEmpty; }
/** * @param $preApproval * @return array */ public static function getCharge($preApproval) { $data = array(); if ($preApproval->getReference() != null) { $data["reference"] = $preApproval->getReference(); } if ($preApproval->getPreApprovalCode() != null) { $data["preApprovalCode"] = $preApproval->getPreApprovalCode(); } // items $items = $preApproval->getItems(); if (count($items) > 0) { $i = 0; foreach ($items as $key => $value) { $i++; if ($items[$key]->getId() != null) { $data["itemId{$i}"] = $items[$key]->getId(); } if ($items[$key]->getDescription() != null) { $data["itemDescription{$i}"] = $items[$key]->getDescription(); } if ($items[$key]->getQuantity() != null) { $data["itemQuantity{$i}"] = $items[$key]->getQuantity(); } if ($items[$key]->getAmount() != null) { $amount = PagSeguroHelper::decimalFormat($items[$key]->getAmount()); $data["itemAmount{$i}"] = $amount; } } } return $data; }
public static function getData($payment) { $data = null; $data = parent::getData($payment); // paymentMode if ($payment->getPaymentMode() != null) { $data["paymentMode"] = $payment->getPaymentMode()->getValue(); } // paymentMethod if ($payment->getPaymentMethod()->getPaymentMethod() != null) { $data["paymentMethod"] = $payment->getPaymentMethod()->getPaymentMethod(); } // senderHash if ($payment->getSenderHash() != null) { $data["senderHash"] = $payment->getSenderHash(); } // receiverEmail if ($payment->getReceiverEmail() != null) { $data["receiverEmail"] = $payment->getReceiverEmail(); } // Bank name if ($payment->getOnlineDebit() != null) { $data["bankName"] = $payment->getOnlineDebit()->getBankName(); } //Credit Card if ($payment->getCreditCard() != null) { //Token if ($payment->getCreditCard()->getToken() != null) { $data['creditCardToken'] = $payment->getCreditCard()->getToken(); } //Installments if ($payment->getCreditCard()->getInstallment() != null) { $installment = $payment->getCreditCard()->getInstallment(); if ($installment->getQuantity() != null && $installment->getValue()) { $data['installmentQuantity'] = $installment->getQuantity(); $data['installmentValue'] = PagSeguroHelper::decimalFormat($installment->getValue()); } } //Holder if ($payment->getCreditCard()->getHolder() != null) { $holder = $payment->getCreditCard()->getHolder(); if ($holder->getName() != null) { $data['creditCardHolderName'] = $holder->getName(); } // documents /*** @var $document PagSeguroDocument */ if ($payment->getCreditCard()->getHolder()->getDocuments() != null) { $documents = $payment->getCreditCard()->getHolder()->getDocuments(); $data['creditCardHolderCPF'] = $documents->getValue(); } if ($holder->getBirthDate() != null) { $data['creditCardHolderBirthDate'] = $holder->getBirthDate(); } // phone if ($holder->getPhone() != null) { if ($holder->getPhone()->getAreaCode() != null) { $data['creditCardHolderAreaCode'] = $holder->getPhone()->getAreaCode(); } if ($holder->getPhone()->getNumber() != null) { $data['creditCardHolderPhone'] = $holder->getPhone()->getNumber(); } } } //Billing Address if ($payment->getCreditCard()->getBilling() != null) { $billingAddress = $payment->getCreditCard()->getBilling()->getAddress(); if ($billingAddress->getStreet() != null) { $data['billingAddressStreet'] = $billingAddress->getStreet(); } if ($billingAddress->getNumber() != null) { $data['billingAddressNumber'] = $billingAddress->getNumber(); } if ($billingAddress->getComplement() != null) { $data['billingAddressComplement'] = $billingAddress->getComplement(); } if ($billingAddress->getCity() != null) { $data['billingAddressCity'] = $billingAddress->getCity(); } if ($billingAddress->getState() != null) { $data['billingAddressState'] = $billingAddress->getState(); } if ($billingAddress->getDistrict() != null) { $data['billingAddressDistrict'] = $billingAddress->getDistrict(); } if ($billingAddress->getPostalCode() != null) { $data['billingAddressPostalCode'] = $billingAddress->getPostalCode(); } if ($billingAddress->getCountry() != null) { $data['billingAddressCountry'] = $billingAddress->getCountry(); } } } return $data; }
/** * Extra Amount * @return extra amount */ private function _extraAmount() { $_tax_amount = self::toFloat($this->Order->getTaxAmount()); $_discount_amount = self::toFloat($this->Order->getBaseDiscountAmount()); return PagSeguroHelper::decimalFormat($_discount_amount + $_tax_amount); }
/** * Gets notification url * @return string */ public function getNotificationUrl() { return !PagSeguroHelper::isEmpty(Configuration::get('PAGSEGURO_NOTIFICATION_URL')) ? Configuration::get('PAGSEGURO_NOTIFICATION_URL') : $this->_notificationURL(); }
/** * Extra Amount * @return extra amount */ private function extraAmount() { $discountAmount = self::toFloat($this->order->getBaseDiscountAmount()); $taxAmount = self::toFloat($this->order->getTaxAmount()); return PagSeguroHelper::decimalFormat($discountAmount + $taxAmount); }
public function setValue($value) { $this->value = PagSeguroHelper::decimalFormat($value); }
/** * Perform update by received PagSeguro notification * @param string $notificationCode */ private function _doUpdateByNotification($statuses, $notificationCode) { try { // getting credentials data $credentials = new PagSeguroAccountCredentials($this->payment_params->pagseguro_email, $this->payment_params->pagseguro_token); // getting transaction data object $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode); // getting PagSeguro status number $statusPagSeguro = $transaction->getStatus()->getValue(); $array_status = array(0 => 'Initiated', 1 => 'Waiting payment', 2 => 'In analysis', 3 => 'Paid', 4 => 'Available', 5 => 'In dispute', 6 => 'refunded', 7 => 'cancelled'); // performing update status if (!PagSeguroHelper::isEmpty($statusPagSeguro) && (int) $statusPagSeguro == 3) { $orderClass = hikashop_get('class.order'); $dbOrder = $orderClass->get((int) $transaction->getReference()); $email = new stdClass(); $history = new stdClass(); $order_status = $this->payment_params->verified_status; $history->notified = 1; if ($dbOrder->order_status == $order_status) { return true; } $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $dbOrder->order_id; $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE); $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url)); $mail_status = $statuses[$order_status]; $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Pagseguro', $array_status[$statusPagSeguro], $dbOrder->order_number); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Pagseguro', $array_status[$statusPagSeguro])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text; $this->modifyOrder($dbOrder->order_id, $order_status, $history, $email); } elseif ((int) $statusPagSeguro == 7) { $orderClass = hikashop_get('class.order'); $dbOrder = $orderClass->get((int) $transaction->getReference()); $email = new stdClass(); $history = new stdClass(); $order_status = $this->payment_params->invalid_status; $history->notified = 0; if ($dbOrder->order_status == $order_status) { return true; } $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $dbOrder->order_id; $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE); $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url)); $mail_status = $statuses[$order_status]; $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Pagseguro', $array_status[$statusPagSeguro], $dbOrder->order_number); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Pagseguro', $array_status[$statusPagSeguro])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $mail_status) . "\r\n\r\n" . $order_text; $this->modifyOrder($dbOrder->order_id, $order_status, $history, $email); } } catch (PagSeguroServiceException $e) { LogPagSeguro::error("Error trying get transaction [" . $e->getMessage() . "]"); } return true; }
/** * Generates shipping data to PagSeguro transaction * @param stdClass $deliveryAddress * @param float $shippingCost * @return \PagSeguroShipping */ private function _generateShippingData($deliveryAddress, $shippingCost) { $shipping = new PagSeguroShipping(); $shipping->setAddress($this->_generateShippingAddressData($deliveryAddress)); $shipping->setType($this->_generateShippingType()); $shipping->setCost(PagSeguroHelper::decimalFormat((double) $shippingCost)); return $shipping; }
private function searchResult($connection, $initialDate = null, $finalDate = null) { $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); LogPagSeguro::info(sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $searchResult->toString()); break; case 'BAD_REQUEST': $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); $err = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error(sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage()); throw $err; break; default: $err = new PagSeguroServiceException($httpStatus); LogPagSeguro::error(sprintf("PagSeguroTransactionSearchService.%s(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end ", self::$logService) . $err->getOneLineMessage()); throw $err; break; } return isset($searchResult) ? $searchResult : false; }
/** * Search transactions abandoned associated with this set of credentials within a date range * * @param PagSeguroCredentials $credentials * @param String $initialDate * @param String $finalDate * @param integer $pageNumber * @param integer $maxPageResults * @return PagSeguroTransactionSearchResult a object of PagSeguroTransactionSearchResult class * @see PagSeguroTransactionSearchResult * @throws PagSeguroServiceException * @throws Exception */ public static function searchAbandoned(PagSeguroCredentials $credentials, $pageNumber, $maxPageResults, $initialDate, $finalDate = null) { LogPagSeguro::info("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME); $searchParams = array('initialDate' => PagSeguroHelper::formatDate($initialDate), 'pageNumber' => $pageNumber, 'maxPageResults' => $maxPageResults); $searchParams['finalDate'] = $finalDate ? PagSeguroHelper::formatDate($finalDate) : null; try { $connection = new PagSeguroHttpConnection(); $connection->get(self::buildSearchUrlAbandoned($connectionData, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new PagSeguroHttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $searchResult = PagSeguroTransactionParser::readSearchResult($connection->getResponse()); LogPagSeguro::info("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $searchResult->toString()); break; case 'BAD_REQUEST': $errors = PagSeguroTransactionParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PagSeguroTransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; } return isset($searchResult) ? $searchResult : false; } catch (PagSeguroServiceException $e) { throw $e; } catch (Exception $e) { LogPagSeguro::error("Exception: " . $e->getMessage()); throw $e; } }
public static function getData($payment) { // reference if ($payment->getReference() != null) { $data["reference"] = $payment->getReference(); } // sender if ($payment->getSender() != null) { if ($payment->getSender()->getName() != null) { $data['senderName'] = $payment->getSender()->getName(); } if ($payment->getSender()->getEmail() != null) { $data['senderEmail'] = $payment->getSender()->getEmail(); } // phone if ($payment->getSender()->getPhone() != null) { if ($payment->getSender()->getPhone()->getAreaCode() != null) { $data['senderAreaCode'] = $payment->getSender()->getPhone()->getAreaCode(); } if ($payment->getSender()->getPhone()->getNumber() != null) { $data['senderPhone'] = $payment->getSender()->getPhone()->getNumber(); } } } // currency if ($payment->getCurrency() != null) { $data['currency'] = $payment->getCurrency(); } // items $items = $payment->getItems(); if (count($items) > 0) { $i = 0; foreach ($items as $key => $value) { $i++; if ($items[$key]->getId() != null) { $data["itemId{$i}"] = $items[$key]->getId(); } if ($items[$key]->getDescription() != null) { $data["itemDescription{$i}"] = $items[$key]->getDescription(); } if ($items[$key]->getQuantity() != null) { $data["itemQuantity{$i}"] = $items[$key]->getQuantity(); } if ($items[$key]->getAmount() != null) { $amount = PagSeguroHelper::decimalFormat($items[$key]->getAmount()); $data["itemAmount{$i}"] = $amount; } if ($items[$key]->getWeight() != null) { $data["itemWeight{$i}"] = $items[$key]->getWeight(); } if ($items[$key]->getShippingCost() != null) { $data["itemShippingCost{$i}"] = PagSeguroHelper::decimalFormat($items[$key]->getShippingCost()); } } } // extraAmount if ($payment->getExtraAmount() != null) { $data['extraAmount'] = PagSeguroHelper::decimalFormat($payment->getExtraAmount()); } // shipping if ($payment->getShipping() != null) { if ($payment->getShipping()->getType() != null && $payment->getShipping()->getType()->getValue() != null) { $data['shippingType'] = $payment->getShipping()->getType()->getValue(); } if ($payment->getShipping()->getCost() != null && $payment->getShipping()->getCost() != null) { $data['shippingCost'] = $payment->getShipping()->getCost(); } // address if ($payment->getShipping()->getAddress() != null) { if ($payment->getShipping()->getAddress()->getStreet() != null) { $data['shippingAddressStreet'] = $payment->getShipping()->getAddress()->getStreet(); } if ($payment->getShipping()->getAddress()->getNumber() != null) { $data['shippingAddressNumber'] = $payment->getShipping()->getAddress()->getNumber(); } if ($payment->getShipping()->getAddress()->getComplement() != null) { $data['shippingAddressComplement'] = $payment->getShipping()->getAddress()->getComplement(); } if ($payment->getShipping()->getAddress()->getCity() != null) { $data['shippingAddressCity'] = $payment->getShipping()->getAddress()->getCity(); } if ($payment->getShipping()->getAddress()->getState() != null) { $data['shippingAddressState'] = $payment->getShipping()->getAddress()->getState(); } if ($payment->getShipping()->getAddress()->getDistrict() != null) { $data['shippingAddressDistrict'] = $payment->getShipping()->getAddress()->getDistrict(); } if ($payment->getShipping()->getAddress()->getPostalCode() != null) { $data['shippingAddressPostalCode'] = $payment->getShipping()->getAddress()->getPostalCode(); } if ($payment->getShipping()->getAddress()->getCountry() != null) { $data['shippingAddressCountry'] = $payment->getShipping()->getAddress()->getCountry(); } } } // maxAge if ($payment->getMaxAge() != null) { $data['maxAge'] = $payment->getMaxAge(); } // maxUses if ($payment->getMaxUses() != null) { $data['maxUses'] = $payment->getMaxUses(); } // redirectURL if ($payment->getRedirectURL() != null) { $data['redirectURL'] = $payment->getRedirectURL(); } // notificationURL if ($payment->getNotificationURL() != null) { $data['notificationURL'] = $payment->getNotificationURL(); } return $data; }
/** * @param $payment PagSeguroPaymentRequest * @return mixed */ public static function getData($payment) { $data = null; // reference if ($payment->getReference() != null) { $data["reference"] = $payment->getReference(); } // sender if ($payment->getSender() != null) { if ($payment->getSender()->getName() != null) { $data['senderName'] = $payment->getSender()->getName(); } if ($payment->getSender()->getEmail() != null) { $data['senderEmail'] = $payment->getSender()->getEmail(); } // phone if ($payment->getSender()->getPhone() != null) { if ($payment->getSender()->getPhone()->getAreaCode() != null) { $data['senderAreaCode'] = $payment->getSender()->getPhone()->getAreaCode(); } if ($payment->getSender()->getPhone()->getNumber() != null) { $data['senderPhone'] = $payment->getSender()->getPhone()->getNumber(); } } // documents /** @var $document PagSeguroDocument */ if ($payment->getSender()->getDocuments() != null) { $documents = $payment->getSender()->getDocuments(); if (is_array($documents) && count($documents) == 1) { foreach ($documents as $document) { if (!is_null($document)) { $data['senderCPF'] = $document->getValue(); } } } } } // currency if ($payment->getCurrency() != null) { $data['currency'] = $payment->getCurrency(); } // items $items = $payment->getItems(); if (count($items) > 0) { $i = 0; foreach ($items as $key => $value) { $i++; if ($items[$key]->getId() != null) { $data["itemId{$i}"] = $items[$key]->getId(); } if ($items[$key]->getDescription() != null) { $data["itemDescription{$i}"] = $items[$key]->getDescription(); } if ($items[$key]->getQuantity() != null) { $data["itemQuantity{$i}"] = $items[$key]->getQuantity(); } if ($items[$key]->getAmount() != null) { $amount = PagSeguroHelper::decimalFormat($items[$key]->getAmount()); $data["itemAmount{$i}"] = $amount; } if ($items[$key]->getWeight() != null) { $data["itemWeight{$i}"] = $items[$key]->getWeight(); } if ($items[$key]->getShippingCost() != null) { $data["itemShippingCost{$i}"] = PagSeguroHelper::decimalFormat($items[$key]->getShippingCost()); } } } // extraAmount if ($payment->getExtraAmount() != null) { $data['extraAmount'] = PagSeguroHelper::decimalFormat($payment->getExtraAmount()); } // shipping if ($payment->getShipping() != null) { if ($payment->getShipping()->getType() != null && $payment->getShipping()->getType()->getValue() != null) { $data['shippingType'] = $payment->getShipping()->getType()->getValue(); } if ($payment->getShipping()->getCost() != null && $payment->getShipping()->getCost() != null) { $data['shippingCost'] = $payment->getShipping()->getCost(); } // address if ($payment->getShipping()->getAddress() != null) { if ($payment->getShipping()->getAddress()->getStreet() != null) { $data['shippingAddressStreet'] = $payment->getShipping()->getAddress()->getStreet(); } if ($payment->getShipping()->getAddress()->getNumber() != null) { $data['shippingAddressNumber'] = $payment->getShipping()->getAddress()->getNumber(); } if ($payment->getShipping()->getAddress()->getComplement() != null) { $data['shippingAddressComplement'] = $payment->getShipping()->getAddress()->getComplement(); } if ($payment->getShipping()->getAddress()->getCity() != null) { $data['shippingAddressCity'] = $payment->getShipping()->getAddress()->getCity(); } if ($payment->getShipping()->getAddress()->getState() != null) { $data['shippingAddressState'] = $payment->getShipping()->getAddress()->getState(); } if ($payment->getShipping()->getAddress()->getDistrict() != null) { $data['shippingAddressDistrict'] = $payment->getShipping()->getAddress()->getDistrict(); } if ($payment->getShipping()->getAddress()->getPostalCode() != null) { $data['shippingAddressPostalCode'] = $payment->getShipping()->getAddress()->getPostalCode(); } if ($payment->getShipping()->getAddress()->getCountry() != null) { $data['shippingAddressCountry'] = $payment->getShipping()->getAddress()->getCountry(); } } } // maxAge if ($payment->getMaxAge() != null) { $data['maxAge'] = $payment->getMaxAge(); } // maxUses if ($payment->getMaxUses() != null) { $data['maxUses'] = $payment->getMaxUses(); } // redirectURL if ($payment->getRedirectURL() != null) { $data['redirectURL'] = $payment->getRedirectURL(); } // notificationURL if ($payment->getNotificationURL() != null) { $data['notificationURL'] = $payment->getNotificationURL(); } // metadata if (count($payment->getMetaData()->getItems()) > 0) { $i = 0; foreach ($payment->getMetaData()->getItems() as $item) { if ($item instanceof PagSeguroMetaDataItem) { if (!PagSeguroHelper::isEmpty($item->getKey()) && !PagSeguroHelper::isEmpty($item->getValue())) { $i++; $data['metadataItemKey' . $i] = $item->getKey(); $data['metadataItemValue' . $i] = $item->getValue(); if (!PagSeguroHelper::isEmpty($item->getGroup())) { $data['metadataItemGroup' . $i] = $item->getGroup(); } } } } } // parameter if (count($payment->getParameter()->getItems()) > 0) { foreach ($payment->getParameter()->getItems() as $item) { if ($item instanceof PagSeguroParameterItem) { if (!PagSeguroHelper::isEmpty($item->getKey()) && !PagSeguroHelper::isEmpty($item->getValue())) { if (!PagSeguroHelper::isEmpty($item->getGroup())) { $data[$item->getKey() . '' . $item->getGroup()] = $item->getValue(); } else { $data[$item->getKey()] = $item->getValue(); } } } } } return $data; }
public function getItemsTotalAmount($items, $shipping = false) { foreach ($items as $item) { if (isset($amount)) { $amount = $amount + $item->getAmount() * $item->getQuantity(); if ($shipping) { $amount = $amount + $item->getShippingCost(); } } else { $amount = $item->getAmount() * $item->getQuantity(); if ($shipping) { $amount = $amount + $item->getShippingCost(); } } } return PagSeguroHelper::decimalFormat($amount); }
public function setDescription($description) { $this->description = PagSeguroHelper::formatString($description, 255); }
public function setValue($value) { $this->value = PagSeguroHelper::getOnlyNumbers($value); }