#StackBounty: #php #laravel #laravel-5 #paypal PayPal API with Laravel – Updating of data

Bounty: 250

I’m trying to implement the API of paypal payment with laravel 5.1. But when I login in paypal (sandbox), it uses the address I used in my account, and also it uses the name from paypal account not the data from my website. That’s my problem.

I want to use the data from my website because it doesn’t make sense if I enter the shipping address (for example) from my website and not using it. Please see my code below for reference (Or comment down below for some details from me).

class PaypalPaymentController extends BaseController

    private $_api_context;

    public function __construct(){
        $paypal_conf = Config::get('paypal');

        $this->_api_context = new ApiContext(new OAuthTokenCredential(


    public function payWithPaypal(Request $request){
        $payer = new Payer;

        $price = 0;

        switch($request->get('amount')) {
            case '10 books':
                $price = 6200;
            case '20 books':
                $price = 12200;
            case '50 books':
                $price = 25200;
                return redirect()
                        ->with('danger', 'Please select the right amount of book/s.');

        $item1 = new Item();

        $item_list = new ItemList();

        $amount = new Amount();

        $transaction = new Transaction();
                    ->setDescription('Books transaction');

        $redirect_urls = new RedirectUrls();

        $payment = new Payment();

        } catch(PalpalExceptionPPConnectionException $e){
                return redirect()
                        ->with('danger', 'Connection Timeout.');

            return redirect()
                    ->with('danger', 'Some error occured, sorry for the inconvenience.');

        foreach($payment->getLinks() as $link){
            if($link->getRel() == 'approval_url'){
                $redirect_url = $link->getHref();

        Session::put('paypal_payment_id', $payment->getId());

            return Redirect::away($redirect_url);

        return redirect()
                ->with('danger', 'Unknown error occured.');

    public function getPaymentStatus(){
        $payment_id = Session::get('paypal_payment_id');

        if(empty(Input::get('PayerID')) || empty(Input::get('token'))){
            return redirect()
                    ->with('danger', 'Payment failed.');

        $payment = Payment::get($payment_id, $this->_api_context);
        $execution = new PaymentExecution();

        $result = $payment->execute($execution, $this->_api_context);

        if($result->getState() == 'approved'){
            // Send Email
            $email_data = [
                'number_of_books' => $payment->transactions[0]->item_list->items[0]->name,
                'shipping' => [
                    'street' => $payment->payer->payer_info->shipping_address->line1,
                    'city' => $payment->payer->payer_info->shipping_address->city,
                    'state' => $payment->payer->payer_info->shipping_address->state,
                    'country' => $payment->payer->payer_info->shipping_address->country_code,

            // Send email function here ...

            return redirect()
                    ->with('success', 'Transaction payment success!');

        return redirect()
                ->with('danger', 'Payment failed.');


I also reviewed this link but it seems like it cannot answer my problem. Also, what if the country has a province? How can we add that?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.