online payment
This commit is contained in:
parent
d3726ffef3
commit
b091829fc9
|
|
@ -175,7 +175,8 @@ class Plugin extends PluginBase
|
|||
'TPS\Birzha\Components\Offers' => 'offers',
|
||||
'TPS\Birzha\Components\Singleoffer' => 'singleoffer',
|
||||
'TPS\Birzha\Components\OfferForm' => 'offerform',
|
||||
'TPS\Birzha\Components\Messages' => 'messages'
|
||||
'TPS\Birzha\Components\Messages' => 'messages',
|
||||
'TPS\Birzha\Components\PaymentApi' => 'paymentapi'
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,11 @@ class OfferForm extends ComponentBase
|
|||
*/
|
||||
public $countries;
|
||||
|
||||
|
||||
const REGISTRATION_URI = 'register.do';
|
||||
|
||||
const STATUS_URI = 'getOrderStatus.do';
|
||||
|
||||
const API_URL = 'https://mpi.gov.tm/payment/rest/';
|
||||
|
||||
public function componentDetails() {
|
||||
return [
|
||||
|
|
@ -244,7 +248,26 @@ class OfferForm extends ComponentBase
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected function payOnline() {
|
||||
$payment = $this->createNewPayment(false, 'online');
|
||||
|
||||
$response = $this->registerOrder($payment);
|
||||
|
||||
$result = json_decode($response->body,true);
|
||||
|
||||
if($result['errorCode'] == 0){
|
||||
$payment->order_id = $result['orderId'];
|
||||
|
||||
$payment->save();
|
||||
|
||||
return $result['formUrl'];
|
||||
}
|
||||
else{
|
||||
throw new AjaxException(
|
||||
$result
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function onPayByBankTransfer() {
|
||||
$data = input();
|
||||
|
|
@ -374,5 +397,31 @@ class OfferForm extends ComponentBase
|
|||
}
|
||||
|
||||
// payment
|
||||
|
||||
protected function registerOrder($payment) {
|
||||
$client = self::getClient(self::REGISTRATION_URI);
|
||||
|
||||
$url = $this->controller->pageUrl('bank_result.htm', ['payment_id' => $payment->id]);
|
||||
|
||||
$client->data([
|
||||
'amount' => $payment->amount * 100,//multiply by 100 to obtain tenge
|
||||
'currency' => 934,
|
||||
'description' => 'Kart üçin döwlet pajy.',
|
||||
'orderNumber' => strtoupper(str_random(5)) . date('jn'),
|
||||
|
||||
'failUrl' => $url . '?status=success',
|
||||
'returnUrl' => $url . '?status=failed',
|
||||
|
||||
]);
|
||||
|
||||
$client->setOption(CURLOPT_POSTFIELDS,$client->getRequestData());
|
||||
// dd($client);
|
||||
return $client->send();
|
||||
}
|
||||
|
||||
private static function getClient($url){
|
||||
return Http::make(self::API_URL.$url, Http::METHOD_POST)->data([
|
||||
'userName' => Settings::getValue('api_login'),
|
||||
'password' => Settings::getValue('api_password'),
|
||||
])->timeout(3600);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php namespace Tps\Birzha\Components;
|
||||
|
||||
use Cms\Classes\ComponentBase;
|
||||
|
||||
class PaymentApi extends ComponentBase
|
||||
{
|
||||
public function componentDetails() {
|
||||
return [
|
||||
'name' => 'Payment API',
|
||||
'description' => 'Payment API'
|
||||
];
|
||||
}
|
||||
|
||||
public function defineProperties()
|
||||
{
|
||||
return [
|
||||
'payment_id' => [
|
||||
'title' => 'Payment ID',
|
||||
'description' => 'Payment ID',
|
||||
'default' => '{{ :payment_id }}',
|
||||
'type' => 'string',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<script>
|
||||
window.location.href = "{{url}}";
|
||||
</script>
|
||||
<!-- <div>
|
||||
<h1>{{url}}</h1>
|
||||
</div> -->
|
||||
|
|
@ -7,3 +7,6 @@ Route::namespace('TPS\Birzha\Controllers')->group(function () {
|
|||
Route::get('version', 'Settings@version')->name('version');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Route::get('payment-result', ['as'=>'paymentReturn','uses'=>'...@checkPayment'] );
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
title = "bank_result"
|
||||
url = "/bank_result/:payment_id"
|
||||
layout = "default"
|
||||
is_hidden = 0
|
||||
|
||||
[viewBag]
|
||||
localeTitle[en] = "bank_result"
|
||||
localeTitle[ru] = "bank_result"
|
||||
localeUrl[en] = "/bank_result/:payment_id/:is_payment_cancelled/:is_payment_successful"
|
||||
localeUrl[ru] = "/bank_result/:payment_id/:is_payment_cancelled/:is_payment_successful"
|
||||
|
||||
[paymentapi]
|
||||
payment_id = "{{ :payment_id }}"
|
||||
is_payment_cancelled = "{{ :is_payment_cancelled }}"
|
||||
is_payment_successful = "{{ :is_payment_successful }}"
|
||||
==
|
||||
{% component 'paymentapi' %}
|
||||
Loading…
Reference in New Issue