Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2.  
  3. require_once '/home/hat3tank/public_html/users/init.php';
  4.  
  5. $db = DB::getInstance();
  6. $user_id = $user->data()->id;
  7.  
  8. use PayPal\Api\Payment;
  9. use PayPal\Api\PaymentExecution;
  10.  
  11. require 'app/start.php';
  12.  
  13. if(isset($_GET['success'])) {
  14.    
  15.     $approved = $_GET['success'] === 'true';
  16.    
  17.     if($approved) {
  18.        
  19.         $payerId = $_GET['PayerID'];
  20.        
  21.         //Get the payment_id from database
  22.         $paymentId = $db->get('transactions_paypal',['hash','=',$_SESSION['paypal_hash']]);
  23.        
  24.         $paymentId = $paymentId->first()->payment_id;
  25.          
  26.        
  27.         //Get the paypal payment
  28.         $payment = Payment::get($paymentId, $paypal);
  29.        
  30.         $execution = new PaymentExecution();
  31.         $execution->setPayerId($payerId);
  32.        
  33.        
  34.         //Execute Paypal Payment
  35.         $payment->execute($execution, $paypal);
  36.        
  37.  
  38.         $fields = array (
  39.           'user_id'        => $user_id,
  40.           'permission_id'  => 4
  41.         );
  42.        
  43.         //update the logged in user's account info
  44.         $db->insert('user_permission_matches',$fields);
  45.        
  46. //        //UNset PayPal hasg
  47. //        unset($_SESSION['paypal_hash']);
  48.        
  49.         //Redirect user to success page, alter these to take you your own redirect.
  50.        
  51.         header('Location: payment_success.php');
  52.        
  53.     } else {
  54.        
  55.         header('Location: payment_cancelled.php');
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement