protected function setUp()
 {
     OpenPayU_Configuration::setEnvironment('secure');
     // production
     OpenPayU_Configuration::setMerchantPosId('145227');
     // POS ID (Checkout)
     OpenPayU_Configuration::setSignatureKey('13a980d4f851f3d9a1cfc792fb1f5e50');
     //Second MD5 key. You will find it in admin panel.
     $this->initializeOrderData();
 }
 public function testHostedOrderForm()
 {
     $expectedForm = file_get_contents(realpath(dirname(__FILE__)) . '/../../resources/hostedOrderForm.txt');
     OpenPayU_Configuration::setHashAlgorithm('MD5');
     $form = OpenPayU_Order::hostedOrderForm($this->_order);
     $this->assertEquals($expectedForm, $form);
 }
 /**
  * @test
  */
 public function shouldSetSenderProperty()
 {
     $array = array();
     $result = OpenPayU_Util::setSenderProperty($array);
     $this->assertEquals($result['properties'][0]['name'], 'sender');
     $this->assertEquals($result['properties'][0]['value'], OpenPayU_Configuration::getFullSenderName());
 }
 public function testShouldSetSenderProperty()
 {
     $array = array();
     $result = json_decode(OpenPayU_Util::buildJsonFromArray($array));
     $this->assertEquals($result->properties[0]->name, 'sender');
     $this->assertEquals($result->properties[0]->value, OpenPayU_Configuration::getFullSenderName());
 }
예제 #5
0
 /**
  * @param $data
  * @param $incomingSignature
  * @throws OpenPayU_Exception_Authorization
  */
 public static function verifyDocumentSignature($data, $incomingSignature)
 {
     $sign = OpenPayU_Util::parseSignature($incomingSignature);
     if (false === OpenPayU_Util::verifySignature($data, $sign->signature, OpenPayU_Configuration::getSignatureKey(), $sign->algorithm)) {
         throw new OpenPayU_Exception_Authorization('Invalid signature - ' . $sign->signature);
     }
 }
예제 #6
0
 /**
  * @param $pathUrl
  * @param $data
  * @return mixed
  */
 public static function delete($pathUrl, $data)
 {
     $posId = OpenPayU_Configuration::getMerchantPosId();
     $signatureKey = OpenPayU_Configuration::getSignatureKey();
     $response = OpenPayU_HttpCurl::doRequest('DELETE', $pathUrl, $data, $posId, $signatureKey);
     return $response;
 }
예제 #7
0
 public function __construct(Session $session, Router $router, $environement, $merchant_pos_id, $pos_auth_key, $client_id, $client_secret, $signature_key)
 {
     $this->session = $session;
     $this->session->start();
     $this->environment = $environement;
     $this->merchantPosId = $merchant_pos_id;
     $this->posAuthKey = $pos_auth_key;
     $this->clientId = $client_id;
     $this->clientSecret = $client_secret;
     $this->signatureKey = $signature_key;
     $this->currencyCode = 'PLN';
     // TODO: from configuration
     $this->orderType = self::ORDER_TYPE_VIRTUAL;
     \OpenPayU_Configuration::setEnvironment($this->environment);
     \OpenPayU_Configuration::setMerchantPosId($this->merchantPosId);
     \OpenPayU_Configuration::setPosAuthKey($this->posAuthKey);
     \OpenPayU_Configuration::setClientId($this->clientId);
     \OpenPayU_Configuration::setClientSecret($this->clientSecret);
     \OpenPayU_Configuration::setSignatureKey($this->signatureKey);
     $this->authUrl = \OpenPayU_Configuration::$authUrl;
     $this->summaryUrl = \OpenPayU_Configuration::$summaryUrl;
     $this->notifyUrl = $router->generate('webultdPayuPaymentBundle_status', array(), true);
     $this->cancelUrl = $router->generate('webultdPayuPaymentBundle_cancel', array(), true);
     $this->completeUrl = $router->generate('webultdPayuPaymentBundle_success', array(), true);
 }
예제 #8
0
 /**
  * @deprecated
  * @param array $data
  * @return OpenPayU_Result
  */
 public static function create($data)
 {
     $pathUrl = OpenPayU_Configuration::getServiceUrl() . 'token' . OpenPayU_Configuration::getDataFormat(true);
     $xml = OpenPayU_Util::buildXmlFromArray($data, 'TokenCreateRequest');
     $result = self::verifyResponse(OpenPayU_Http::post($pathUrl, $xml), 'TokenCreateResponse');
     return $result;
 }
