Skip to content

Instantly share code, notes, and snippets.

@jiromm
Last active June 4, 2017 17:25
Show Gist options
  • Save jiromm/6764db28abdd9bbc39f19c249870573b to your computer and use it in GitHub Desktop.
Save jiromm/6764db28abdd9bbc39f19c249870573b to your computer and use it in GitHub Desktop.
Converse.php
<?php
class Converse {
const CURRENCY_AMD = '051';
const CURRENCY_AMD = 'hy';
protected $endpoint = 'https://xxx/payment/rest/register.do';
protected $username = '';
protected $password = '';
protected function getClient()
{
$client = new \Zend\Http\Client();
return $client
->setAdapter(new \Zend\Http\Client\Adapter\Curl())
->setOptions([
'curloptions' => [
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
],
])
->setUri($this->endpoint)
->setMethod(\Zend\Http\Request::METHOD_POST);
}
public function registerOrder(\Zend\Stdlib\Parameters $postData, $uuid, $returnUrl)
{
/**
* @var \Zend\Http\Client $client
*/
$client = $this->getClient();
$client
->setParameterPost([
'userName' => $this->username,
'password' => $this->password,
'orderNumber' => $uuid,
'amount' => $postData->get('amount') * 100,
'currency' => self::CURRENCY_AMD,
'returnUrl' => $returnUrl,
'description' => sprintf('Order by %s %s',
$postData->get('name'),
$postData->get('surname')),
'language' => self::LANGUAGE,
]);
$result = $client->send();
$jsonResult = Json::decode($result->getBody(), Json::TYPE_ARRAY);
if ($jsonResult['errorCode'] != '0') {
throw new \Exception('Converse result is error: ' . print_r($jsonResult, true));
}
$response = new Response();
$response->setStatusCode(302);
$response->getHeaders()
->addHeaderLine('Location', $jsonResult['formUrl']);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment