/** * @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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
public function testServiceUrl() { OpenPayU_Configuration::setEnvironment('secure'); $this->assertEquals('https://secure.payu.com/api/v2_1/', OpenPayU_Configuration::getServiceUrl()); }