Я пытаюсь интегрировать Payfast с моим проектом laravel. Проблема, с которой я столкнулся, заключается в том, что данные не передаются в Payfast, поэтому Payfast продолжает выдавать мне сообщение об ошибке The supplied variables are not according to specification:
Вот мой код в моем контроллере
public function payPayfast(Request $request)
{
$data = [
'merchant_id' => $request->merchant_id,
'merchant_key' => $request->merchant_key,
'return_url' => $request->return_url,
'cancel_url' => $request->cancel_url,
'm_payment_id' => $request->m_payment_id,
'amount' => $request->amount,
'item_name' => 'Test Item From Controller',
'item_description' => 'This is a test product',
'email_confirmation' => '1',
'confirmation_address' => '',
'payment_method' => $request->payment_method,
'signature' => $request->signature,
];
return redirect()->to('https://sandbox.payfast.co.za/eng/process')->with('data', $data);
}
вот мой код в моем подтверждении.blade.php
<div class = "content_wrapper">
<h1>Order Confrimation</h1>
<div class = "row">
<div class = "col-lg-12">
<form action = "{{ route('payfast.payPayfast') }}" method = "POST">
@csrf
<input type = "hidden" name = "merchant_id" value = "11111111">
<input type = "hidden" name = "merchant_key" value = "2222222222222">
<input type = "hidden" name = "return_url" value = "{{ route('payfast.success') }}">
<input type = "hidden" name = "cancel_url" value = "{{ route('payfast.cancel') }}">
<input type = "hidden" name = "notify_url" value = "{{ route('payfast.notify') }}">
<input type = "hidden" name = "m_payment_id" value = "01AB">
<input type = "hidden" name = "amount" class = "completePrice" value = "{{ $total }}">
<input type = "hidden" name = "item_name" value = "Test Item">
<input type = "hidden" name = "item_description" value = "A test product">
<input type = "hidden" name = "email_confirmation" value = "1">
<input type = "hidden" name = "confirmation_address" value = "[email protected]">
<input type = "hidden" name = "payment_method" value = "eft">
<?php
$success = url('payfast-success');
$cancel = url('payfast-cancel');
$notify = url('payfast-notify');
$original_str = getAscii('merchant_id=11111111&merchant_key=2222222222222&return_url='.$success.'&cancel_url='.$cancel.'¬ify_url='.$notify.'&m_payment_id=01AB&amount='.$totalPrice.'&item_name=Test Item&item_description=A test product&email_confirmation=1&[email protected]&payment_method=eft');
$hash_str = hash('MD5', $original_str);
$hash = strtolower($hash_str);
?>
<input type = "hidden" name = "signature" value = "{{ $hash }}">
<button class = "btn btn-dark" type = "submit"><img src = "{{ asset('img/eft-payfast.jpg') }}"></button>
</form>
</div>
</div>
</div>






Функция with добавляет данные в сеанс, но PayFast ожидает, что данные будут в URL-адресе, например. https://sandbox.payfast.co.za/eng/process?amount=100&merchant_id=12&merchant_key=23&item_name=cool.
Не похоже, что Генератор URL предоставляет простой способ превратить массив в параметры запроса. Вы можете просто построить запрос, используя конкатенацию строк, или взглянуть на этот отвечать, который включает функцию для построения такого пути.
Вы хотите сначала отправить его своему собственному контроллеру, чтобы выполнить дополнительные проверки данных перед перенаправлением в PayFast? Если нет, то вы можете просто опубликовать прямо в PayFast из своей формы — так выполняется большинство интеграций PayFast, через
form post.