예제 #9
0
 /**
  * @param string $key
  * @return array
  */
 public function getConfig($key = null)
 {
     $config = ['merchant_pos_id' => \OpenPayU_Configuration::getMerchantPosId(), 'signature_key' => \OpenPayU_Configuration::getSignatureKey()];
     if ($key) {
         return $config[$key];
     }
     return $config;
 }
예제 #10
0
 function payment_status($payment)
 {
     $this->config->load('payu', true);
     if (!$this->isLoggedIn) {
         redirect('/login', 'refresh');
     }
     if (!$this->isAdmin) {
         redirect('/', 'refresh');
     }
     OpenPayU_Configuration::setEnvironment('secure');
     OpenPayU_Configuration::setMerchantPosId($this->config->item('PosId', 'payu'));
     OpenPayU_Configuration::setSignatureKey($this->config->item('SignatureKey', 'payu'));
     $order = OpenPayU_Order::retrieve($payment)->getResponse()->orders;
     /* $this->Debug( $order, true ); */
     $this->show('user/panels/admin/payment_status', array('order' => $order));
 }
예제 #11
0
 /**
  * @param $requestType
  * @param $pathUrl
  * @param $data
  * @param $signature
  * @return mixed
  * @throws OpenPayU_Exception_Configuration
  * @throws OpenPayU_Exception_Network
  * @throws OpenPayU_Exception_Authorization
  */
 public static function doRequest($requestType, $pathUrl, $data, $posId, $signatureKey)
 {
     if (empty($pathUrl)) {
         throw new OpenPayU_Exception_Configuration('The end point is empty');
     }
     if (empty($posId)) {
         throw new OpenPayU_Exception_Configuration('PosId is empty');
     }
     if (empty($signatureKey)) {
         throw new OpenPayU_Exception_Configuration('SignatureKey is empty');
     }
     $userNameAndPassword = $posId . ":" . $signatureKey;
     $header = array();
     if (OpenPayU_Configuration::getApiVersion() >= 2) {
         $header[] = 'Content-Type:application/json';
         $header[] = 'Accept:application/json';
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $pathUrl);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType);
     curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'OpenPayU_HttpCurl::readHeader');
     curl_setopt($ch, CURLOPT_POSTFIELDS, OpenPayU_Configuration::getApiVersion() < 2 ? 'DOCUMENT=' . urlencode($data) : $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSLVERSION, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, $userNameAndPassword);
     $response = curl_exec($ch);
     $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($response === false) {
         throw new OpenPayU_Exception_Network(curl_error($ch));
     }
     curl_close($ch);
     return array('code' => $httpStatus, 'response' => trim($response));
 }
예제 #12
0
 /**
  * Function make refund for order
  * @param $orderId
  * @param $description
  * @param int $amount Amount of refund in pennies
  * @return null|OpenPayU_Result
  * @throws OpenPayU_Exception
  */
 public static function create($orderId, $description, $amount = null)
 {
     if (empty($orderId)) {
         throw new OpenPayU_Exception('Invalid orderId value for refund');
     }
     if (empty($description)) {
         throw new OpenPayU_Exception('Invalid description of refund');
     }
     $refund = array('orderId' => $orderId, 'refund' => array('description' => $description));
     if (!empty($amount)) {
         $refund['refund']['amount'] = (int) $amount;
     }
     $pathUrl = OpenPayU_Configuration::getServiceUrl() . 'orders/' . $refund['orderId'] . '/refund';
     $data = OpenPayU_Util::buildJsonFromArray($refund);
     if (empty($data)) {
         throw new OpenPayU_Exception('Empty message RefundCreateResponse');
     }
     $result = self::verifyResponse(OpenPayU_Http::post($pathUrl, $data), 'RefundCreateResponse');
     return $result;
 }
예제 #13
0
 /**
  * Function returns authorize by client credentials response
  * @access public
  * @param integer $debug
  * @return OpenPayU_ResultOAuth
  */
 public static function accessTokenByClientCredentials($debug = TRUE)
 {
     $url = OpenPayU_Configuration::getServiceUrl() . 'oauth/authorize';
     $result = new OpenPayU_ResultOAuth();
     $result->setUrl($url);
     OpenPayU::setOpenPayuEndPoint($url);
     if ($debug) {
         OpenPayU::addOutputConsole('retrieve accessToken', 'retrieve accessToken, client credentials mode, url: ' . $url);
     }
     try {
         OpenPayU::setOpenPayuEndPoint($url);
         $json = OpenPayUOAuth::getAccessTokenByClientCredentials(OpenPayU_Configuration::getClientId(), OpenPayU_Configuration::getClientSecret());
         $result->setAccessToken($json->{'access_token'});
         $result->setPayuUserEmail($json->{'payu_user_email'});
         $result->setPayuUserId($json->{'payu_user_id'});
         $result->setExpiresIn($json->{'expires_in'});
         $result->setRefreshToken($json->{'refresh_token'});
         $result->setSuccess(1);
     } catch (Exception $ex) {
         $result->setSuccess(0);
         $result->setError($ex->getMessage());
     }
     return $result;
 }
