Skip to content

Commit

Permalink
Merge pull request #39 from goodoneuz/paynet
Browse files Browse the repository at this point in the history
Paynet finalize
  • Loading branch information
shaxzodbek-uzb authored Apr 11, 2019
2 parents 75d031f + 06b5212 commit d462be2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
36 changes: 20 additions & 16 deletions src/Http/Classes/Paynet/Paynet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Goodoneuz\PayUz\Services\PaymentSystemService;
use Goodoneuz\PayUz\Services\PaymentService;
use Goodoneuz\PayUz\Http\Classes\PaymentException;

use Log;
class Paynet
{
public $config;
Expand All @@ -21,26 +21,26 @@ public function __construct()
$this->config = PaymentSystemService::getPaymentSystemParamsCollect(PaymentSystem::PAYNET);
$this->response = new Response();
$this->request = new Request($this->response);
$this->response->setRequest($request);
$this->response->setRequest($this->request);
$this->merchant = new Merchant($this->config, $this->request, $this->response);
}
public function run(){
$this->merchant->Authorize();
switch ($this->request->params['method']) {
case Request::METHOD_CheckTransaction:
$body = $this->CheckTransaction();
$body = Response::makeResponse($this->CheckTransaction());
break;
case Request::METHOD_PerformTransaction:
$body = $this->PerformTransaction();
$body = Response::makeResponse($this->PerformTransaction());
break;
case Request::METHOD_CancelTransaction:
$body = $this->CancelTransaction();
$body = Response::makeResponse($this->CancelTransaction());
break;
case Request::METHOD_GetStatement:
$body = $this->GetStatement();
break;
case Request::METHOD_GetInformation:
$body = $this->GetInformation();
$body = Response::makeResponse($this->GetInformation());
break;
default:
$this->response->response($this->request, 'Method not found.', PaynetException::ERROR_METHOD_NOT_FOUND);
Expand Down Expand Up @@ -100,10 +100,10 @@ private function PerformTransaction()
'system_time_datetime' => DataFormat::timestamp2datetime($this->request->params['transactionTime'])
));
$transaction = Transaction::create([
'payment_system' => Transaction::PAYNET,
'payment_system' => PaymentSystem::PAYNET,
'system_transaction_id' => $this->request->params['transactionId'],
'amount' => 1 * $this->request->params['amount'],
'currency_code' => Transaction::CODE_UZS,
'currency_code' => Transaction::CURRENCY_CODE_UZS,
'state' => Transaction::STATE_CREATED,
'updated_time' => 1*$create_time,
'comment' => (isset($this->request->params['error_note'])?$this->request->params['error_note']:''),
Expand Down Expand Up @@ -152,7 +152,7 @@ private function CancelTransaction(){
private function GetStatement()
{

$transactions = Transaction::where('payment_system', Transaction::PAYNET)
$transactions = Transaction::where('payment_system', PaymentSystem::PAYNET)
->where('state','<>',Transaction::STATE_CANCELLED)
->where('created_at','<=',DataFormat::toDateTime($this->request->params['dateTo']))
->where('created_at','>=',DataFormat::toDateTime($this->request->params['dateFrom']))
Expand All @@ -168,13 +168,17 @@ private function GetStatement()
"<transactionTime>".DataFormat::toDateTimeWithTimeZone($transaction->created_at)."</transactionTime>".
"</statements>";
}

return "<ns1:GetStatementResult>".
"<errorMsg>Success</errorMsg>".
"<status>0</status>".
"<timeStamp>".DataFormat::toDateTimeWithTimeZone(now())."</timeStamp>".
$statements .
"</ns1:GetStatementResult>";

return "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://uws.provider.com/\">".
"<SOAP-ENV:Body>".
"<ns1:GetStatementResult>".
"<errorMsg>Success</errorMsg>".
"<status>0</status>".
"<timeStamp>".DataFormat::toDateTimeWithTimeZone(now())."</timeStamp>".
$statements .
"</ns1:GetStatementResult>".
"</SOAP-ENV:Body>".
"</SOAP-ENV:Envelope>";
}

private function GetInformation(){
Expand Down
5 changes: 4 additions & 1 deletion src/Http/Classes/Paynet/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

namespace Goodoneuz\PayUz\Http\Classes\Paynet;

use Log;
class Request
{

Expand All @@ -33,6 +33,7 @@ public function __construct($response)
$this->response = $response;
$this->params = [];
$arr_params = $this->getRequestArray();
// Log::info($arr_params);
$this->loadAccount($arr_params);

foreach ($arr_params as $key => $value){
Expand All @@ -58,6 +59,8 @@ public function __construct($response)
}
}
public function loadAccount($arr_params){
$arr_params = array_values($arr_params)[0];

$this->params['account'] = [
'login' => $arr_params['username'],
'password' => $arr_params['password']
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Classes/Paynet/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Transaction;
use Carbon\Carbon;
use Goodoneuz\PayUz\Http\Classes\PaymentException;

use Log;
class Response
{
const ERROR_INTERNAL_SYSTEM = -32400;
Expand All @@ -31,11 +31,11 @@ class Response

public function response($request, $body, $code){
$this->request = $request;
$this->body = $this->makeResponse($body);
$this->body = $body;
$this->code = $code;
throw new PaymentException($this);
}
public function makeResponse($body){
public static function makeResponse($body){
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">".
"<soapenv:Body>".
Expand All @@ -45,7 +45,7 @@ public function makeResponse($body){
}
public function send(){
header('content-type: text/xml;');

Log::info($this->body);
if ($this->request == null)
echo 'error';
else
Expand Down
27 changes: 26 additions & 1 deletion src/database/seeds/PayUzSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ public function run()
'name' => 'Click',
'system' => 'click'
]);

PaymentSystem::firstOrCreate([
'name' => 'Paynet',
'system' => 'paynet'
]);
}
if (Schema::hasTable('payment_system_params')) {
//Paycom
PaymentSystemParam::firstOrCreate([
'system' => 'payme',
'label' => 'Login',
Expand All @@ -46,6 +50,7 @@ public function run()
'name' => 'password',
'value' => 'password'
]);
//Click
PaymentSystemParam::firstOrCreate([
'system' => 'click',
'label' => 'Service id',
Expand All @@ -70,6 +75,26 @@ public function run()
'name' => 'merchant_user_id',
'value' => '0000'
]);

//Paynet
PaymentSystemParam::firstOrCreate([
'system' => 'paynet',
'label' => 'Login',
'name' => 'login',
'value' => 'login'
]);
PaymentSystemParam::firstOrCreate([
'system' => 'paynet',
'label' => 'password',
'name' => 'password',
'value' => 'password'
]);
PaymentSystemParam::firstOrCreate([
'system' => 'paynet',
'label' => 'service_id',
'name' => 'service_id',
'value' => 'service_id'
]);
}
}
}

0 comments on commit d462be2

Please sign in to comment.