laravel - 请求一个过时的 PayPal 版本。与 laravel 集成
问题描述
我正在尝试将贝宝与我的 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>
我可以重定向到贝宝,但在贝宝页面上显示消息,例如“您请求了过时版本的 PayPal。此错误通常是由于使用书签造成的。 ”
谁能指导我这段代码有什么问题。在第二个代码值类似于此“ _xclick&business=info@gmail.com+&item_name=Unlimited_Pizza&amount=199 ”。
我正在 ubuntu 的本地服务器上开发此应用程序。
解决方案
请按照以下步骤操作并告诉我它是否有效:
- 检查您的控制器并将其添加到您的功能以显示此付款页面:)
数组中的值:
$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>
推荐阅读
- php - 如何忽略 - 在 laravel 中的数字
- nginx - NGINX JWT 身份验证验证特定 JWT 声明(iss、aud 等)
- flutter - 如何在没有 BuildContext 的情况下解析 ImageProvider
- google-sheets - Google 表格:为什么我的查询的第一个单元格重复?
- eclipse - PropertyManager2 迭代树以获得无限深度以删除/移动 IFile
- python - 在 GPU 上使用 tensorflow,但也在同一代码中使用 numpy 数组:内存开销延迟?
- discord.py - 转发:Discord.py 和 Sympy(我认为主要是 discord.py)
- typescript - Apollo 客户端错误:在上下文中找不到“客户端”或作为选项传入。将根组件包装在一个
- python - 如何仅绘制最大的矩形轮廓来检测车辆牌照(专门用于摩托车牌照)
- javascript - 如何从 JavaScript 对象中动态检索任意指定的深度嵌套值?