Adarsh Bhatt
Adarsh Bhatt

Reputation: 588

Requested an outdated version of PayPal. Integration with laravel

I am trying to integrate paypal with my laravel project. I have did two type of template code in paypal form and get 2 different error with both type of code respectively.

I have tried below codes, please check and help me to solve this problem

1) Code 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>

i got error like " BAD_INPUT_ERROR ".

2) Code 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&[email protected]+&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>

I am able to redirect to paypal but on paypal page it display message like " You have requested an outdated version of PayPal. This error often results from the use of bookmarks. "

Can anyone please guide me what is the issue in this code. in second code value is similar to this " _xclick&[email protected]+&item_name=Unlimited_Pizza&amount=199 ".

I am developing this application in my local server in ubuntu.

Upvotes: 1

Views: 895

Answers (1)

Saif Manwill
Saif Manwill

Reputation: 722

Please follow these steps and tell me if it's work :

  1. Check your Controller & add this to your function to show this payment page :)

Values in Array:

$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. In your view - add this :

Your new form 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>

And to submit :

<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>

Upvotes: 1

Related Questions