让价值传递给Payfast

时间:2019-02-26 13:14:41

标签: laravel payment-gateway

我正在尝试将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);
}

这是我的Confirmation.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="test@test.com">
                <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.'&notify_url='.$notify.'&m_payment_id=01AB&amount='.$totalPrice.'&item_name=Test Item&item_description=A test product&email_confirmation=1&confirmation_address=test@test.com&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>

1 个答案:

答案 0 :(得分:0)

with函数将数据添加到会话中,但是PayFast希望数据位于url中,例如https://sandbox.payfast.co.za/eng/process?amount=100&merchant_id=12&merchant_key=23&item_name=cool

URLGenerator似乎没有提供一种将数组转换为查询参数的简便方法。您可以简单地使用字符串串联来构造查询,或者看看这个answer,其中包括一个构造这样的路径的函数。