updated paypal
This commit is contained in:
@@ -30,7 +30,7 @@ class PaypalController extends Controller
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$paypal_env = "live";
|
||||
$paypal_env = "sandbox";
|
||||
$paypal_apiUrl = 'https://api.paypal.com'; // default
|
||||
|
||||
if ($paypal_env == 'live') {
|
||||
@@ -392,6 +392,22 @@ class PaypalController extends Controller
|
||||
|
||||
public function getDone(Request $request)
|
||||
{
|
||||
|
||||
$paypal_model = new PayPalModel;
|
||||
$m = new TeamStoreModel;
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
$userId = Auth::user()->id;
|
||||
$user_email = Auth::user()->email;
|
||||
|
||||
|
||||
$checkCartKey = $paypal_model->checkCartKey($cartKey);
|
||||
|
||||
if(count($checkCartKey) > 0) {
|
||||
$message = 'You already paid for this order. Please check your Order Page. <a href="user/orders"> <strong> <u>click here</u> </strong></a>.';
|
||||
Session::put('cartkeyError', $message);
|
||||
return Redirect::route('cart');
|
||||
}
|
||||
|
||||
$id = $request->get('paymentId');
|
||||
$token = $request->get('token');
|
||||
$payer_id = $request->get('PayerID');
|
||||
@@ -405,29 +421,14 @@ class PaypalController extends Controller
|
||||
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
|
||||
$obj = json_decode($executePayment);
|
||||
// var_dump($obj);
|
||||
} catch (PayPalConnectionException $e) {
|
||||
//throw $th;
|
||||
// echo $e->getCode();
|
||||
echo $e->getData();
|
||||
Session::put('cartkeyError', 'Invalid payment.');
|
||||
return Redirect::route('cart');
|
||||
}
|
||||
|
||||
if ($executePayment->getState() == 'approved') {
|
||||
|
||||
// print_r($executePayment);
|
||||
// if ($executePayment->getState() == 'approved') {
|
||||
|
||||
// /** it's all right **/
|
||||
// /** Here Write your database logic like that insert record or value in database if you want **/
|
||||
|
||||
// // \Session::put('success','Payment success');
|
||||
// // return Redirect::route('paywithpaypal');
|
||||
// echo 'Payment success';
|
||||
// }
|
||||
|
||||
// var_dump($obj->payer->payer_info->shipping_address);
|
||||
// var_dump($obj->transactions[0]->item_list->shipping_address);
|
||||
/** it's all right **/
|
||||
/** Here Write your database logic like that insert record or value in database if you want **/
|
||||
|
||||
// \Session::put('success','Payment success');
|
||||
// return Redirect::route('paywithpaypal');
|
||||
$line2 = null;
|
||||
|
||||
//details
|
||||
@@ -462,11 +463,7 @@ class PaypalController extends Controller
|
||||
|
||||
/// end paypal codes
|
||||
|
||||
$paypal_model = new PayPalModel;
|
||||
$m = new TeamStoreModel;
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
$userId = Auth::user()->id;
|
||||
$user_email = Auth::user()->email;
|
||||
|
||||
|
||||
$payment_details = array(
|
||||
|
||||
@@ -573,6 +570,32 @@ class PaypalController extends Controller
|
||||
return view('paypal.get_done')
|
||||
->with('currency', $currency)
|
||||
->with('total', $total);
|
||||
}else {
|
||||
Session::put('cartkeyError', 'Something went wrong. Please try again.');
|
||||
return Redirect::route('cart');
|
||||
}
|
||||
} catch (PayPalConnectionException $e) {
|
||||
//throw $th;
|
||||
// echo $e->getCode();
|
||||
echo $e->getData();
|
||||
Session::put('cartkeyError', 'Invalid payment.');
|
||||
return Redirect::route('cart');
|
||||
}
|
||||
|
||||
|
||||
// print_r($executePayment);
|
||||
// if ($executePayment->getState() == 'approved') {
|
||||
|
||||
// /** it's all right **/
|
||||
// /** Here Write your database logic like that insert record or value in database if you want **/
|
||||
|
||||
// // \Session::put('success','Payment success');
|
||||
// // return Redirect::route('paywithpaypal');
|
||||
// echo 'Payment success';
|
||||
// }
|
||||
|
||||
// var_dump($obj->payer->payer_info->shipping_address);
|
||||
// var_dump($obj->transactions[0]->item_list->shipping_address);
|
||||
}
|
||||
|
||||
|
||||
@@ -584,6 +607,10 @@ class PaypalController extends Controller
|
||||
$items = $m->myCart($cartKey);
|
||||
$getSubtotal = $m->getSubtotal($cartKey);
|
||||
|
||||
if($items == null) {
|
||||
return redirect()->route('cart');
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->VoucherId != null) {
|
||||
$voucherIds[] = $item->VoucherId;
|
||||
|
||||
@@ -38,4 +38,14 @@ class PayPalModel extends Model {
|
||||
// var_dump($i);
|
||||
return $i;
|
||||
}
|
||||
|
||||
function checkCartKey($ck){
|
||||
|
||||
$i = DB::table('payment_details')
|
||||
->where('CartKey', $ck)
|
||||
// ->take(1)
|
||||
->get();
|
||||
// var_dump($i);
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user