Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

525
Views
Laravel: devuelve datos del servidor sin redirigir

Lo que estoy tratando de hacer es llamar a la función del servidor y validar los datos en la función javascript, pero la declaración de devolución del servidor hace la redirección antes de la response.complete("success")

 button.onclick = async function handlePurchase() { const payment = new PaymentRequest(methods, details, options); try { const response = await payment.show(); // Call server logic here and validate response if OK continue // But server response redirect here so code not completed $('#checkout-form').submit(); $.ajax({ url: '{{route("apple-pay")}}', type: 'post', data: $('#checkout-form').serialize(), success: function(data){ console.log('data :>> ', data); } }); await response.complete("success"); // redirect to success page } catch (err) { console.error("Uh oh, something bad happened", err.message); } }

Función del servidor:

 public function pay(Request $request) { $merchant_id = env('CREDIMAX_MERCHANT_ID'); $password = env('CREDIMAX_INTEGRATION_PASSWORD'); $response = Http::withBasicAuth('merchant.'.$merchant_id, $password)->put ('https://example.com/api/rest/merchant/'.$merchant_id.'/order/1530/transaction/1', $data); return $respone->json(); }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Separe la solicitud que está realizando a la aplicación de terceros y la respuesta que está enviando a su llamada ajax. Esto es lo que quiero decir:

 public function pay(Request $request) { $merchant_id = env('CREDIMAX_MERCHANT_ID'); $password = env('CREDIMAX_INTEGRATION_PASSWORD'); $response = Http::withBasicAuth('merchant.'.$merchant_id, $password)->put ('https://example.com/api/rest/merchant/'.$merchant_id.'/order/1530/transaction/1', $data); return response()->json([ 'success' => $response->ok() ? 1 : 0, ... ]); }
over 4 years ago · Santiago Trujillo Report

0

Verifique la última línea en el controlador que dice "return $respone->json();" y debería ser "return $response->json();" -- Falta la "s" en respuesta.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!