我正在尝试将Paystack付款集成到我的Laravel项目中。它在开发环境中可以正常工作,因为它会成功。但是,当我将项目移至生产环境时,它会带来以下错误。
客户端错误:POST https://api.paystack.co/transaction/initialize 导致403禁止响应
刀片
<form method="POST" action="{{ route('pay') }}" accept-charset="UTF-8" class="form-horizontal" role="form">
<div class="row" style="margin-bottom:40px;">
<div class="col-md-8 col-md-offset-2">
<div>
<p><strong><i>*You are required to make a payment of N5,000 as Application and Processing
fee</i></strong></p>
</div>
</div>
<input type="hidden" name="email" value="{{ Auth::user()->email }}"> {{-- required --}}
<input type="hidden" name="orderID" value="{{ Auth::user()->id }}">
<input type="hidden" name="amount" value="500000"> {{-- required in kobo --}}
<input type="hidden" name="quantity" value="3">
<input type="hidden" name="metadata"
value="{{ json_encode($array = ['key_name' => 'value',]) }}"> {{-- For other necessary things you want to add to your payload. it is optional though --}}
<input type="hidden" name="reference" value="{{ Paystack::genTranxRef() }}"> {{-- required --}}
<input type="hidden" name="key" value="{{ config('paystack.secretKey') }}"> {{-- required --}}
{{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}}
<input type="hidden" name="_token"
value="{{ csrf_token() }}"> {{-- employ this in place of csrf_field only in laravel 5.0 --}}
<p>
<button class="btn btn-success btn-lg btn-block text-center" type="submit" value="Pay Now!">
<i class="fa fa-plus-circle fa-lg"></i> Process My Application
</button>
</p>
</div>
</form>
控制器
class PaymentController extends Controller
{
/**
* Redirect the User to Paystack Payment Page
*/
public function redirectToGateway()
{
return Paystack::getAuthorizationUrl()->redirectNow();
}
/**
* Obtain Paystack payment information
*/
public function handleGatewayCallback()
{
$paymentDetails = Paystack::getPaymentData();
// Now you have the payment details,
// you can store the authorization_code in your db to allow for recurrent subscriptions
// you can then redirect or do whatever you want
if (array_key_exists('data', $paymentDetails) && array_key_exists('status',
$paymentDetails['data']) && ($paymentDetails['data']['status'] === 'success')) {
echo 'Transaction Was Successful';
if (auth()->user()->update(['reference' => $paymentDetails['data']['reference']])) {
\Mail::to(Auth::user()->email)->send(new Payments(Auth::user()));
\Mail::to('info@example.com')->send(new Confirmation(Auth::user()));
}
} else {
echo 'Transaction Was Unsuccessful';
}
return redirect()->back()->with('success', 'Your Payment Was Received. Thank You.');
}
}