예제 #14
0
 /**
  * @access public
  * @param string $sender
  */
 public static function setSender($sender)
 {
     self::$sender = $sender;
 }
예제 #15
0
 /**
  * Initialize PayU configuration
  */
 protected function initializeOpenPayUConfiguration()
 {
     $this->_config = $this->getConfig();
     $this->_myUrl = $this->_config->getBaseUrl();
     OpenPayU_Configuration::setApiVersion(2.1);
     OpenPayU_Configuration::setEnvironment('secure');
     OpenPayU_Configuration::setMerchantPosId($this->_config->getMerchantPosId());
     OpenPayU_Configuration::setSignatureKey($this->_config->getSignatureKey());
     OpenPayU_Configuration::setSender("Magento ver " . Mage::getVersion() . "/Plugin ver " . $this->_config->getPluginVersion());
 }
예제 #16
0
<?php

//namespace OpenPayuSdk\Examples\V2;
/**
 * OpenPayU
 *
 * @copyright  Copyright (c) 2014 PayU
 * @license    http://opensource.org/licenses/LGPL-3.0  Open Software License (LGPL 3.0)
 *
 * http://www.payu.com
 * http://developers.payu.com
 * http://twitter.com/openpayu
 *
 */
OpenPayU_Configuration::setEnvironment('secure');
OpenPayU_Configuration::setMerchantPosId('145227');
// POS ID (Checkout)
OpenPayU_Configuration::setSignatureKey('13a980d4f851f3d9a1cfc792fb1f5e50');
//Second MD5 key. You will find it in admin panel.
/* path for example files*/
$dir = explode(basename(dirname(__FILE__)) . '/', $_SERVER['SCRIPT_NAME']);
$directory = $dir[0] . basename(dirname(__FILE__));
$url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $dir[0];
define('HOME_DIR', $url);
define('EXAMPLES_DIR', HOME_DIR . 'examples/');
예제 #17
0
 /**
  * Function use to update status
  * @access public
  * @param string $sessionId
  * @param string $status
  * @param boolean $debug
  * @return object $result
  */
 public static function updateStatus($sessionId, $status, $debug = TRUE)
 {
     $rq = array('ReqId' => md5(rand()), 'MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(), 'SessionId' => $sessionId, 'OrderStatus' => $status, 'Timestamp' => date('c'));
     $result = new OpenPayU_Result();
     $result->setRequest($rq);
     $url = OpenPayU_Configuration::getServiceUrl() . 'co/openpayu/OrderStatusUpdateRequest';
     if ($debug) {
         OpenPayU::addOutputConsole('OpenPayU endpoint for OrderStatusUpdateRequest message', $url);
     }
     $oauthResult = OpenPayu_OAuth::accessTokenByClientCredentials();
     OpenPayU::setOpenPayuEndPoint($url . '?oauth_token=' . $oauthResult->getAccessToken());
     $xml = OpenPayU::buildOrderStatusUpdateRequest($rq);
     if ($debug) {
         OpenPayU::addOutputConsole('OrderStatusUpdateRequest message', htmlentities($xml));
     }
     $merchantPosId = OpenPayU_Configuration::getMerchantPosId();
     $signatureKey = OpenPayU_Configuration::getSignatureKey();
     $response = OpenPayU::sendOpenPayuDocumentAuth($xml, $merchantPosId, $signatureKey);
     if ($debug) {
         OpenPayU::addOutputConsole('OrderStatusUpdateResponse message', htmlentities($response));
     }
     // verify response from PayU service
     $status = OpenPayU::verifyOrderStatusUpdateResponseStatus($response);
     if ($debug) {
         OpenPayU::addOutputConsole('OrderStatusUpdateResponse status', serialize($status));
     }
     $result->setStatus($status);
     $result->setError($status['StatusCode']);
     $result->setSuccess($status['StatusCode'] == 'OPENPAYU_SUCCESS' ? TRUE : FALSE);
     $result->setResponse(OpenPayU::parseOpenPayUDocument($response));
     return $result;
 }
예제 #18
0
 /**
  * @param $items
  * @param $customer_sheet
  * @param $order_notify_link
  * @param $order_cancel_link
  * @param $order_complete_link
  * @param $currency
  * @param $grand_total
  * @param $carriers_list
  * @return array
  */
 private function prepareOrder($items, $customer_sheet, $order_notify_link, $order_cancel_link, $order_complete_link, $currency, $grand_total, $carriers_list)
 {
     $ocreq = array();
     $ocreq['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
     $ocreq['orderUrl'] = $this->context->link->getPageLink('guest-tracking.php', true);
     $ocreq['description'] = $this->l('Order for cart: ') . ' ' . $this->cart->id . ' ' . $this->l(' from the store: ') . ' ' . Configuration::get('PS_SHOP_NAME');
     $ocreq['validityTime'] = 60 * (int) Configuration::get('PAYU_VALIDITY_TIME');
     $ocreq['products'] = $items['products'];
     $ocreq['buyer'] = $customer_sheet;
     $ocreq['customerIp'] = $_SERVER['REMOTE_ADDR'] == '::1' || $_SERVER['REMOTE_ADDR'] == '::' || !preg_match('/^((?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$/m', $_SERVER['REMOTE_ADDR']) ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];
     $ocreq['notifyUrl'] = $order_notify_link;
     $ocreq['cancelUrl'] = $order_cancel_link;
     $ocreq['continueUrl'] = $order_complete_link . '?id_cart=' . $this->cart->id;
     $ocreq['currencyCode'] = $currency['iso_code'];
     $ocreq['totalAmount'] = $grand_total;
     $ocreq['extOrderId'] = $this->cart->id . '-' . microtime();
     $ocreq['shippingMethods'] = $carriers_list['shippingMethods'];
     return $ocreq;
 }
예제 #19
0
 /**
  * @param array $data
  * @return array
  */
 private static function setSenderProperty($data)
 {
     $data['properties'][0] = array('name' => 'sender', 'value' => OpenPayU_Configuration::getFullSenderName());
     return $data;
 }
예제 #20
0
<?php

//namespace OpenPayuSdk\Examples\V2;
/**
 * OpenPayU
 *
 * @copyright  Copyright (c) 2014 PayU
 * @license    http://opensource.org/licenses/LGPL-3.0  Open Software License (LGPL 3.0)
 *
 * http://www.payu.com
 * http://developers.payu.com
 * http://twitter.com/openpayu
 *
 */
OpenPayU_Configuration::setEnvironment('secure');
OpenPayU_Configuration::setMerchantPosId('4966124');
// POS ID (Checkout)
OpenPayU_Configuration::setSignatureKey('b5588f9e8c0b3587bf8de820f385c76e');
//Second MD5 key. You will find it in admin panel.
/* path for example files*/
$dir = explode(basename(dirname(__FILE__)) . '/', $_SERVER['SCRIPT_NAME']);
$directory = $dir[0] . basename(dirname(__FILE__));
$url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $dir[0];
define('HOME_DIR', $url);
define('EXAMPLES_DIR', HOME_DIR . 'examples/');
예제 #21
0
 /**
  * Initializes the payment.
  * @param Mage_Sales_Model_Order
  * @param Mage_Shipping_Model_Shipping
  * @return array
  */
 public function orderCreateRequest(Mage_Sales_Model_Order $order, $allShippingRates)
 {
     $this->setOrder($order);
     $orderCurrencyCode = $order->getOrderCurrencyCode();
     $orderCountryCode = $order->getBillingAddress()->getCountry();
     $shippingCostList = array();
     if (empty($allShippingRates) || Mage::getSingleton('customer/session')->isLoggedIn()) {
         if ($order->getShippingInclTax() > 0) {
             $shippingCostList['shippingMethods'][] = array('name' => $order->getShippingDescription(), 'country' => $orderCountryCode, 'price' => $this->_toAmount($order->getShippingInclTax()));
         }
         $grandTotal = $order->getGrandTotal() - $order->getShippingInclTax();
     } else {
         $firstPrice = 0;
         foreach ($allShippingRates as $key => $rate) {
             $gross = $this->_toAmount($rate->getPrice());
             if ($key == 0) {
                 $firstPrice = $rate->getPrice();
             }
             $shippingCostList['shippingMethods'][] = array('name' => $rate->getMethodTitle(), 'country' => $orderCountryCode, 'price' => $gross);
         }
         $grandTotal = $order->getGrandTotal() - $firstPrice;
     }
     $orderItems = $order->getAllVisibleItems();
     $items = array();
     $productsTotal = 0;
     $isDiscount = false;
     $response = array('redirectUri' => Mage::getUrl('checkout/onepage/failure', array('_secure' => true)));
     foreach ($orderItems as $key => $item) {
         $itemInfo = $item->getData();
         if ($itemInfo['discount_amount'] > 0) {
             $itemInfo['price_incl_tax'] = $itemInfo['price_incl_tax'] - $itemInfo['discount_amount'];
             $isDiscount = true;
         } else {
             if ($itemInfo['discount_percent'] > 0) {
                 $itemInfo['price_incl_tax'] = $itemInfo['price_incl_tax'] * (100 - $itemInfo['discount_percent']) / 100;
             }
         }
         // Check if the item is countable one
         if ($this->_toAmount($itemInfo['price_incl_tax']) > 0) {
             $items['products'][] = array('quantity' => (int) $itemInfo['qty_ordered'], 'name' => $itemInfo['name'], 'unitPrice' => $this->_toAmount($itemInfo['price_incl_tax']));
             $productsTotal += $itemInfo['price_incl_tax'] * $itemInfo['qty_ordered'];
         }
     }
     // assigning the shopping cart
     $shoppingCart = array('grandTotal' => $this->_toAmount($grandTotal), 'CurrencyCode' => $orderCurrencyCode, 'ShoppingCartItems' => $items);
     $orderInfo = array('merchantPosId' => OpenPayU_Configuration::getMerchantPosId(), 'orderUrl' => Mage::getUrl('sales/order/view', array('order_id' => $order->getId())), 'description' => 'Order no ' . $order->getRealOrderId(), 'validityTime' => $this->getConfig()->getOrderValidityTime());
     if ($isDiscount) {
         $items['products'] = array();
         $items['products'][] = array('quantity' => 1, 'name' => $this->_helper()->__('Order #%s', $order->getId()), 'unitPrice' => $this->_toAmount($grandTotal));
     }
     $OCReq = $orderInfo;
     $OCReq['products'] = $items['products'];
     $OCReq['customerIp'] = Mage::app()->getFrontController()->getRequest()->getClientIp();
     $OCReq['notifyUrl'] = $this->getConfig()->getUrl('orderNotifyRequest');
     $OCReq['cancelUrl'] = $this->getConfig()->getUrl('cancelPayment');
     $OCReq['continueUrl'] = $this->getConfig()->getUrl('continuePayment');
     $OCReq['currencyCode'] = $orderCurrencyCode;
     $OCReq['totalAmount'] = $shoppingCart['grandTotal'];
     $OCReq['extOrderId'] = $order->getId() . self::DELIMITER . microtime();
     if (!empty($shippingCostList)) {
         $OCReq['shippingMethods'] = $shippingCostList['shippingMethods'];
     }
     unset($OCReq['shoppingCart']);
     $billingAddressId = $order->getBillingAddressId();
     if (!empty($billingAddressId)) {
         $billingAddress = $order->getBillingAddress();
         $customerEmail = $billingAddress->getEmail();
         if (!empty($customerEmail)) {
             $customerSheet = array('email' => $billingAddress->getEmail(), 'phone' => $billingAddress->getTelephone(), 'firstName' => $billingAddress->getFirstname(), 'lastName' => $billingAddress->getLastname());
             $shippingAddressId = $order->getShippingAddressId();
             if (!empty($shippingAddressId)) {
                 $shippingAddress = $order->getShippingAddress();
             }
             if (!$order->getIsVirtual()) {
                 $customerSheet['delivery'] = array('street' => trim(implode(' ', $shippingAddress->getStreet())), 'postalCode' => $shippingAddress->getPostcode(), 'city' => $shippingAddress->getCity(), 'countryCode' => $shippingAddress->getCountry(), 'recipientName' => trim($shippingAddress->getFirstname() . ' ' . $shippingAddress->getLastname()), 'recipientPhone' => $shippingAddress->getTelephone(), 'recipientEmail' => $shippingAddress->getEmail());
             }
             $OCReq['buyer'] = $customerSheet;
         }
     }
     try {
         $result = OpenPayU_Order::create($OCReq);
         if ($result->getStatus() == OpenPayU_Order::STATUS_SUCCESS) {
             // store session identifier in session info
             Mage::getSingleton('core/session')->setPayUSessionId($result->getResponse()->orderId);
             // assign current transaction id
             $this->_transactionId = $result->getResponse()->orderId;
             $order->getPayment()->setLastTransId($this->_transactionId);
             $locale = Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId());
             $langCode = explode('_', $locale, 2);
             $response = array('redirectUri' => $result->getResponse()->redirectUri, 'url' => OpenPayu_Configuration::getSummaryUrl(), 'sessionId' => $result->getResponse()->orderId, 'lang' => strtolower($langCode[1]));
             $customer = Mage::getModel('customer/customer');
             if ($order->getCustomerIsGuest()) {
                 $email = $billingAddress->getEmail();
                 $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
                 $customer->loadByEmail($email);
                 if (!$customer->getId()) {
                     $order->setCustomerEmail($email);
                 }
             } else {
                 $customer->load($order->getCustomerId());
             }
         } else {
             Mage::throwException($this->_helper()->__('There was a problem with the payment initialization, please contact system administrator.'));
         }
     } catch (Exception $e) {
         Mage::logException($e);
     }
     $order->sendNewOrderEmail();
     $order->save();
     return $response;
 }
