首页 > 解决方案 > 请求一个过时的 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 的本地服务器上开发此应用程序。

标签: laravelpaypal

解决方案


请按照以下步骤操作并告诉我它是否有效:

  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]);
  1. 在你看来 - 添加这个:

您的新表单 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>

推荐阅读