我正在尝试将Paypal与我的laravel项目集成。我用贝宝(Paypal)形式做了两种类型的模板代码,两种类型的代码分别出现了2种不同的错误。
我尝试了以下代码,请检查并帮助我解决此问题
1)代码1:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="frmTransaction" id="frmTransaction">
<input type="hidden" name="business" value="{{$paypal_id}}">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value=" {{$product['product']->name}}">
<input type="hidden" name="item_number" value="{{$product['product']->id}}">
<input type="hidden" name="amount" value="{{$product['product']->price}}">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="cancel_return" value="{{ url('payment-cancel')}}">
<input type="hidden" name="return" value="{{ url('payment-status')}}">
</form>
<script>document.frmTransaction.submit();</script>
我收到类似“ BAD_INPUT_ERROR ”的错误。
2)代码2:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="frmTransaction" id="frmTransaction">
<input type="hidden" name="business" value="{{$paypal_id}}">
<input type="hidden" name="cmd" value="_xclick&business=info@gmail.com+&item_name={{str_replace(' ', '_',$product['product']->name)}}&amount={{$product['product']->price}}">
<input type="hidden" name="item_name" value="{{$product['product']->name}}">
<input type="hidden" name="item_number" value="{{$product['product']->id}}">
<input type="hidden" name="amount" value="{{$product['product']->price}}">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="cancel_return" value="{{ url('payment-cancel')}}">
<input type="hidden" name="return" value="{{ url('payment-status')}}">
</form>
<script>document.frmTransaction.submit();</script>
我能够重定向到贝宝,但是在贝宝页面上,它显示类似“ 您请求的贝宝版本已过时。此错误通常是由于使用了书签导致的。“
任何人都可以指导我此代码中的问题是什么。第二个代码中的值与此“ _xclick&business=info@gmail.com+&item_name=Unlimited_Pizza&amount=199 ”类似。
我正在ubuntu的本地服务器上开发此应用程序。
答案 0 :(得分:1)
请按照以下步骤操作,并告诉我是否可行:
数组中的值
$values = [
'charest' => 'utf-8',
'lc' => 'US',
'cmd' => '_xclick',
'amount' => $product['product']->price, // PRICE
'business' => $paypal_id, // PAYPAL EMAIL
'item_name' => $product['product']->name, // NAME
'item_number' => $product['product']->id, // ITEM ID
'currency_code' => 'USD',
'no_note' => '1',
'tax_rate' => 0, // 0- TO NOT ADD ANY FEES
'no_shipping' => 1, // NO ADDRESS
'rm' => '1',
'page_style' => 'paypal',
'custom' => '', // ANY VALUES TO RETURN IT AFTER PAYMENT SUCCESS
'return' => url('payment-status'), // RETURN - MUST BE A VALID URL
'cancel_return' => url('payment-cancel'),
'notify_url' => url('payment-success') // IPN PAYPAL - CREATE THIS ROUTE - TO CHECK IF IS PAID
];
$pay_url = "https://www.paypal.com/cgi-bin/webscr";
// CREATE $payment TO CHECK IF IS SANDBOX or LIVE - FROM CONFIG FILE FOR EXAMPLE
if ($payment == 'sandbox') :
$pay_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
endif;
// RETURN YOUR VIEW WITH THIS VALUES
return view ('your_view', ['pay_url' => $pay_url, 'values' => $values]);
您的新表单HTML:)
<form action='{{ $pay_url }}' method='POST' class='paypal-form' target='_top' id='pay_now_paypal'>
@foreach ($values as $name => $value) : ?>
<input type='hidden' name='{{ $name }}' value='{{ $value }}'>
@endforeach
</form>
并提交:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script>
<a href="#" class="btn btn-success paypal-button">Pay with Paypal <i class="fa fa-angle-double-right"></i></a>
<script>
// update paypal form on paypal button click
$('.paypal-button').on('click', function(e) {
e.preventDefault();
$('#pay_now_paypal').submit();
});
</script>