Narejen paypal paypalCreateOrder in paypalCaptureOrder

This commit is contained in:
pero1203 2020-09-09 11:22:20 +02:00
parent 192d97bcee
commit 4f9bb1b658
7 changed files with 304 additions and 54 deletions

View File

@ -19,7 +19,8 @@
"phpmailer/phpmailer": "~6.0", "phpmailer/phpmailer": "~6.0",
"minishlink/web-push": "^5.2", "minishlink/web-push": "^5.2",
"stripe/stripe-php": "^7.40", "stripe/stripe-php": "^7.40",
"geoip2/geoip2": "~2.0" "geoip2/geoip2": "~2.0",
"paypal/paypal-checkout-sdk": "^1.0"
}, },
"require-dev": { "require-dev": {
"kint-php/kint": "^1.1", "kint-php/kint": "^1.1",

123
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "f48f2e76d23925213a1c248388654ed4", "hash": "c9fc655cdb58743c38114c03e68c1cc7",
"content-hash": "4faadcc7d5b72636e2d9ac9a18b062a2", "content-hash": "a150435d7f20bef4fdda8cb6c59eb1a6",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
@ -663,6 +663,95 @@
], ],
"time": "2020-03-20 21:48:09" "time": "2020-03-20 21:48:09"
}, },
{
"name": "paypal/paypal-checkout-sdk",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/paypal/Checkout-PHP-SDK.git",
"reference": "ed6a55075448308b87a8b59dcb7fedf04a048cb1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paypal/Checkout-PHP-SDK/zipball/ed6a55075448308b87a8b59dcb7fedf04a048cb1",
"reference": "ed6a55075448308b87a8b59dcb7fedf04a048cb1",
"shasum": ""
},
"require": {
"paypal/paypalhttp": "1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
},
"type": "library",
"autoload": {
"psr-4": {
"PayPalCheckoutSdk\\": "lib/PayPalCheckoutSdk",
"Sample\\": "samples/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"https://github.com/paypal/Checkout-PHP-SDK/blob/master/LICENSE"
],
"authors": [
{
"name": "PayPal",
"homepage": "https://github.com/paypal/Checkout-PHP-SDK/contributors"
}
],
"description": "PayPal's PHP SDK for Checkout REST APIs",
"homepage": "http://github.com/paypal/Checkout-PHP-SDK/",
"keywords": [
"checkout",
"orders",
"payments",
"paypal",
"rest",
"sdk"
],
"time": "2019-11-07 23:16:44"
},
{
"name": "paypal/paypalhttp",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/paypal/paypalhttp_php.git",
"reference": "1ad9b846a046f09d6135cbf2cbaa7701bbc630a3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paypal/paypalhttp_php/zipball/1ad9b846a046f09d6135cbf2cbaa7701bbc630a3",
"reference": "1ad9b846a046f09d6135cbf2cbaa7701bbc630a3",
"shasum": ""
},
"require": {
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"wiremock-php/wiremock-php": "1.43.2"
},
"type": "library",
"autoload": {
"psr-4": {
"PayPalHttp\\": "lib/PayPalHttp"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PayPal",
"homepage": "https://github.com/paypal/paypalhttp_php/contributors"
}
],
"abandoned": true,
"time": "2019-11-06 21:27:12"
},
{ {
"name": "phpmailer/phpmailer", "name": "phpmailer/phpmailer",
"version": "v6.1.7", "version": "v6.1.7",
@ -874,16 +963,16 @@
}, },
{ {
"name": "spomky-labs/base64url", "name": "spomky-labs/base64url",
"version": "v2.0.2", "version": "v2.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Spomky-Labs/base64url.git", "url": "https://github.com/Spomky-Labs/base64url.git",
"reference": "69e77e7d7c5407a253dacdd7bfe6b8978b7a4fb2" "reference": "48ea8ff600cefe56b82d3d5b768b6f4f3bfe05a1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Spomky-Labs/base64url/zipball/69e77e7d7c5407a253dacdd7bfe6b8978b7a4fb2", "url": "https://api.github.com/repos/Spomky-Labs/base64url/zipball/48ea8ff600cefe56b82d3d5b768b6f4f3bfe05a1",
"reference": "69e77e7d7c5407a253dacdd7bfe6b8978b7a4fb2", "reference": "48ea8ff600cefe56b82d3d5b768b6f4f3bfe05a1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -922,20 +1011,20 @@
"safe", "safe",
"url" "url"
], ],
"time": "2020-08-01 14:15:43" "time": "2020-08-30 13:35:33"
}, },
{ {
"name": "stripe/stripe-php", "name": "stripe/stripe-php",
"version": "v7.49.0", "version": "v7.52.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/stripe/stripe-php.git", "url": "https://github.com/stripe/stripe-php.git",
"reference": "db6229bff448f7f3bf7f6aee112d5d9ba34ca4ba" "reference": "51e95c514aff45616dff09791ca5b2f10cf5c4e8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/stripe/stripe-php/zipball/db6229bff448f7f3bf7f6aee112d5d9ba34ca4ba", "url": "https://api.github.com/repos/stripe/stripe-php/zipball/51e95c514aff45616dff09791ca5b2f10cf5c4e8",
"reference": "db6229bff448f7f3bf7f6aee112d5d9ba34ca4ba", "reference": "51e95c514aff45616dff09791ca5b2f10cf5c4e8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -979,7 +1068,7 @@
"payment processing", "payment processing",
"stripe" "stripe"
], ],
"time": "2020-08-19 22:48:20" "time": "2020-09-08 19:29:20"
}, },
{ {
"name": "symfony/polyfill-intl-idn", "name": "symfony/polyfill-intl-idn",
@ -2230,16 +2319,16 @@
}, },
{ {
"name": "symfony/var-dumper", "name": "symfony/var-dumper",
"version": "v4.4.11", "version": "v4.4.13",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/var-dumper.git", "url": "https://github.com/symfony/var-dumper.git",
"reference": "2125805a1a4e57f2340bc566c3013ca94d2722dc" "reference": "1bef32329f3166486ab7cb88599cae4875632b99"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/2125805a1a4e57f2340bc566c3013ca94d2722dc", "url": "https://api.github.com/repos/symfony/var-dumper/zipball/1bef32329f3166486ab7cb88599cae4875632b99",
"reference": "2125805a1a4e57f2340bc566c3013ca94d2722dc", "reference": "1bef32329f3166486ab7cb88599cae4875632b99",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2303,7 +2392,7 @@
"debug", "debug",
"dump" "dump"
], ],
"time": "2020-06-24 13:34:53" "time": "2020-08-17 07:31:35"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -76,6 +76,7 @@ class ApiNarocilaController{
return true; return true;
else{ else{
$this->response['error'] = 'Napaka! Napačen token.'; $this->response['error'] = 'Napaka! Napačen token.';
$this->response['success'] = false;
return false; return false;
} }
@ -88,6 +89,7 @@ class ApiNarocilaController{
if (!isset($this->params['action'])) { if (!isset($this->params['action'])) {
$this->response['error'] = 'Napaka! Manjkajo parametri!'; $this->response['error'] = 'Napaka! Manjkajo parametri!';
$this->response['success'] = false;
} }
else { else {
@ -122,6 +124,7 @@ class ApiNarocilaController{
} }
else{ else{
$this->response['error'] = 'Napaka! Manjka ID narocila!'; $this->response['error'] = 'Napaka! Manjka ID narocila!';
$this->response['success'] = false;
} }
break; break;
@ -135,6 +138,7 @@ class ApiNarocilaController{
} }
else{ else{
$this->response['error'] = 'Napaka! Manjka ID narocila!'; $this->response['error'] = 'Napaka! Manjka ID narocila!';
$this->response['success'] = false;
} }
break; break;
@ -208,6 +212,8 @@ class ApiNarocilaController{
if($usr_id == '' || $usr_id == 0){ if($usr_id == '' || $usr_id == 0){
$this->response['error'] = 'ERROR! Missing user ID.'; $this->response['error'] = 'ERROR! Missing user ID.';
$this->response['success'] = false;
break; break;
} }
@ -223,6 +229,20 @@ class ApiNarocilaController{
$this->response = $price; $this->response = $price;
break; break;
// Preveri, ce je narocilo placano preko paypala
case 'check_narocilo_paypal':
if(isset($this->data['narocilo_id'])){
$paypal = new UserNarocilaPaypal($this->data['narocilo_id']);
$this->response = $narocilo->paypalCaptureOrder();
}
else{
$this->response['error'] = 'Napaka! Manjka ID narocila!';
$this->response['success'] = false;
}
break;
} }
} }
} }

