thephpleague / omnipay

A framework agnostic, multi-gateway payment processing library for PHP 5.6+
http://omnipay.thephpleague.com/
MIT License
5.91k stars 925 forks source link

Cannot deserialize instance of `java.lang.String` out of START_OBJECT token #679

Closed hrace009 closed 1 year ago

hrace009 commented 1 year ago

Hello,

I have problem, bellow my code

<?php

namespace App\Http\Controllers\Front;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Omnipay\Omnipay;

class DonateController extends Controller
{
    protected $gateway;

    public function __construct()
    {
        $this->gateway = Omnipay::create( 'PayPal_Rest' );
        $this->gateway->initialize([
            'clientId' => config('pw-config.payment.paypal.client_id'),
            'secret'   => config('pw-config.payment.paypal.secret'),
            'testMode' => true,
        ]);
    }

    public function getPaypalIndex()
    {
        //TODO: Please make paypal running!
        return view('front.donate.paypal.index');
    }

    public function postPaypalSubmit( Request $request )
    {
        $transaction = $this->gateway->purchase([
            'amount'        => number_format( $request->dollars, 0 ),
            'currency'      => config('pw-config.payment.paypal.currency'),
            'description'   => __('donate.paypal.description', ['amount' => $request->dollars, 'currency' => config('pw-config.currency_name')]),
            'returnUrl'     => redirect()->route('app.donate.paypal.complete'),
            'cancelUrl'     => redirect()->route('app.donate.paypal'),
        ]);

        $response = $transaction->send();

        if ( $response->isRedirect() )
        {
            $response->redirect();
        }
        else
        {
            dd($response);
        }
    }
}

when i dd($response) i got this error

#data: array:5 [▼
    "name" => "VALIDATION_ERROR"
    "message" => "Invalid request - see details"
    "debug_id" => "74cf76d525a90"
    "information_link" => "https://developer.paypal.com/docs/api/payments/#errors"
    "details" => array:1 [▼
      0 => array:3 [▼
        "field" => "/redirect_urls/return_url"
        "location" => "body"
        "issue" => "Cannot deserialize instance of `java.lang.String` out of START_OBJECT token"
      ]
    ]
  ]
  #statusCode: 400

Please help,

Thanks

hrace009 commented 1 year ago

I found the fix.

It because i use

'returnUrl'     => redirect()->route('app.donate.paypal.complete'),
'cancelUrl'     => redirect()->route('app.donate.paypal'),

it should be

'returnUrl' => route('app.donate.paypal.complete'),
'cancelUrl' => route('app.donate.paypal'),

Sorry my bad