Giter Site home page Giter Site logo

payzap's Introduction

Payzap - Simple paypal payments for laravel

Description

Payzap is the new simple way of integrating paypal in your laravel application with a few lines of code. It uses simple and elegant syntax to create the payment.

Installation

composer require consoletvs/payzap

Register the service provider to the current project (Not needed if using laravel 5.5+):

ConsoleTVs\Payzap\PayzapServiceProvider::class

Publish the configuration:

php artisan vendor:publish

Example payment controller, view and routes

  • PaymentController.php
<?php

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)];
    }
}
  • payment.blade.php:
<!DOCTYPE html>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>

<body>
    <div id="paypal-button"></div>
    {!! $payment->scripts() !!}
</body>
  • Routes (web.php)
Route::get('/payment', 'PaymentController@index')->name('payment');
Route::get('/payment/finished', function () {
    return "Payment Executed.";
})->name('payment.finished');

payzap's People

Contributors

consoletvs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.