fix pargar
This commit is contained in:
@@ -59,7 +59,8 @@ class PargarInboundController extends Controller
|
|||||||
|
|
||||||
public function upsertCustomers(Request $request)
|
public function upsertCustomers(Request $request)
|
||||||
{
|
{
|
||||||
$customers = $request->input('Customers', []);
|
$payload = $this->pargarPayload($request);
|
||||||
|
$customers = $payload['Customers'] ?? [];
|
||||||
if (! is_array($customers) || $customers === []) {
|
if (! is_array($customers) || $customers === []) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
@@ -209,7 +210,8 @@ class PargarInboundController extends Controller
|
|||||||
|
|
||||||
public function confirmOrders(Request $request)
|
public function confirmOrders(Request $request)
|
||||||
{
|
{
|
||||||
$orderIds = $request->input('OrderIds', []);
|
$payload = $this->pargarPayload($request);
|
||||||
|
$orderIds = $payload['OrderIds'] ?? [];
|
||||||
if (! is_array($orderIds)) {
|
if (! is_array($orderIds)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
@@ -229,7 +231,7 @@ class PargarInboundController extends Controller
|
|||||||
|
|
||||||
public function storeDocuments(Request $request)
|
public function storeDocuments(Request $request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $this->pargarPayload($request);
|
||||||
$accountId = trim((string) ($data['accountId'] ?? ''));
|
$accountId = trim((string) ($data['accountId'] ?? ''));
|
||||||
$transactions = $data['transactions'] ?? [];
|
$transactions = $data['transactions'] ?? [];
|
||||||
|
|
||||||
@@ -255,7 +257,7 @@ class PargarInboundController extends Controller
|
|||||||
|
|
||||||
public function storeMande(Request $request)
|
public function storeMande(Request $request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $this->pargarPayload($request);
|
||||||
$accountId = trim((string) ($data['AccountId'] ?? ''));
|
$accountId = trim((string) ($data['AccountId'] ?? ''));
|
||||||
|
|
||||||
$customer = Customer::where('pargar_account_id', $accountId)->first();
|
$customer = Customer::where('pargar_account_id', $accountId)->first();
|
||||||
@@ -343,7 +345,8 @@ class PargarInboundController extends Controller
|
|||||||
|
|
||||||
public function confirmCustomers(Request $request)
|
public function confirmCustomers(Request $request)
|
||||||
{
|
{
|
||||||
$rows = $request->input('customers', []);
|
$payload = $this->pargarPayload($request);
|
||||||
|
$rows = $payload['customers'] ?? [];
|
||||||
if (! is_array($rows)) {
|
if (! is_array($rows)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
@@ -393,23 +396,29 @@ class PargarInboundController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function pargarLoginCredentials(Request $request): array
|
private function pargarLoginCredentials(Request $request): array
|
||||||
{
|
{
|
||||||
$username = (string) $request->input('username', '');
|
$payload = $this->pargarPayload($request);
|
||||||
$password = (string) $request->input('password', '');
|
|
||||||
|
|
||||||
if ($username === '' && $password === '') {
|
|
||||||
$payload = json_decode((string) $request->getContent(), true);
|
|
||||||
if (is_array($payload)) {
|
|
||||||
$username = (string) ($payload['username'] ?? '');
|
|
||||||
$password = (string) ($payload['password'] ?? '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
$this->normalizeCredential($username),
|
$this->normalizeCredential((string) ($payload['username'] ?? '')),
|
||||||
$this->normalizeCredential($password),
|
$this->normalizeCredential((string) ($payload['password'] ?? '')),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function pargarPayload(Request $request): array
|
||||||
|
{
|
||||||
|
$payload = $request->all();
|
||||||
|
if ($payload !== []) {
|
||||||
|
return $payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = json_decode((string) $request->getContent(), true);
|
||||||
|
|
||||||
|
return is_array($decoded) ? $decoded : [];
|
||||||
|
}
|
||||||
|
|
||||||
private function normalizeCredential(string $value): string
|
private function normalizeCredential(string $value): string
|
||||||
{
|
{
|
||||||
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||||
|
|||||||
Reference in New Issue
Block a user