예제 #22
0
 public function buildorder()
 {
     $OCRV2 = array();
     $this->language->load('payment/payu');
     $this->load->model('payment/payu');
     $this->loadLibConfig();
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $this->load->model('localisation/country');
     $this->tax->setShippingAddress($order_info['shipping_country_id'], $order_info['shipping_zone_id']);
     $this->tax->setPaymentAddress($order_info['payment_country_id'], $order_info['payment_zone_id']);
     $this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
     $grandTotal = 0;
     $cartItems = array();
     $orderType = 'VIRTUAL';
     $shippingCostAmount = 0.0;
     $decimalPlace = $this->currency->getDecimalPlace();
     if (!empty($this->session->data['vouchers'])) {
         foreach ($this->session->data['vouchers'] as $voucher) {
             $this->vouchersAmount += $this->currency->format($voucher['amount']);
             $OCRV2['products'][] = array('quantity' => 1, 'name' => $voucher['description'], 'unitPrice' => $this->toAmount($voucher['amount']));
         }
     }
     foreach ($this->cart->getProducts() as $item) {
         list($orderType, $OCRV2, $grandTotal) = $this->prepareProductsSection($decimalPlace, $item, $order_info, $OCRV2, $grandTotal);
     }
     $shoppingCart = array('GrandTotal' => $grandTotal, 'CurrencyCode' => $order_info['currency_code'], 'ShoppingCartItems' => $cartItems);
     //$this->session->data['sessionId'] = md5(rand() . rand() . rand() . rand()) . $this->session->data['order_id'];
     $order = array('MerchantPosId' => OpenPayU_Configuration::getMerchantPosId(), 'SessionId' => '', 'OrderUrl' => $this->url->link('payment/payu/callback') . '?order=' . $this->session->data['order_id'], 'OrderCreateDate' => date("c"), 'OrderDescription' => 'Order ' . $this->session->data['order_id'], 'MerchantAuthorizationKey' => OpenPayU_Configuration::getPosAuthKey(), 'OrderType' => $orderType, 'ShoppingCart' => $shoppingCart);
     $OCReq = array('ReqId' => md5(rand()), 'CustomerIp' => $order_info['ip'] == "::1" || $order_info['ip'] == "::" || !preg_match("/^((?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9]).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\$/m", $order_info['ip']) ? '127.0.0.1' : $order_info['ip'], 'NotifyUrl' => $this->url->link('payment/payu/ordernotify'), 'OrderCancelUrl' => $this->url->link('payment/payu/paymentcancel'), 'OrderCompleteUrl' => $this->url->link('payment/payu/paymentsuccess'), 'Order' => $order);
     $customer = array();
     if (!empty($order_info['email'])) {
         $customer = array('email' => $order_info['email'], 'firstName' => $order_info['firstname'], 'lastName' => $order_info['lastname'], 'phone' => $order_info['telephone']);
     } elseif (!empty($this->session->data['customer_id'])) {
         $this->load->model('account\\customer');
         $custdata = $this->model_account_customer->getCustomer($this->session['customer_id']);
         if (!empty($custdata['email'])) {
             $customer = array('email' => $order_info['email'], 'firstName' => $order_info['firstname'], 'lastName' => $order_info['lastname'], 'phone' => $order_info['telephone']);
         }
     }
     if ($orderType == 'MATERIAL') {
         if (!empty($customer) && !empty($order_info['shipping_city']) && !empty($order_info['shipping_postcode']) && !empty($order_info['payment_iso_code_2'])) {
             $customer['delivery'] = array('street' => $order_info['shipping_address_1'] . " " . ($order_info['shipping_address_2'] ? $order_info['shipping_address_2'] : ''), 'postalCode' => $order_info['shipping_postcode'], 'city' => $order_info['shipping_city'], 'countryCode' => $order_info['payment_iso_code_2'], 'recipientName' => $order_info['shipping_firstname'] . " " . $order_info['shipping_lastname'], 'recipientPhone' => $order_info['telephone'], 'recipientEmail' => $order_info['email']);
         }
         if (!empty($order_info['shipping_method'])) {
             list($shippingCostList, $shippingCostAmount) = $this->prepareShippingMethodsSection($decimalPlace, $order_info);
         } else {
             $shippingCostList = array();
             $shipping_methods = $this->getShippings($this->session->data['order_id'], $order_info['shipping_country_id']);
             $country = $this->model_localisation_country->getCountry($order_info['shipping_country_id']);
             foreach ($shipping_methods as $onemethod) {
                 if (empty($decimalPlace)) {
                     $onemethod['cost'] *= 100;
                     $shippingCostAmount = $shippingCost;
                 }
                 $price = $this->currency->format($this->tax->calculate($onemethod['cost'], $onemethod['tax_class_id']), $order_info['currency_code'], false, false);
                 $price = preg_replace("/[^0-9]/", "", $price);
                 $shippingCostList['shippingMethods'][] = array('name' => $onemethod['title'], 'country' => $country['iso_code_2'], 'price' => $price);
             }
         }
     }
     if (isset($this->session->data['coupon']) || !empty($this->session->data['coupon'])) {
         $OCRV2 = $this->prepareCumulatedProductsArray($OCRV2, $order_info, $shippingCostAmount);
     }
     $OCRV2['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
     $OCRV2['orderUrl'] = $this->url->link('payment/payu/callback') . '?order=' . $this->session->data['order_id'];
     $OCRV2['description'] = "Zamówienie #" . $this->session->data['order_id'];
     $OCRV2['customerIp'] = $OCReq['CustomerIp'];
     $OCRV2['notifyUrl'] = $OCReq['NotifyUrl'];
     $OCRV2['cancelUrl'] = $OCReq['OrderCancelUrl'];
     $OCRV2['continueUrl'] = $OCReq['OrderCompleteUrl'];
     $OCRV2['currencyCode'] = $order_info['currency_code'];
     $total = $order_info['total'];
     if (empty($decimalPlace)) {
         $total = $this->toAmount($total);
     }
     $total = str_ireplace(array('.', ' '), array('', ''), $this->currency->format($total - $shippingCostAmount, $order_info['currency_code'], false, false));
     $OCRV2['totalAmount'] = $total;
     $OCRV2['extOrderId'] = $this->session->data['order_id'] . '-' . microtime();
     if (isset($shippingCostList)) {
         $OCRV2['shippingMethods'] = $shippingCostList['shippingMethods'];
     }
     $OCRV2['buyer'] = $customer;
     return $OCRV2;
 }
예제 #23
0
 * http://developers.payu.com
 * http://twitter.com/openpayu
 *
 */
require_once realpath(dirname(__FILE__)) . '/../../../lib/openpayu.php';
require_once realpath(dirname(__FILE__)) . '/../../config.php';
OpenPayU_Configuration::setEnvironment('secure');
OpenPayU_Configuration::setMerchantPosId('4966124');
// POS ID (Checkout)
OpenPayU_Configuration::setSignatureKey('b5588f9e8c0b3587bf8de820f385c76e');
//Second MD5 key. You will find it in admin panel.
$order = array();
$order['notifyUrl'] = 'http://localhost' . dirname($_SERVER['REQUEST_URI']) . '/OrderNotify.php';
$order['continueUrl'] = 'http://localhost' . dirname($_SERVER['REQUEST_URI']) . '/../../layout/success.php';
$order['customerIp'] = '127.0.0.1';
$order['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
$order['description'] = 'New order';
$order['currencyCode'] = 'PLN';
$order['totalAmount'] = 3200;
$order['extOrderId'] = rand(1000, 1000000);
$order['products'][0]['name'] = 'Product1';
$order['products'][0]['unitPrice'] = 1000;
$order['products'][0]['quantity'] = 1;
$order['products'][1]['name'] = 'Product2';
$order['products'][1]['unitPrice'] = 2200;
$order['products'][1]['quantity'] = 1;
$order['buyer']['email'] = '*****@*****.**';
$order['buyer']['phone'] = '123123123';
$order['buyer']['firstName'] = 'Jan';
$order['buyer']['lastName'] = 'Kowalski';
/*~~~~~~~~ optional part INVOICE data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 public static function setSignatureKey($value)
 {
     self::$signatureKey = $value;
 }
예제 #25
0
 /**
  * Function builds OpenPayU Xml Document
  * @access public
  * @param string  $data
  * @param string  $startElement
  * @param integer $request
  * @param string  $xml_version
  * @param string  $xml_encoding
  * @return string $xml
  */
 public static function buildOpenPayUDocument($data, $startElement, $request = 1, $xml_version = '1.0', $xml_encoding = 'UTF-8')
 {
     if (!is_array($data)) {
         return false;
     }
     $xml = new XmlWriter();
     $xml->openMemory();
     $xml->startDocument($xml_version, $xml_encoding);
     if (OpenPayU_Configuration::getApiVersion() < 2) {
         $xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/openpayu.xsd');
         $header = $request == 1 ? 'HeaderRequest' : 'HeaderResponse';
         $xml->startElement($header);
         $xml->writeElement('Algorithm', OpenPayU_Configuration::getHashAlgorithm());
         $xml->writeElement('SenderName', 'exampleSenderName');
         $xml->writeElement('Version', $xml_version);
         $xml->endElement();
     } else {
         $xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/20/openpayu.xsd');
     }
     // domain level - open
     if (OpenPayU_Configuration::getApiVersion() < 2) {
         $xml->startElement(OpenPayUDomain::getDomain4Message($startElement));
     }
     // message level - open
     $xml->startElement($startElement);
     OpenPayU_Util::convertArrayToXml($xml, $data);
     // message level - close
     $xml->endElement();
     // domain level - close
     $xml->endElement();
     // document level - close
     if (OpenPayU_Configuration::getApiVersion() < 2) {
         $xml->endElement();
     }
     return $xml->outputMemory(true);
 }
예제 #26
0
 /**
  * Generate a form body for hosted order
  *
  * @access public
  * @param $order An array containing full Order
  * @param $params An optional array with form elements' params
  * @return string Response html form
  */
 public static function hostedOrderForm($order, $params = array())
 {
     $orderFormUrl = OpenPayU_Configuration::getServiceUrl() . 'orders';
     $usortedFormFieldValuesAsArray = array();
     $htmlFormFields = OpenPayU_Util::convertArrayToHtmlForm($order, "", $usortedFormFieldValuesAsArray);
     ksort($usortedFormFieldValuesAsArray);
     $sortedFormFieldValuesAsString = implode('', array_values($usortedFormFieldValuesAsArray));
     $signature = OpenPayU_Util::generateSignData($sortedFormFieldValuesAsString, OpenPayU_Configuration::getHashAlgorithm(), OpenPayU_Configuration::getMerchantPosId(), OpenPayU_Configuration::getSignatureKey());
     $formParams = array_merge(self::$defaultFormParams, $params);
     $htmlOutput = sprintf("<form method=\"POST\" action=\"%s\" id=\"%s\" class=\"%s\">\n", $orderFormUrl, $formParams['formId'], $formParams['formClass']);
     $htmlOutput .= $htmlFormFields;
     $htmlOutput .= sprintf("<input type=\"hidden\" name=\"OpenPayu-Signature\" value=\"%s\" />", $signature);
     $htmlOutput .= sprintf("<button type=\"submit\" formtarget=\"%s\" id=\"%s\" class=\"%s\">%s</button>", $formParams['submitTarget'], $formParams['submitId'], $formParams['submitClass'], $formParams['submitContent']);
     $htmlOutput .= "</form>\n";
     return $htmlOutput;
 }
예제 #27
0
 /**
  * @param $data
  * @return mixed
  */
 public static function setSenderProperty($data)
 {
     $data['properties'][0]['name'] = 'sender';
     $data['properties'][0]['value'] = OpenPayU_Configuration::getFullSenderName();
     return $data;
 }
 /**
  * @test
  */
 public function shouldReturnDefgaultSDKVersionWhenComposerFileIsNotGiven()
 {
     //given
     $OpenPayU_ConfigurationMock = $this->getMock('OpenPayU_Configuration');
     $OpenPayU_ConfigurationMock->expects($this->any())->method('getComposerFilePath')->will($this->returnValue('mock.json'));
     //when
     $sdkVersion = OpenPayU_Configuration::getSdkVersion();
     //then
     $this->assertEquals(self::PHP_SDK_VERSION, $sdkVersion);
 }
 /**
  * @param OptionsResolverInterface $resolver
  */
 protected function configureOrder(OptionsResolverInterface $resolver)
 {
     $resolver->setRequired(['continueUrl', 'notifyUrl', 'customerIp', 'merchantPosId', 'description', 'currencyCode', 'totalAmount', 'extOrderId', 'products', 'buyer'])->setDefaults(['currencyCode' => 'PLN', 'merchantPosId' => (int) \OpenPayU_Configuration::getMerchantPosId()])->setAllowedTypes(['continueUrl' => 'string', 'notifyUrl' => 'string', 'customerIp' => 'string', 'merchantPosId' => 'int', 'description' => 'string', 'currencyCode' => 'string', 'totalAmount' => 'integer', 'extOrderId' => 'integer', 'products' => 'array', 'buyer' => 'array']);
 }
예제 #30
0
 public function __construct($environment, $signatureKey, $posId)
 {
     \OpenPayU_Configuration::setEnvironment($environment);
     \OpenPayU_Configuration::setMerchantPosId($posId);
     \OpenPayU_Configuration::setSignatureKey($signatureKey);
 }