View File

@ -647,6 +647,8 @@ class UserNarocila{
if($usr_id <= 0){ if($usr_id <= 0){
$response['error'] = 'ERROR! Missing user ID.'; $response['error'] = 'ERROR! Missing user ID.';
$response['success'] = false;
return $response; return $response;
} }
@ -684,6 +686,8 @@ class UserNarocila{
"); ");
if (!$sqlNarocilo){ if (!$sqlNarocilo){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
@ -713,7 +717,6 @@ class UserNarocila{
} }
return $response; return $response;
} }
@ -753,6 +756,8 @@ class UserNarocila{
} }
catch (Exception $e){ catch (Exception $e){
$response['error'] = 'ERROR! Sending email with invoice failed.'; $response['error'] = 'ERROR! Sending email with invoice failed.';
$response['success'] = false;
return $response; return $response;
} }
@ -768,6 +773,8 @@ class UserNarocila{
$token = isset($narocilo_data['stripe_id']) ? $narocilo_data['stripe_id'] : ''; $token = isset($narocilo_data['stripe_id']) ? $narocilo_data['stripe_id'] : '';
if($token == ''){ if($token == ''){
$response['error'] = 'ERROR! Missing token.'; $response['error'] = 'ERROR! Missing token.';
$response['success'] = false;
return $response; return $response;
} }
@ -789,10 +796,12 @@ class UserNarocila{
} }
else{ else{
$response['error'] = $payment_response['error']; $response['error'] = $payment_response['error'];
$response['success'] = false;
} }
} }
else{ else{
$response['error'] = $stripe_response['error']; $response['error'] = $stripe_response['error'];
$response['success'] = false;
} }
$response['narocilo_id'] = $narocilo_id; $response['narocilo_id'] = $narocilo_id;
@ -814,11 +823,12 @@ class UserNarocila{
// Ce je bilo placilo preko stripa uspesno zgeneriramo racun in uporabniku aktiviramo paket // Ce je bilo placilo preko stripa uspesno zgeneriramo racun in uporabniku aktiviramo paket
if($paypal_response['success'] == true){ if($paypal_response['success'] == true){
$response['paypal_url'] = $paypal_response['paypal_url']; $response['paypal_link'] = $paypal_response['paypal_link'];
$response['success'] = true; $response['success'] = true;
} }
else{ else{
$response['error'] = $paypal_response['error']; $response['error'] = $paypal_response['error'];
$response['success'] = false;
} }
return $response; return $response;
@ -826,7 +836,7 @@ class UserNarocila{
// Posodobi obstojece narocilo za uporabnika - ZA TESTIRATI // Posodobi obstojece narocilo za uporabnika
public function updateNarocilo($narocilo_data){ public function updateNarocilo($narocilo_data){
global $global_user_id; global $global_user_id;
@ -835,6 +845,7 @@ class UserNarocila{
// ce nimamo id-ja narocila vrnemo error // ce nimamo id-ja narocila vrnemo error
if(!isset($narocilo_data['narocilo_id']) || $narocilo_data['narocilo_id'] == '0'){ if(!isset($narocilo_data['narocilo_id']) || $narocilo_data['narocilo_id'] == '0'){
$response['error'] = 'Napaka! Manjka ID narocila!'; $response['error'] = 'Napaka! Manjka ID narocila!';
$response['success'] = false;
return $response; return $response;
} }
@ -864,6 +875,8 @@ class UserNarocila{
$sqlNarocilo = sisplet_query("UPDATE user_access_narocilo SET ".$update.", cebelica_id_racun='0', cebelica_id_predracun='0' WHERE id='".$narocilo_data['narocilo_id']."'"); $sqlNarocilo = sisplet_query("UPDATE user_access_narocilo SET ".$update.", cebelica_id_racun='0', cebelica_id_predracun='0' WHERE id='".$narocilo_data['narocilo_id']."'");
if (!$sqlNarocilo){ if (!$sqlNarocilo){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
@ -882,6 +895,7 @@ class UserNarocila{
// Ce nimamo id-ja narocila vrnemo error // Ce nimamo id-ja narocila vrnemo error
if($narocilo_id == 0){ if($narocilo_id == 0){
$response['error'] = 'Napaka! Manjka ID narocila!'; $response['error'] = 'Napaka! Manjka ID narocila!';
$response['success'] = false;
return $response; return $response;
} }
@ -894,6 +908,7 @@ class UserNarocila{
// Ce je bil racun ze placan ne naredimo nicesar // Ce je bil racun ze placan ne naredimo nicesar
if($rowNarocilo['status'] == 1){ if($rowNarocilo['status'] == 1){
$response['error'] = 'Napaka! Račun je že plačan!'; $response['error'] = 'Napaka! Račun je že plačan!';
$response['success'] = false;
return $response; return $response;
} }
@ -924,6 +939,8 @@ class UserNarocila{
"); ");
if (!$sqlAccess){ if (!$sqlAccess){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
} }
@ -932,6 +949,8 @@ class UserNarocila{
$sqlAccess = sisplet_query("UPDATE user_access SET time_expire = time_expire + INTERVAL '".$rowNarocilo['trajanje']."' MONTH WHERE usr_id='".$rowNarocilo['usr_id']."'"); $sqlAccess = sisplet_query("UPDATE user_access SET time_expire = time_expire + INTERVAL '".$rowNarocilo['trajanje']."' MONTH WHERE usr_id='".$rowNarocilo['usr_id']."'");
if (!$sqlAccess){ if (!$sqlAccess){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
} }
@ -948,6 +967,8 @@ class UserNarocila{
"); ");
if (!$sqlAccess){ if (!$sqlAccess){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
} }
@ -957,6 +978,8 @@ class UserNarocila{
$sqlNarociloStatus = sisplet_query("UPDATE user_access_narocilo SET status='1' WHERE id='".$narocilo_id."'"); $sqlNarociloStatus = sisplet_query("UPDATE user_access_narocilo SET status='1' WHERE id='".$narocilo_id."'");
if (!$sqlNarociloStatus){ if (!$sqlNarociloStatus){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }

View File

@ -7,14 +7,23 @@
*/ */
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
class UserNarocilaPaypal{ class UserNarocilaPaypal{
private $narocilo; private $narocilo;
private $paypal_client;
public function __construct($narocilo_id){ public function __construct($narocilo_id){
global $app_settings; global $app_settings;
global $paypal_client_id;
global $paypal_secret;
if($narocilo_id > 0){ if($narocilo_id > 0){
@ -28,6 +37,10 @@ class UserNarocilaPaypal{
else{ else{
die("Napaka pri komunikaciji s paypal! Narocilo ne obstaja."); die("Napaka pri komunikaciji s paypal! Narocilo ne obstaja.");
} }
// Ustvarimo okolje za paypal
$environment = new SandboxEnvironment($paypal_client_id, $paypal_secret);
$this->paypal_client = new PayPalHttpClient($environment);
} }
else { else {
die("Napaka pri komunikaciji s paypal! Manjka ID naročila."); die("Napaka pri komunikaciji s paypal! Manjka ID naročila.");
@ -37,11 +50,10 @@ class UserNarocilaPaypal{
// Placamo narocilo s paypal // Placamo narocilo s paypal
public function paypalCreatePayment(){ public function paypalCreatePayment(){
global $paypal_account;
global $paypal_client_id;
global $paypal_secret;
global $site_url; global $site_url;
$response = array();
$UA = new UserNarocila(); $UA = new UserNarocila();
$cena = $UA->getPrice($this->narocilo['package_name'], $this->narocilo['trajanje'], $this->narocilo['discount']); $cena = $UA->getPrice($this->narocilo['package_name'], $this->narocilo['trajanje'], $this->narocilo['discount']);
@ -67,60 +79,161 @@ class UserNarocilaPaypal{
} }
// Podatki za paypal potrebni za placilo // Podatki narocila
$orderDetails = array( $orderDetails = array(
'business' => $paypal_client_id, 'ime' => '1KA naročnina (paket '.strtoupper($this->narocilo['package_name']). ' - '.$this->narocilo['trajanje'].' '.$months_string.')',
'narocilo_id' => $this->narocilo['id'],
'item_name' => '1KA naročnina (paket '.strtoupper($this->narocilo['package_name']). ' - '.$this->narocilo['trajanje'].' '.$months_string.')', 'cena' => $cena_za_placilo,
'item_number' => $this->narocilo['id'],
'amount' => $cena_za_placilo * 100,
'currency_code' => 'EUR',
'return' => $site_url.'frontend/payments/paypal-pay.php',
'cancel_return' => $site_url.'frontend/payments/paypal-cancel.php',
'cmd' => '_xclick'
); );
// Posljemo placilo na paypal, da se lahko potem user prijavi in ga placa // Ustvarimo order na paypal, da se lahko potem user prijavi in ga placa
$paypalResponse = $this->paypalCreatePaymentSend($orderDetails); $paypal_response = $this->paypalCreateOrder($orderDetails);
if(!isset($paypal_response['success']) || $paypal_response['success'] == false){
return $paypal_response;
}
// Vstavimo plačilo v bazo // Vstavimo plačilo v bazo
$sqlNarocilo = sisplet_query("INSERT INTO user_access_paypal_transaction $sqlNarocilo = sisplet_query("INSERT INTO user_access_paypal_transaction
(transaction_id, narocilo_id, price, currency_type, time) (transaction_id, narocilo_id, price, currency_type, time)
VALUES VALUES
('".$paypalResponse['transaction_id']."', '".$paypalResponse['narocilo_id']."', '".$paypalResponse['price']."', '".$paypalResponse['currency_type']."',NOW()) ('".$paypal_response['transaction_id']."', '".$this->narocilo['id']."', '".$cena_za_placilo."', 'EUR', NOW())
"); ");
if (!$sqlNarocilo){ if (!$sqlNarocilo){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
$response = array(); $response['paypal_link'] = $paypal_response['paypal_link'];
$response['success'] = true;
return $response; return $response;
} }
// Posljemo podatke za placilo paypalu
// Posljemo podatke za placilo paypalu - TODO private function paypalCreateOrder($orderDetails){
private function paypalCreatePaymentSend(){ global $site_url;
global $paypal_account;
global $paypal_client_id;
global $paypal_secret;
$response = array(); $response = array();
$paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; $request = new OrdersCreateRequest();
/* $request->prefer('return=representation');
$response['transaction_id'] = $_GET['tx']; //$request->headers["prefer"] = "return=representation";
$response['narocilo_id'] = $_GET['item_number'];
$response['price'] = $_GET['amt']; $request->body = [
$response['currency_type'] = $_GET['cc']; "intent" => "CAPTURE",
*/ "purchase_units" => [[
"reference_id" => $orderDetails['narocilo_id'],
"amount" => [
"value" => $orderDetails['cena'],
"currency_code" => "EUR"
]
]],
"application_context" => [
"cancel_url" => $site_url . '/d/narocilo/paypal-cancel',
"return_url" => $site_url . '/d/narocilo/paypal'
]
];
try {
// Poklicemo paypal api za ustvarjanje narocila
$paypal_response = $client->execute($request);
if($paypal_response->result->status != 'CREATED'){
$response['error'] = 'ERROR! Order was not created.';
$response['success'] = false;
return $response;
}
// Dobimo id paypal narocila
$response['transaction_id'] = $paypal_response->result->id;
// Dobimo link za preusmeritev stranke, da potrdi narocilo in potem lahko izvedemo "capture"
foreach($paypal_response->result->links as $link){
if($link->rel == 'capture')
$response['paypal_link'] = $link->href;
}
}
catch (HttpException $e) {
$response['error'] = $e->getMessage();
return $response;
}
$response['success'] = true;
return $response;
}
// Zakljucimo placilo, ce je bilo placilo ok odobreno preko paypala s strani stranke
public function paypalCaptureOrder(){
$response = array();
// Preverimo plačilo v bazo
$sqlNarociloPaypal = sisplet_query("SELECT transaction_id
FROM user_access_paypal_transaction
WHERE narocilo_id='".$this->narocilo['id']."'
");
if (!$sqlNarociloPaypal){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response;
}
// Narocilo ne obstaja (ni v bazi paypal narocil)
if (mysqli_num_rows($sqlNarociloPaypal) == 0){
$response['error'] = 'ERROR! Paypal order does not exist.';
$response['success'] = false;
return $response;
}
$rowNarociloPaypal = mysqli_fetch_array($sqlNarociloPaypal);
// Preverimo, ce je bilo vse ok placano - POST request to /v2/checkout/orders
$request = new OrdersCaptureRequest($rowNarociloPaypal['transaction_id']);
//$request->prefer('return=representation');
try {
// Poklicemo paypal api kjer preverimo placilo narocila
$paypal_response = $client->execute($request);
}
catch (HttpException $e) {
$response['error'] = $e->getMessage();
$response['success'] = false;
return $response;
}
// Posodobimo status narocila
$sqlNarocilo = sisplet_query("UPDATE user_access_paypal_transaction
SET status='".$paypal_response->result->status."'
WHERE transaction_id='".$paypal_response->result->id."'
");
if (!$sqlNarocilo){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response;
}
$response['status'] = $paypal_response->result->status;
$response['success'] = true;
return $response; return $response;
} }
} }

View File

@ -100,6 +100,8 @@ class UserNarocilaStripe{
"); ");
if (!$sqlNarocilo){ if (!$sqlNarocilo){
$response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']); $response['error'] = 'ERROR! '.mysqli_error($GLOBALS['connect_db']);
$response['success'] = false;
return $response; return $response;
} }
$response = array(); $response = array();
@ -118,6 +120,7 @@ class UserNarocilaStripe{
// Placilo ni uspelo // Placilo ni uspelo
else{ else{
$response['error'] = 'ERROR! Stripe payment failed. Failure code '.$stripeResponse['failure_code']; $response['error'] = 'ERROR! Stripe payment failed. Failure code '.$stripeResponse['failure_code'];
$response['success'] = false;
} }
return $response; return $response;

View File

@ -9291,6 +9291,7 @@ CREATE TABLE user_access_paypal_transaction(
price DECIMAL(7,2) NOT NULL DEFAULT '0', price DECIMAL(7,2) NOT NULL DEFAULT '0',
currency_type VARCHAR(100) NOT NULL DEFAULT '', currency_type VARCHAR(100) NOT NULL DEFAULT '',
time DATETIME(3) NOT NULL, time DATETIME(3) NOT NULL,
status VARCHAR(30) NOT NULL DEFAULT '',
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY (transaction_id) UNIQUE KEY (transaction_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;