create payment table, update controller

This commit is contained in:
joseph le 2023-12-06 16:53:48 +07:00
parent adc5e60f17
commit d191e80d61
2 changed files with 95 additions and 26 deletions

View File

@ -15,24 +15,36 @@ class PayPalController extends Controller
[
'id' => 1,
'item' => [
'name' => 'photo',
'sku' => 'photo001',
'quantity' => '3',
'name' => 'Laptop',
'sku' => 'L001',
'quantity' => '1',
'unit_amount' => [
'currency_code' => 'USD',
'value' => '10',
'value' => '1000',
],
]
],
[
'id' => 2,
'item' => [
'name' => 'oto',
'sku' => 'oto001',
'quantity' => '2',
'name' => 'iPad',
'sku' => 'I001',
'quantity' => '1',
'unit_amount' => [
'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)
{
// $provider = new PayPalClient;
// $provider->setApiCredentials(config('paypal'));
// $provider->getAccessToken();
$orders = Payment::all();
$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypalToken = $provider->getAccessToken();
// $id_order = session('paypal_payment_id');
// $detail = $id_order ? json_encode($provider->showOrderDetails($id_order)) : null;
// if($id_order){
// dd(session('paypal_payment_id'));
// }
// dd($id_order);
return view('paypal', ['user' => $request->user()]);
foreach( $orders as $order ){
$order['data'] = json_encode($provider->showOrderDetails($order['id_order']));
}
return view('paypal', ['user' => $request->user(), 'orders' => $orders ?? []]);
}
/**
@ -168,7 +178,7 @@ class PayPalController extends Controller
$order->save();
if (isset($response['status']) && 'COMPLETED' == $response['status']) {
return redirect(route('paypal'))->with(['success', 'Transaction complete.']);
return redirect(route('paypal'))->with('success', 'Transaction complete.');
} else {
return redirect(route('paypal'))
->with('error', $response['message'] ?? 'Something went wrong.');

View File

@ -14,7 +14,7 @@
<div class="col-10 offset-1 mt-5">
<div class="card">
<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>
</div>
<div class="card-body">
@ -35,14 +35,73 @@
</div>
@endif
<center>
<a href="{{ route('paypal.payment', ['id'=>2, 'user_id'=>$user->id]) }}" class="btn btn-success">Pay with PayPal </a>
</center>
<div class="d-flex">
<div class="card m-1" style="width: 18rem;">
<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 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>
</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>