Skip to content

Commit

Permalink
Merge pull request #61 from abdurashid-dev/master
Browse files Browse the repository at this point in the history
  • Loading branch information
shaxzodbek-uzb authored Aug 10, 2023
2 parents 7f06cb7 + 63e8b57 commit 380e891
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
2 changes: 2 additions & 0 deletions publishable/Payments/before_response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return $additional_params;
37 changes: 21 additions & 16 deletions src/Http/Classes/Click/Click.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Click extends BaseGateway

public function __construct()
{
$this->config = PaymentSystemService::getPaymentSystemParamsCollect(PaymentSystem::CLICK);
$this->request = request();
$this->config = PaymentSystemService::getPaymentSystemParamsCollect(PaymentSystem::CLICK);
$this->request = request();
$this->response = new Response();
$this->merchant = new Merchant($this->response);
}
Expand Down Expand Up @@ -81,28 +81,29 @@ private function Prepare()
$create_time = DataFormat::timestamp(true);

$detail = array(
'create_time' => $create_time,
'system_time_datetime' => DataFormat::timestamp2datetime($params['sign_time'])
'create_time' => $create_time,
'system_time_datetime' => DataFormat::timestamp2datetime($params['sign_time'])
);

$transaction = Transaction::create([
'payment_system' => PaymentSystem::CLICK,
'payment_system' => PaymentSystem::CLICK,
'system_transaction_id' => $params['click_trans_id'],
'amount' => $params['amount'],
'currency_code' => Transaction::CURRENCY_CODE_UZS,
'state' => Transaction::STATE_CREATED,
'updated_time' => 1 * $create_time,
'comment' => $params['error_note'],
'detail' => $detail,
'transactionable_type' => get_class($model),
'transactionable_id' => $model->id
'amount' => $params['amount'],
'currency_code' => Transaction::CURRENCY_CODE_UZS,
'state' => Transaction::STATE_CREATED,
'updated_time' => 1 * $create_time,
'comment' => $params['error_note'],
'detail' => $detail,
'transactionable_type' => get_class($model),
'transactionable_id' => $model->id
]);

$additional_params['merchant_prepare_id'] = $transaction->id;
PaymentService::payListener($model, $transaction, 'paying');

$this->response->setResult(Response::SUCCESS, $additional_params);
}

private function Complete()
{
$params = $this->request->all();
Expand All @@ -115,7 +116,8 @@ private function Complete()
$transaction = null;
try {
$transaction = Transaction::find($params['merchant_prepare_id']);
} catch(\Exception $e) { }
} catch (\Exception $e) {
}
if (!$transaction)
$this->response->setResult(Response::ERROR_TRANSACTION_NOT_FOUND);

Expand Down Expand Up @@ -147,7 +149,10 @@ private function Complete()
$additional_params['merchant_confirm_id'] = $transaction->id;

PaymentService::payListener(null, $transaction, 'after-pay');
$this->response->setResult(Response::SUCCESS, $additional_params);

$response = PaymentService::beforeResponse("CLick@Complete", $params, $additional_params);

$this->response->setResult(Response::SUCCESS, $response);
}

private function check_for_required_field($fields)
Expand Down Expand Up @@ -183,7 +188,7 @@ public function getRedirectParams($model, $amount, $currency, $url)
'SIGN_TIME' => $time,
'SIGN_STRING' => $sign,
'RETURN_URL' => $url,
'url' => 'https://my.click.uz/pay/'
'url' => 'https://my.click.uz/pay/'
];
}
}
16 changes: 14 additions & 2 deletions src/Services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static function convertModelToKey($model)
{
return require base_path('/app/Http/Controllers/Payments/model_key.php');
}

/*
* $key - key of model
* returns model or null
Expand All @@ -29,8 +30,9 @@ public static function convertKeyToModel($key)
{
return require base_path('/app/Http/Controllers/Payments/key_model.php');
}

/*
* returns true/false
* returns true/false
*/
public static function isProperModelAndAmount($model, $amount)
{
Expand Down Expand Up @@ -62,4 +64,14 @@ public static function payListener($model, $transaction, $action_type)
break;
}
}
}

/**
* @param string $string - response string
* @param $params - request params
* @param array $additional_params - additional params
*/
public static function beforeResponse(string $string, $params, array $additional_params)
{
return require base_path('/app/Http/Controllers/Payments/before_response.php');
}
}

0 comments on commit 380e891

Please sign in to comment.