create payment table, update controller
This commit is contained in:
parent
adc5e60f17
commit
d191e80d61
|
|
@ -15,24 +15,36 @@ class PayPalController extends Controller
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'item' => [
|
'item' => [
|
||||||
'name' => 'photo',
|
'name' => 'Laptop',
|
||||||
'sku' => 'photo001',
|
'sku' => 'L001',
|
||||||
'quantity' => '3',
|
'quantity' => '1',
|
||||||
'unit_amount' => [
|
'unit_amount' => [
|
||||||
'currency_code' => 'USD',
|
'currency_code' => 'USD',
|
||||||
'value' => '10',
|
'value' => '1000',
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => 2,
|
'id' => 2,
|
||||||
'item' => [
|
'item' => [
|
||||||
'name' => 'oto',
|
'name' => 'iPad',
|
||||||
'sku' => 'oto001',
|
'sku' => 'I001',
|
||||||
'quantity' => '2',
|
'quantity' => '1',
|
||||||
'unit_amount' => [
|
'unit_amount' => [
|
||||||
'currency_code' => 'USD',
|
'currency_code' => 'USD',
|
||||||
'value' => '10',
|
'value' => '500',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'item' => [
|
||||||
|
'name' => 'Dep Laos',
|
||||||
|
'sku' => 'D001',
|
||||||
|
'quantity' => '1',
|
||||||
|
'unit_amount' => [
|
||||||
|
'currency_code' => 'USD',
|
||||||
|
'value' => '100',
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
@ -47,17 +59,15 @@ class PayPalController extends Controller
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
// $provider = new PayPalClient;
|
$orders = Payment::all();
|
||||||
// $provider->setApiCredentials(config('paypal'));
|
$provider = new PayPalClient;
|
||||||
// $provider->getAccessToken();
|
$provider->setApiCredentials(config('paypal'));
|
||||||
|
$paypalToken = $provider->getAccessToken();
|
||||||
|
|
||||||
// $id_order = session('paypal_payment_id');
|
foreach( $orders as $order ){
|
||||||
// $detail = $id_order ? json_encode($provider->showOrderDetails($id_order)) : null;
|
$order['data'] = json_encode($provider->showOrderDetails($order['id_order']));
|
||||||
// if($id_order){
|
}
|
||||||
// dd(session('paypal_payment_id'));
|
return view('paypal', ['user' => $request->user(), 'orders' => $orders ?? []]);
|
||||||
// }
|
|
||||||
// dd($id_order);
|
|
||||||
return view('paypal', ['user' => $request->user()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -119,7 +129,7 @@ class PayPalController extends Controller
|
||||||
|
|
||||||
foreach ($order['links'] as $links) {
|
foreach ($order['links'] as $links) {
|
||||||
if ('approve' == $links['rel']) {
|
if ('approve' == $links['rel']) {
|
||||||
Payment::create(['user_id'=>$user_id, 'id_order'=>$order['id'], 'status'=>'pending']);
|
Payment::create(['user_id' => $user_id, 'id_order' => $order['id'], 'status' => 'pending']);
|
||||||
return redirect()->away($links['href']);
|
return redirect()->away($links['href']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +178,7 @@ class PayPalController extends Controller
|
||||||
$order->save();
|
$order->save();
|
||||||
|
|
||||||
if (isset($response['status']) && 'COMPLETED' == $response['status']) {
|
if (isset($response['status']) && 'COMPLETED' == $response['status']) {
|
||||||
return redirect(route('paypal'))->with(['success', 'Transaction complete.']);
|
return redirect(route('paypal'))->with('success', 'Transaction complete.');
|
||||||
} else {
|
} else {
|
||||||
return redirect(route('paypal'))
|
return redirect(route('paypal'))
|
||||||
->with('error', $response['message'] ?? 'Something went wrong.');
|
->with('error', $response['message'] ?? 'Something went wrong.');
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
<div class="col-10 offset-1 mt-5">
|
<div class="col-10 offset-1 mt-5">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header bg-primary">
|
<div class="card-header bg-primary">
|
||||||
<h3 class="text-white">Laravel PayPal Payment Gateway Integration Example - ItSolutionStuff.com
|
<h3 class="text-white">Tạp hóa
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
@ -35,14 +35,73 @@
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<center>
|
<div class="d-flex">
|
||||||
<a href="{{ route('paypal.payment', ['id'=>2, 'user_id'=>$user->id]) }}" class="btn btn-success">Pay with PayPal </a>
|
<div class="card m-1" style="width: 18rem;">
|
||||||
</center>
|
<div class="h-75">
|
||||||
|
<img src="https://cdn.tgdd.vn/Files/2022/07/07/1445532/laptop-like-new-99-la-gi-co-tot-khong-co-nen-1.jpg" class="card-img-top" alt="...">
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Laptop</h5>
|
||||||
|
<h4 class="card-title">$1000.00 USD</h4>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up
|
||||||
|
the
|
||||||
|
bulk of the card's content.</p>
|
||||||
|
<a href="{{ route('paypal.payment', ['id' => 1, 'user_id' => $user->id]) }}" class="btn btn-primary">Buy now</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card m-1" style="width: 18rem;">
|
||||||
|
<div class="h-75">
|
||||||
|
<img src="https://cdn2.cellphones.com.vn/insecure/rs:fill:0:358/q:80/plain/https://cellphones.com.vn/media/catalog/product/1/_/1_253_7.jpg" class="card-img-top" alt="...">
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">iPad</h5>
|
||||||
|
<h4 class="card-title">$500.00 USD</h4>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up
|
||||||
|
the
|
||||||
|
bulk of the card's content.</p>
|
||||||
|
<a href="{{ route('paypal.payment', ['id' => 2, 'user_id' => $user->id]) }}" class="btn btn-primary">Buy now</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card m-1" style="width: 18rem;">
|
||||||
|
<div class="h-75">
|
||||||
|
<img src="https://chosathaiphong.com/wp-content/uploads/2018/04/dep-tong-lao-1.jpg" class="card-img-top" alt="...">
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Dep Lao's</h5>
|
||||||
|
<h4 class="card-title">$100.00 USD</h4>
|
||||||
|
<p class="card-text">Some quick example text to build on the card title and make up
|
||||||
|
the
|
||||||
|
bulk of the card's content.</p>
|
||||||
|
<a href="{{ route('paypal.payment', ['id' => 3, 'user_id' => $user->id]) }}" class="btn btn-primary">Buy now</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h5 class="mt-5">List orders</h5>
|
||||||
|
@foreach($orders as $order)
|
||||||
|
<h6 onclick="updateDetail({{$order->id}})">{{$order->id_order}} - {{$order->status}}</h6>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
<div id="detail" style="background-color: aquamarine"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
<script>
|
||||||
|
const updateDetail = (id) => {
|
||||||
|
const data = {!!$orders!!}
|
||||||
|
const order = JSON.parse(data.filter((i)=>i.id===id)[0].data)
|
||||||
|
let divDetail = document.getElementById('detail').innerHTML = `
|
||||||
|
<h6>ID: ${order.id}</h6>
|
||||||
|
<h6>Intent: ${order.intent}</h6>
|
||||||
|
<h6>Status: ${order.status}</h6>
|
||||||
|
<h6>Items: ${JSON.stringify(order.purchase_units[0].items,null, 2)}</h6>
|
||||||
|
` ;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue