<?php
/**
 * Created by PhpStorm.
 * User: varun_2
 * Date: 31-01-2016
 * Time: 21:33
 */

namespace App\Http\Controllers\Action;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Sale;
use PayPal\Api\Payment ;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential ;

class PaypalValidator
{

    private $_api_context;

    public function __construct()
    {
        // setup PayPal api context\
        $paypal_conf = \Config::get('paypal');
        $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
        $this->_api_context->setConfig($paypal_conf['settings']);
    }

    public function verifyPayment( $payment_id )
    {
        $sale = null ;
        try
        {
            $pay = Payment::get( $payment_id , $this->_api_context ) ;
//            $execute = new PaymentExecution();
//            $sale = Sale::get($payment_id , $this->_api_context);
            return $pay ;
        } catch (Exception $ex) {
            return false ;
        }
    }
}