Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'PayPal-PHP-SDK/autoload.php';
- require '../../../config-and-databases.php';
- require '../../class.smtp.php';
- require '../../class.phpmailer.php';
- require '../../configfile.php';
- require '../check.php';
- require '../validate.php';
- $apiContext = new \PayPal\Rest\ApiContext(
- new \PayPal\Auth\OAuthTokenCredential($paypal_ClientID,$paypal_ClientSecret)
- );
- if(isset($paypal_mode) && $paypal_mode=='live')
- $apiContext->setConfig(
- array(
- 'mode' => 'live',
- )
- );
- use PayPal\Api\Amount;
- use PayPal\Api\Details;
- use PayPal\Api\Payment;
- use PayPal\Api\PaymentExecution;
- use PayPal\Api\Transaction;
- use PayPal\Rest\ApiContext;
- use PayPal\Api\Authorization;
- use PayPal\Api\Capture;
- if (!isset($_GET['success']))
- exit;
- if (!isset($_GET['paymentId']))
- exit;
- if (!isset($_GET['PayerID']))
- exit;
- if (!isset($_GET['token']))
- exit;
- if ($_GET['success']!='false' && $_GET['success']!='true')
- exit;
- $paymentId = $_GET['paymentId'];
- $token = $_GET['token'];
- $PayerID = $_GET['PayerID'];
- if($filecurs=fopen('paiments.log', 'a'))
- {}
- else
- die('Unable to write or create the file: '.$file);
- function filewritestream($content)
- {
- global $filecurs;
- if(fwrite($filecurs,$content) === false)
- die('Unable to write the file: '.$file);
- }
- $debug=true;
- $actioninerror=array();
- if($debug)
- {
- filewritestream(json_encode($_POST));
- filewritestream(json_encode($_SERVER));
- }
- $data2 = '[{"details":"VPS2016 Basic: 12 Month","price":948,"quantity":"1","drop":[]},{"details":" - Backup: 12 Month","price":588,"quantity":"1"},{"details":" - Backup remote: 12 Month","price":588,"quantity":"1"}]';
- if (isset($_GET['success']) && $_GET['success'] == 'true') {
- //load the base info
- $reply = pg_query_params($postgres_link,'SELECT id,actiononpayment,customer,details FROM invoice WHERE paymentmethod=$1 AND paymentcode=$2',array('paypal',$token)) or die(pg_last_error());
- $data = pg_fetch_array($reply);
- $productslist=json_decode($data['details'],true);
- /*cho '<pre>';
- echo print_r($productslist);
- echo '</pre>';*/
- $internaltotal=0;
- if($productslist!==NULL)
- foreach($productslist as $product)
- if(isset($product['details']) && isset($product['price']) && isset($product['quantity']))
- $internaltotal+=$product['price']*$product['quantity'];
- //insert into database
- $payment = Payment::get($paymentId, $apiContext);
- $execution = new PaymentExecution();
- $execution->setPayerId($PayerID);
- try {
- $result = $payment->execute($execution, $apiContext);
- echo '<pre>';
- var_dump($result);
- var_dump($result->state);
- echo '</pre>';
- filewritestream($result);
- //Capture the payment
- $arrayAuth = array("Executed Payment" => array("Payment id" => $payment->getId(), "Execution" => $execution, "Result" => $result));
- $payment = Payment::get($paymentId, $apiContext);
- $arrayAuth["Payment"] = $payment;
- $arrayAuth["Exito"] = "";
- $authorization = Authorization::get($paymentId, $apiContext);
- $amt = new Amount();
- //Cause 1$ test2
- $amt->setCurrency("USD")->setTotal(1);
- //$amt->setCurrency("USD")->setTotal($internaltotal);
- echo "<b style='color:green; font-size:25px;'>Transaccion realizada con exito<br></b>";
- $capture = new Capture();
- $capture->setAmount($amt);
- $getCapture = $authorization->capture($capture, $apiContext);
- //do the internal code
- if($data['actiononpayment']!='')
- {
- $actions=json_decode($data['actiononpayment'],true);
- if(paimentActionIsValid($actions,$data))
- {
- $returnCode=paimentValidate($actions,$data);
- pg_query_params($postgres_link,'UPDATE invoice SET paymentstat=$1 WHERE id=$2',array($returnCode,$transactionId)) or die(pg_last_error());
- if($returnCode!=1)
- {
- filewritestream(json_encode($_POST)."\n");
- filewritestream('paiment problem at apply: '.$transactionId."\n");
- }
- else if($debug)
- filewritestream('paiment ok: '.$transactionId.' '.$data['actiononpayment']."\n");
- if(count($actioninerror)>0)
- {
- $mail->addAddress($admin_email);
- $mail->Subject = 'For the invoice: '.$data['id'].' is unable to understand';
- $mail->Body = 'For the invoice: '.$data['id'].' is unable to understand: '.implode(',',array_keys($actioninerror));
- if (!$mail->send())
- echo 'Mailer error: '.$mail->ErrorInfo."\n";
- else
- echo 'Mail send'."\n";
- }
- foreach($vps_regenconfig_and_restart as $vpsid=>$falsevalue)
- {
- $reply = pg_query_params($postgres_link,'SELECT host FROM vps WHERE id=$1',array($vpsid)) or die(pg_last_error());
- if($data = pg_fetch_array($reply))
- {
- $file = fopen('/tmp/lock-vps-'.$vpsid,"w+");
- if(!flock($file,LOCK_EX|LOCK_NB))
- {
- fclose($file);
- echo 'Action already in progress for vps '.$vpsid."\n";
- }
- else
- {
- if(!setconfigfile($vpsid))
- {
- filewritestream('set config file wrong:'.$vpsid."\n");
- flock($file,LOCK_UN);
- fclose($file);
- echo 'Erro to set config file for vps '.$vpsid."\n";
- }
- $replyhardware = pg_query_params($postgres_link,'SELECT host FROM hardware WHERE id=$1',array($data['host'])) or die(pg_last_error());
- if($datahardware = pg_fetch_array($replyhardware))
- {
- filewritestream('restart try: '.$vpsid."\n");
- exec($restart_command.' '.$vpsid.' '.$datahardware['host'],$output,$returncode);
- if($returncode!=0)
- echo implode("\n",$output);
- }
- else
- filewritestream('restart wrong:'.$vpsid."\n");
- fclose($file);
- }
- }
- else
- filewritestream('vps not found:'.$vpsid."\n");
- }
- }
- else
- filewritestream('paimentActionIsValid:'.json_encode($actioninerror)."\n".$data['actiononpayment']."\n");
- }
- } catch (PayPal\Exception\PayPalConnectionException $ex) {
- echo "<b style='color:red; font-size:25px;'>Error Vago<br>
- Message: " . $ex->getCode() . "</b>";
- echo $ex->getData();
- echo $ex->getMessage();
- echo '<pre>';
- echo print_r($ex->getTrace());
- echo '</pre>';
- }
- } else {
- echo ("<b style='color:green; font-size:25px;'>User Cancelled the Approval</b>");
- }
- fclose($filecurs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement