Merge branch 'front-api'

This commit is contained in:
Robert 2020-11-05 14:38:49 +01:00
commit 0a2d8aaf0e
4 changed files with 1523 additions and 20 deletions

View File

@ -7,10 +7,11 @@ function nakupovanje_1ka_menu()
{
$items = [];
$items['nakupovanje-api'] = [
$items['nakupovanje-api/%'] = [
'title' => 'API', //page title
'page callback' => 'nakupovanje_1ka_api', //callback function which is invoked when menu item is called.
'access callback' => MENU_CALLBACK, //any user can access this page
'access callback' => MENU_LOCAL_ACTION, //any user can access this page
//'type' => MENU_CALLBACK,
'page arguments' => [
1,
],
@ -196,7 +197,56 @@ function nakupovanje_1ka_menu()
function nakupovanje_1ka_api()
{
return 'success';
$api_url = 'http://1ka.test/frontend/payments/api.php';
// Ime akcije dobimo preko zadnjega GET parametra, ki ga Drupal samo uporabi
$action = arg(1);
// GET params
$params = 'action='. $action; // Funkcija, ki jo želimo izvesti
$post_data = $_POST;
if(!empty($post_data) && sizeof($post_data) > 0){
$request_method = 'POST';
$raw_post_data = http_build_query($post_data);
} else {
$request_method = 'GET';
$raw_post_data = '';
}
// Pripravimo stvari za izdelavo tokena
$request_url = $api_url.'?'.$params;
$data = $request_method . $request_url .$raw_post_data;
// Nastavimo identifier in key userja
$private_key = 'NLFYb67/[pUE%W-s';
// Izracunamo hash (token)
$token = hash_hmac('sha256', $data, $private_key);
// Pripravimo klic dodamo parametra »identifikator« in »token«
$ch = curl_init($request.'&token='.$token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_method);
if($request_method == 'POST') {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data)); // JSON string za POST
curl_setopt($ch, CURLOPT_POST, TRUE);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
// Izvedemo klic
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
die();
}
function nakupovanje_1ka_kosarica()

View File

@ -795,7 +795,7 @@
) {
var parametri = window.location.search.substr(1);
jQuery.post('/frontend/payments/api.php?action=cancel_narocilo_paypal', parametri).done(function (val) {
jQuery.post('/d/nakupovanje-api/cancel_narocilo_paypal', parametri).done(function (val) {
val = JSON.parse(val);
if (val.error) {
@ -811,7 +811,7 @@
){
var parametri = window.location.search.substr(1);
jQuery.post('/frontend/payments/api.php?action=capture_narocilo_paypal', parametri).done(function (val) {
jQuery.post('/d/nakupovanje-api/capture_narocilo_paypal', parametri).done(function (val) {
val = JSON.parse(val);
if (val.error) {
@ -847,12 +847,19 @@
// PRidobimo pakete
if (window.location.pathname.indexOf('zasebni-paketi') > -1 || window.location.pathname.indexOf('private-packages') > -1) {
jQuery.post('/frontend/payments/api.php?action=get_paketi').done(function (val) {
jQuery.post('/d/nakupovanje-api/get_paketi').done(function (val) {
val = JSON.parse(val);
jQuery('[data-price="2"]').text(val.paketi[2].price[12].monthly);
jQuery('[data-price="3"]').text(val.paketi[3].price[12].monthly);
});
// jQuery.post('/frontend/payments/api.php?action=get_paketi').done(function (val) {
// val = JSON.parse(val);
//
// jQuery('[data-price="2"]').text(val.paketi[2].price[12].monthly);
// jQuery('[data-price="3"]').text(val.paketi[3].price[12].monthly);
// });
}
@ -960,8 +967,7 @@
var podatki = jQuery('#narocilo-poslovni-uporabniki').serialize();
jQuery.post('/frontend/payments/api.php?action=send_poslovni_uporabniki', podatki).done(function (val) {
jQuery.post('/d/nakupovanje-api/send_poslovni_uporabniki', podatki).done(function (val) {
val = JSON.parse(val);
if (val.success) {
@ -971,6 +977,17 @@
}
});
// jQuery.post('/frontend/payments/api.php?action=send_poslovni_uporabniki', podatki).done(function (val) {
// val = JSON.parse(val);
//
// if (val.success) {
// jQuery('#narocilo-poslovni-uporabniki').hide();
// jQuery('#nakup-1ka-poslovni-uporabniki .uspesno-oddano-narocilo').show();
// jQuery('.vsebina h1').text('Uspešno oddano naročilo');
// }
// });
});
jQuery(window).scroll(function () {
@ -1190,8 +1207,7 @@ function oddajNarociloNaStreznik() {
var podatki = jQuery('form#narocilo-paketa-podatki').serialize();
jQuery.post('/frontend/payments/api.php?action=create_narocilo', podatki).done(function (val) {
jQuery.post('/d/nakupovanje-api/create_narocilo', podatki).done(function (val) {
val = JSON.parse(val);
if (val.error) {
@ -1273,7 +1289,8 @@ function posodobiCenoPaketa() {
var trajanje = jQuery('[name="trajanje"]:checked').val();
jQuery.post('/frontend/payments/api.php?action=get_paketi').done(function (val) {
jQuery.post('/d/nakupovanje-api/get_paketi').done(function (val) {
val = JSON.parse(val);
var cenaIzpisGledeNaDDV = '';
@ -1298,7 +1315,7 @@ function posodobiCenoPaketa() {
// Preverimo, če ima kak popust od prej
jQuery('.podatki-za-placilo-racuna').show();
jQuery.post('/frontend/payments/api.php?action=get_active_subscription', {
jQuery.post('/d/nakupovanje-api/get_active_subscription', {
'package_id': paket,
'trajanje': trajanje,
'email': jQuery('#narocilo-paketa-podatki #f-email').val(),

File diff suppressed because it is too large Load Diff

View File

@ -24,11 +24,11 @@ class ApiNarocilaController{
// Preverimo, ce je klic ok (token)
//if($this->checkToken()){
if($this->checkToken()){
// Izvedemo akcijo
$this->executeAction();
//}
}
// Logiramo response klica
@ -75,7 +75,6 @@ class ApiNarocilaController{
}
private function checkToken(){
$raw_post_data = '';
if($this->method == 'POST' && $this->data){
@ -83,16 +82,19 @@ class ApiNarocilaController{
}
// Dobimo request (brez id in token)
$request = ($_SERVER["HTTPS"] == 'on') ? 'https://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] : 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$request_url = ($_SERVER["HTTPS"] == 'on') ? 'https://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] : 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
if(!isset($_SERVER['HTTP_IDENTIFIER']))
$request = preg_replace('/([?&])identifier=[^&]+(&|$)/', '$1', $request);
$request_url = preg_replace('/([?&])identifier=[^&]+(&|$)/', '$1', $request_url);
if(!isset($_SERVER['HTTP_TOKEN']))
$request = preg_replace('/([?&])token=[^&]+(&|$)/', '$1', $request);
$request_url = preg_replace('/([?&])token=[^&]+(&|$)/', '$1', $request_url);
if(!isset($_SERVER['HTTP_TOKEN']) || !isset($_SERVER['HTTP_IDENTIFIER']))
$request = substr($request, 0, -1);
$request_url = substr($request_url, 0, -1);
// Na nasi strani naredimo hmac podatkov z ustreznim private key-em
$data = $this->method . $request . $raw_post_data;
$data = $this->method . $request_url . $raw_post_data;
$token = hash_hmac('sha256', $data, $this->private_key);
if($this->params['token'] == $token)