Beispiel #1
0
 /**
  * Function returns authorize by client credentials response
  * @access public
  * @param bool $debug
  * @return OpenPayUResultOAuth $result
  */
 public static function accessTokenByClientCredentials($debug = true)
 {
     $url = OpenPayUConfiguration::getServiceUrl() . 'oauth/authorize';
     $result = new OpenPayUResultOAuth();
     $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(OpenPayUConfiguration::getClientId(), OpenPayUConfiguration::getClientSecret());
         $result->setAccessToken($json->{'access_token'});
         if (isset($json->{'payu_user_email'})) {
             $result->setPayuUserEmail($json->{'payu_user_email'});
         }
         if (isset($json->{'payu_user_id'})) {
             $result->setPayuUserId($json->{'payu_user_id'});
         }
         $result->setExpiresIn($json->{'expires_in'});
         if (isset($json->{'refresh_token'})) {
             $result->setRefreshToken($json->{'refresh_token'});
         }
         $result->setSuccess(1);
     } catch (Exception $ex) {
         $result->setSuccess(0);
         $result->setError($ex->getMessage());
     }
     return $result;
 }
 public static function getAccessTokenOnly($oauth_client_name, $oauth_client_secret)
 {
     $params = 'client_id=' . $oauth_client_name . '&client_secret=' . $oauth_client_secret . '&grant_type=client_credentials';
     $response = OpenPayU::sendData(OpenPayUNetwork::$openPayuEndPointUrl, $params);
     $resp_json = json_decode($response);
     OpenPayU::addOutputConsole('oauth response', $response);
     $access_token = $resp_json->{'access_token'};
     if (empty($access_token)) {
         throw new Exception('access_token is empty, error: ' . $response);
     }
     return $access_token;
 }
 /**
  * @return JsonResponse|Response
  */
 public function notifyAction()
 {
     $paymentController = $this->get('ant_qa.payu_bundle.controller.payment');
     /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
     $dispatcher = $this->container->get('event_dispatcher');
     try {
         $body = file_get_contents('php://input');
         $data = stripslashes(trim($body));
         /** @var \stdClass $result */
         $result = \OpenPayU_Order::consumeNotification($data)->getResponse();
         if ($result->order->orderId) {
             $order = \OpenPayU_Order::retrieve($result->order->orderId);
             /** @var Payment $payment */
             $payment = $this->getDoctrine()->getManager()->getRepository($this->container->getParameter('payu_bundle.payment_class'))->find($result->order->orderId);
             if ($payment) {
                 if ($payment->getStatus() !== Payment::STATUS_COMPLETED && $payment->getStatus() !== Payment::STATUS_CANCELED) {
                     //update payment status
                     $payment->setStatus($result->order->status);
                     $this->getDoctrine()->getManager()->flush();
                     $event = new PaymentEvent($payment);
                     $dispatcher->dispatch(AntQaPaymentEvents::PAYMENT_STATUS_UPDATE, $event);
                     if ($result->order->status === Payment::STATUS_CANCELED) {
                         //payment canceled - eg. notify user?
                         $event = new PaymentEvent($payment);
                         $dispatcher->dispatch(AntQaPaymentEvents::PAYMENT_CANCELED, $event);
                     }
                     if ($result->order->status === Payment::STATUS_COMPLETED) {
                         //process payment action - eg. add user point?
                         $event = new PaymentEvent($payment);
                         $dispatcher->dispatch(AntQaPaymentEvents::PAYMENT_COMPLETED, $event);
                     }
                 }
             }
             $responseContent = \OpenPayU::buildOrderNotifyResponse($result->order->orderId);
             $response = new Response();
             $response->setContent($responseContent);
             $response->headers->add(['Content-Type' => 'application/json']);
             return $response;
         }
     } catch (\Exception $e) {
         $this->get('logger')->addError($e->getMessage());
         return new JsonResponse($e->getMessage());
     }
     return new Response('thanks for notice');
 }
