update paypal payment
This commit is contained in:
@@ -18,6 +18,7 @@ use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
// use Mail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PayPal\Exception\PayPalConnectionException;
|
||||
|
||||
|
||||
class PaypalController extends Controller
|
||||
@@ -28,11 +29,10 @@ class PaypalController extends Controller
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$paypal_env = "live";
|
||||
$paypal_env = "sandbox";
|
||||
$paypal_apiUrl = 'https://api.paypal.com'; // default
|
||||
|
||||
if($paypal_env == 'live'){
|
||||
|
||||
$paypal_apiUrl = 'https://api.paypal.com';
|
||||
}else{
|
||||
$paypal_apiUrl = 'https://api.sandbox.paypal.com';
|
||||
@@ -97,7 +97,14 @@ class PaypalController extends Controller
|
||||
$m = new TeamStoreModel;
|
||||
$paypal_model = new PayPalModel;
|
||||
$last_id = $paypal_model->getLastIdPaymentDetails();
|
||||
$invoice_num = str_pad($last_id[0]->Id, 4, '0', STR_PAD_LEFT);
|
||||
// var_dump(count($last_id));
|
||||
if(count($last_id) > 0){
|
||||
$lastId = $last_id[0]->Id + 1;
|
||||
}else{
|
||||
$lastId = 1;
|
||||
}
|
||||
$invoice_num = str_pad($lastId, 6, '0', STR_PAD_LEFT);
|
||||
// var_dump($invoice_num);
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
|
||||
$items = $m->myCart($cartKey);
|
||||
@@ -252,13 +259,23 @@ class PaypalController extends Controller
|
||||
$token = $request->get('token');
|
||||
$payer_id = $request->get('PayerID');
|
||||
|
||||
try {
|
||||
$payment = PayPal::getById($id, $this->_apiContext);
|
||||
|
||||
$payment = PayPal::getById($id, $this->_apiContext);
|
||||
$paymentExecution = PayPal::PaymentExecution();
|
||||
|
||||
$paymentExecution = PayPal::PaymentExecution();
|
||||
$paymentExecution->setPayerId($payer_id);
|
||||
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
|
||||
$obj = json_decode($executePayment);
|
||||
|
||||
} catch (PayPalConnectionException $e) {
|
||||
//throw $th;
|
||||
// echo $e->getCode();
|
||||
echo $e->getData();
|
||||
Session::put('cartkeyError','Invalid payment.');
|
||||
return Redirect::route('cart');
|
||||
}
|
||||
|
||||
$paymentExecution->setPayerId($payer_id);
|
||||
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
|
||||
|
||||
// print_r($executePayment);
|
||||
// if ($executePayment->getState() == 'approved') {
|
||||
@@ -270,7 +287,7 @@ class PaypalController extends Controller
|
||||
// // return Redirect::route('paywithpaypal');
|
||||
// echo 'Payment success';
|
||||
// }
|
||||
$obj = json_decode($executePayment);
|
||||
|
||||
|
||||
|
||||
$line2 = null;
|
||||
|
||||
@@ -40,11 +40,16 @@
|
||||
<div class="col-lg-12">
|
||||
<h3>Shopping Cart</h3>
|
||||
@if(Session::has('cartkeyError'))
|
||||
<div class="alert alert-danger alert-dismissible">
|
||||
{{-- <div class="alert alert-danger alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h4><i class="fa fa-exclamation-circle"></i> Error:</h4>
|
||||
{!! Session::get('cartkeyError') !!}
|
||||
</div>
|
||||
</div> --}}
|
||||
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<strong>Error!</strong> {!! Session::get('cartkeyError') !!}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user