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; }
/** * @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($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); } }
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.'); } }
/** * @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; }
/** * 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; }
/** * Gets notification url * @return string */ public function getNotificationUrl() { return !PagSeguroHelper::isEmpty(Configuration::get('PAGSEGURO_NOTIFICATION_URL')) ? Configuration::get('PAGSEGURO_NOTIFICATION_URL') : $this->_notificationURL(); }
/** * 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; }
/** * Gets the PagSeguro plugin configured values * @return array */ private function _getParamsData() { $paramsData = array(); $db = JFactory::getDBO(); $db->setQuery('SELECT `payment_params` FROM `#__virtuemart_paymentmethods` WHERE `payment_element`="pagseguro" '); $data = explode('|', $db->loadResult()); foreach ($data as $param) { if (!PagSeguroHelper::isEmpty($param)) { $array_temp = explode('=', $param); $paramsData[$array_temp[0]] = str_replace('"', '', $array_temp[1]); } } return $paramsData; }