PHP code example of consoletvs / payzap

1. Go to this page and download the library: Download consoletvs/payzap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

consoletvs / payzap example snippets


ConsoleTVs\Payzap\PayzapServiceProvider::class



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use ConsoleTVs\Payzap\Classes\Payment;

class PaymentController extends Controller
{
    /**
     * Returns the payment view and setups the javascript logic.
     *
     * @author Erik Campobadal <[email protected]>
     * @copyright 2017 erik.cat
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $payment = Payment::prepare()
            ->createUrl(route('api::payments.create'))
            ->executeUrl(route('api::payments.execute'))
            ->redirectUrl(route('payment.finished'))
            ->buttonId('paypal-button');

        return view('payment', compact('payment'));
    }

    /**
     * Creates the paypal payment using payzap.
     *
     * @author Erik Campobadal <[email protected]>
     * @copyright 2017 erik.cat
     * @return \ConsoleTVs\Payzap\Classes\Payment
     */
    public function create()
    {
        return Payment::create()
            ->addItem([
                'name' => 'Product 1',
                'currency' => 'EUR',
                'quantity' => 1,
                'price' => 0.5,
            ])->addItem([
                'name' => 'Product 2',
                'currency' => 'EUR',
                'quantity' => 2,
                'price' => 0.25,
            ])->description("My first payment")
            ->generate();
    }

    /**
     * Executes the paypal payment and returns the result boolean in an array.
     *
     * @author Erik Campobadal <[email protected]>
     * @copyright 2017 erik.cat
     * @param  Request $request
     * @return array
     */
    public function execute(Request $request)
    {
        return ['result' => Payment::execute($request->payment_id, $request->payer_id) !== false];
    }
}

Route::get('/payment', 'PaymentController@index')->name('payment');
Route::get('/payment/finished', function () {
    return "Payment Executed.";
})->name('payment.finished');

php artisan vendor:publish