@henock_barakael By writing some code. Tackle the task in steps.
Multiple payment API using checkbox
How can i make an API multiple payment using checkbox data in table? I mean: Import CSV file and store data to DB next click checkall to make multiple payment.
@martinbean Please can you help me?
CONTROLLER
public function import(Request $request){ $path = $request->file('file')->getRealPath(); Excel::import(new PayoutsImport, $path); Toastr::success("Records successful imported!",'Success'); return redirect()->back(); }
VIEW
<div class="row g-4 align-items-center">
<div class="col-sm">
<div>
<h5 class="card-title mb-0">TICKETS LIST</h5>
</div>
</div>
<div class="col-sm-auto">
<div>
<button class="btn btn-danger btn-border btn-sm delete-all">Delete All</button>
<button type="button" class="btn btn-secondary btn-border btn-sm pay-all" data-url="">Pay All</button>
</div>
</div>
</div>
</div>
<div class="card-body">
<table class="display table table-bordered" id="fixed-header" style="width:100%">
<thead class="table-light text-muted">
<tr>
<th scope="col" style="width: 50px;">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check_all">
</div>
</th>
{{-- <th class="text-center">#</th> --}}
<th class="text-left">Customer Number</th>
<th class="text-center">Amount</th>
<th class="text-center">Currency</th>
<th class="text-left">File Uploaded On</th>
{{-- <th class="text-left">Updated_at</th> --}}
<th class="text-left">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody class="list form-check-all">
@if($payouts->count())
@foreach ($payouts as $key => $item)
<tr id="tr_{{$item->id}}">
<th scope="row">
<div class="form-check">
<input class="form-check-input checkbox" type="checkbox" data-id="{{$item->id}}">
</div>
</th>
{{-- <td class="text-center">{{ ++$key }}</td> --}}
<td class="text-left">{{ $item->credit_account }}</td>
<td class="text-center">{{ $item->amount }}</td>
<td class="text-center">{{ $item->currency }}</td>
<td class="text-left">{{ $item->created_at }}</td>
{{-- <td class="text-left">{{ $item->updated_at }}</td> --}}
<td class="text-left"><span class="badge rounded-pill badge-soft-success">Unpaid</span></td>
<td class="text-center">
{!! Form::open(['method' => 'POST','route' => ['admin.paiement', $item->id],'style'=>'display:inline']) !!}
{!! Form::submit('Payer', ['class' => 'btn btn-secondary btn-border btn-sm','data-toggle'=>'confirmation','data-placement'=>'left']) !!}
{!! Form::close() !!}
{!! Form::open(['method' => 'DELETE','route' => ['admin.paiement.delete', $item->id],'style'=>'display:inline']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger btn-border btn-sm','data-toggle'=>'confirmation','data-placement'=>'left']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
</div>
</div>
AJAX
$('.pay-all').on('click', function(e) { var idsArr = []; $(".checkbox:checked").each(function() { idsArr.push($(this).attr('data-id')); }); if(idsArr.length <=0) { alert("Please select atleast one transaction to credit."); } // Start Multiple Paiement else {
var strIds = idsArr.join(",");
$.ajax({
url: "{{ route('admin.paiement.multiple') }}",
type: 'POST',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: 'ids='+strIds,
success: function (data) {
if (data['status']==true) {
alert(data['message']);
}
else {
alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});
}
// End Multiple paiement
});
});
PROCESS PAYMENT
public function payoutAPI($credit_account, $amount, $currency){ $operator = $this->vendor($credit_account); iif ($operator == "orange") { $prefix = "O"; $apiURL = ''; $merchant_ref = $this->merchant_ref($prefix); $key = "oXc7119158]AIl5.mZZ'#(c}m6rP,Xi"; $debit_account = "0858005722"; $vendor = "orange"; }
$accessToken = "";
$headers = [
'X-header' => 'Content-Type:application/json',
'Authorization' => 'Bearer '.$accessToken,
];
$curl_post_data = [
"credit_account" => $telephone,
"amount" => $amount,
"currency" => $currency,
"action" => "payout",
"debit_channel" => $vendor,
"debit_account" => $debit_account,
"merchant_ref" => $merchant_ref,
"merchant_code" => "FP001",
"key" => $key
];
$response = Http::withHeaders($headers)->post($apiURL, $curl_post_data);
$statusCode = $response->status();
$responseBody = json_decode($response->getBody(), true);
@martinbean any answer?
Please or to participate in this conversation.