Beispiel #4
0
 /**
  * Function builds OrderStatusUpdateRequest Document
  * @access public
  * @param string $data
  * @return string $xml
  */
 public static function buildOrderStatusUpdateRequest($data)
 {
     $xml = OpenPayU::buildOpenPayURequestDocument($data, 'OrderStatusUpdateRequest');
     return $xml;
 }
 /**
  * This function sends auth data to the EndPointUrl OpenPayU
  * @access public
  * @param string  $doc
  * @param integer $merchantPosId
  * @param string  $signatureKey
  * @param string  $algorithm
  * @return string
  * @throws OpenPayU_Exception_Configuration
  * @deprecated
  */
 public static function sendOpenPayuDocumentAuth($doc, $merchantPosId, $signatureKey, $algorithm = 'MD5')
 {
     if (empty(self::$openPayuEndPointUrl)) {
         throw new OpenPayU_Exception_Configuration('OpenPayUNetwork::$openPayuEndPointUrl is empty');
     }
     if (empty($signatureKey)) {
         throw new OpenPayU_Exception_Configuration('Merchant Signature Key should not be null or empty.');
     }
     if (empty($merchantPosId)) {
         throw new OpenPayU_Exception_Configuration('MerchantPosId should not be null or empty.');
     }
     $tosigndata = $doc . $signatureKey;
     $xml = urlencode($doc);
     $signature = '';
     if ($algorithm == 'MD5') {
         $signature = md5($tosigndata);
     } else {
         if ($algorithm == 'SHA') {
             $signature = sha1($tosigndata);
         } else {
             if ($algorithm == 'SHA-256' || $algorithm == 'SHA256' || $algorithm == 'SHA_256') {
                 $signature = hash('sha256', $tosigndata);
             }
         }
     }
     $authData = 'sender=' . $merchantPosId . ';signature=' . $signature . ';algorithm=' . $algorithm . ';content=DOCUMENT';
     if (!self::isCurlInstalled()) {
         throw new OpenPayU_Exception_Configuration('curl is not available');
     }
     return OpenPayU::sendDataAuth(self::$openPayuEndPointUrl, 'DOCUMENT=' . $xml, $authData);
 }
 /**
  * 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;
 }
Beispiel #7
0
 public function shipping()
 {
     $this->loadLibConfig();
     if ($this->request->post['DOCUMENT']) {
         $xml = htmlspecialchars_decode($this->request->post['DOCUMENT']);
         $result = OpenPayU_Order::consumeMessage($xml);
         $countrycode = $result->getCountryCode();
         $reqId = $result->getReqId();
         $sessionId = $result->getSessionId();
         $order_id = $this->model_payment_payu->getOrderIdBySessionId(substr($sessionId, 0, 32));
         $this->load->model('localisation/country');
         $country_list = $this->model_localisation_country->getCountries();
         $country_id = 0;
         foreach ($country_list as $country) {
             if ($country['iso_code_2'] == $countrycode) {
                 $country_id = $country['country_id'];
             }
         }
         $this->load->model('checkout/order');
         $order_info = $this->model_checkout_order->getOrder($order_id);
         $shippingCostList = array();
         $this->tax->setShippingAddress($country_id, 0);
         $this->tax->setPaymentAddress($country_id, 0);
         $this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
         foreach ($this->getShippings($order_id, $country_id) as $onemethod) {
             $shipmethod = array('Type' => $onemethod['title'], 'CountryCode' => $countrycode, 'Price' => array('Gross' => str_ireplace('.', '', $this->currency->format($this->tax->calculate($onemethod['cost'], $onemethod['tax_class_id']), $order_info['currency_code'], false, false)), 'Net' => str_ireplace('.', '', $this->currency->format($onemethod['cost'], $order_info['currency_code'], false, false)), 'Tax' => str_ireplace('.', '', $this->currency->format($this->tax->calculate($onemethod['cost'], $onemethod['tax_class_id']) - $onemethod['cost'], $order_info['currency_code'], false, false)), 'CurrencyCode' => $order_info['currency_code']));
             if (false) {
                 $shipmethod[]['State'] = $order_info['shipping_zone'];
                 $shipmethod[]['City'] = $order_info['shipping_city'];
             }
             $shippingCostList[]['ShippingCost'] = $shipmethod;
         }
         $shippingCost = array('CountryCode' => $countrycode, 'ShipToOtherCountry' => 'true', 'ShippingCostList' => $shippingCostList);
         $xml = OpenPayU::buildShippingCostRetrieveResponse($shippingCost, $reqId, $countrycode);
         if (!$result->getSuccess()) {
             $this->logger->write($result->getError() . ' [request: ' . serialize($result->getRequest()) . ', response: ' . serialize(OpenPayU::parseOpenPayUDocument($xml)) . ']');
         }
         header("Content-type: text/xml");
         echo $xml;
     }
 }
Beispiel #8
0
 /**
  * @param $iso_country_code
  * @return null|string
  */
 public function shippingCostRetrieveRequest($iso_country_code)
 {
     if ($iso_country_code) {
         $cart = new Cart($this->id_cart);
         if ($id_country = Country::getByIso($iso_country_code)) {
             if ($id_zone = Country::getIdZone($id_country)) {
                 $carriers = Carrier::getCarriersForOrder($id_zone);
                 $currency = Currency::getCurrency($cart->id_currency);
                 if ($carriers) {
                     $carrier_list = array();
                     foreach ($carriers as $carrier) {
                         $c = new Carrier((int) $carrier['id_carrier']);
                         $shipping_method = $c->getShippingMethod();
                         $price = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier']);
                         $price_tax_exc = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier'], false);
                         $carrier_list[]['ShippingCost'] = array('Type' => $carrier['name'] . ' (' . $carrier['id_carrier'] . ')', 'CountryCode' => Tools::strtoupper($iso_country_code), 'Price' => array('Gross' => $this->toAmount($price), 'Net' => $this->toAmount($price_tax_exc), 'Tax' => $this->toAmount($price) - $this->toAmount($price_tax_exc), 'CurrencyCode' => Tools::strtoupper($currency['iso_code'])));
                     }
                     $shipping_cost = array('CountryCode' => Tools::strtoupper($iso_country_code), 'ShipToOtherCountry' => 'true', 'ShippingCostList' => $carrier_list);
                     $xml = OpenPayU::buildShippingCostRetrieveResponse($shipping_cost, $this->id_request, $iso_country_code);
                     return $xml;
                 } else {
                     Logger::addLog('carrier by id_zone is undefined');
                 }
             }
         }
     }
     return null;
 }