app/Http/Controllers/PaypalController.php
/**
     * Store a details of payment with paypal.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a details of payment with paypal.
Store a details of payment with paypal .
public function postPaymentWithpaypal(Request $request)
    {
        $payer = new Payer();
        $payer->setPaymentMethod('paypal');
        $item_1 = new Item();
        $item_1->setName('Item 1') 
            ->setCurrency('BRL')
            ->setQuantity(1)
            ->setPrice($request->get('amount')); 
        $item_list = new ItemList();
        $item_list->setItems(array($item_1));
        $amount = new Amount();
        $amount->setCurrency('BRL')
            ->setTotal($request->get('amount'));
        $transaction = new Transaction();
        $transaction->setAmount($amount)
            ->setItemList($item_list)
            ->setDescription('Your transaction description');
        $redirect_urls = new RedirectUrls();
        $redirect_urls->setReturnUrl(URL::route('payment.status')) 
            ->setCancelUrl(URL::route('payment.status'));
        $payment = new Payment();
        $payment->setIntent('Sale')
            ->setPayer($payer)
            ->setRedirectUrls($redirect_urls)
            ->setTransactions(array($transaction));
        try {
            $payment->create($this->_api_context);
        } catch (\PayPal\Exception\PPConnectionException $ex) {
            if (\Config::get('app.debug')) {
                \Session::put('error','Falha de comunicação com o servidor da Paypal.');
                return Redirect::route('paywithpaypal');
            } else {
                \Session::put('error','Erro desconhecido. Por favor entre em contato com o administrador do sistema.');
                return Redirect::route('paywithpaypal');
            }
        }
        foreach($payment->getLinks() as $link) {
            if($link->getRel() == 'approval_url') {
                $redirect_url = $link->getHref();
                break;
            }
        }
        Session::put('paypal_payment_id', $payment->getId());
        if(isset($redirect_url)) {
            return Redirect::away($redirect_url);
        }
        \Session::put('error','Erro desconhecido. Por favor entre em contato com o administrador do sistema.');
        return Redirect::route('paywithpaypal');
    }
public function postPaymentWithpaypal ( Request $ request ) { $ payer = new Payer ( ) ; $ payer -> setPaymentMethod ( 'paypal' ) ; $ item_1 = new Item ( ) ; $ item_1 -> setName ( 'Item 1' ) -> setCurrency ( 'BRL' ) -> setQuantity ( 1 ) -> setPrice ( $ request -> get ( 'amount' ) ) ; $ item_list = new ItemList ( ) ; $ item_list -> setItems ( array ( $ item_1 ) ) ; $ amount = new Amount ( ) ; $ amount -> setCurrency ( 'BRL' ) -> setTotal ( $ request -> get ( 'amount' ) ) ; $ transaction = new Transaction ( ) ; $ transaction -> setAmount ( $ amount ) -> setItemList ( $ item_list ) -> setDescription ( 'Your transaction description' ) ; $ redirect_urls = new RedirectUrls ( ) ; $ redirect_urls -> setReturnUrl ( URL :: route ( 'payment.status' ) ) -> setCancelUrl ( URL :: route ( 'payment.status' ) ) ; $ payment = new Payment ( ) ; $ payment -> setIntent ( 'Sale' ) -> setPayer ( $ payer ) -> setRedirectUrls ( $ redirect_urls ) -> setTransactions ( array ( $ transaction ) ) ; try { $ payment -> create ( $ this -> _api_context ) ; } catch ( \ PayPal \ Exception \ PPConnectionException $ ex ) { if ( \ Config :: get ( 'app.debug' ) ) { \ Session :: put ( 'error' , 'Falha de comunicação com o servidor da Paypal.'); return Redirect :: route ( 'paywithpaypal' ) ; } else { \ Session :: put ( 'error' , 'Erro desconhecido. Por favor entre em contato com o administrador do sistema.' ) ; return Redirect :: route ( 'paywithpaypal' ) ; } } foreach ( $ payment -> getLinks ( ) as $ link ) { if ( $ link -> getRel ( ) == 'approval_url' ) { $ redirect_url = $ link -> getHref ( ) ; break ; } } Session :: put ( 'paypal_payment_id' , $ payment -> getId ( ) ) ; if ( isset ( $ redirect_url ) ) { return Redirect :: away ( $ redirect_url ) ; } \ Session :: put ( 'error' , 'Erro desconhecido. Por favor entre em contato com o administrador do sistema.' ) ; return Redirect :: route ( 'paywithpaypal' ) ; }
Store a details of payment with paypal.
Store a details of payment with paypal .
/** item name **/ /** unit price **/ /** Specify return URL **/ /** dd($payment->create($this->_api_context));exit; **/ /** echo "Exception: " . $ex->getMessage() . PHP_EOL; **/ /** $err_data = json_decode($ex->getData(), true); **/ /** exit; **/ /** die('Some error occur, sorry for inconvenient'); **/ /** add payment ID to session **/ /** redirect to paypal **/