Coder Social home page Coder Social logo

stackout / payment-gateways Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 192 KB

This project is meant to provide ease of access to connect to multiple payment gateways.

License: MIT License

PHP 75.68% HTML 23.65% CSS 0.68%
laravel stripe payment-gateway php authorize-net

payment-gateways's Introduction

Please note! This package is a work in progress. I was in dire need of something with respect to a payment processor gateway for scaleability purposes. Please feel free to use and help build the library!

Laravel Payment Gateway Processor

This project is meant to provide ease of access to connect to multiple payment gateways.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them

Laravel
Stripe

Navigate to your desired project folder, and create a new laravel project.

laravel new MyProject

Installing

Installing the package is easy, simply require via composer.

composer require stackout/payment-gateways

After installing, if you want to use the example checkout views to test your connections, place this line inside your config/app.php

Please note, this step is not required. The service provider was used for testing.

providers = [

    // app providers

        Stackout\PaymentGateways\PaymentGatewaysServiceProvider::class,

    // ...

]

Next, after requiring the package, run the artisan command to require the config and migration files. The migration file simply adds a few columns to your user table.

php artisan vendor:publish

If you use NoSQL migrating the files are not required. If there are any properties and data inside of a collection, the data will be appended and used automatically.

Usage

Here is basic usage of the package. You can add a 'charge' method to your user.

use Stackout\PaymentGateways\Traits\IsChargeable;

class User extends Model
{
    use IsChargeable;

}

To charge the user after you've added the IsChargeable trait to the user or customer model

use App\User;

class CheckoutController extends Controller{

    public function postCheckout(Request $request){

        // Charge the Customer
        $user = User::find(1);

        /**
         * Charge the Customer $50.00
         */
        $response = $user->charge(5000); 

        /**
         * If there was a problem or an issue that arose when we tried to charge the card
         * the 'valid()' method let's us know if the charge worked.
         * 
         * Some of the issues that can arise after chargine the card are as follows:
         * - Too many API calls to server
         * - Card was Declined
         * - ect...
         * 
         * If the response here is not valid we can redirect back with errors.
         */
        if(!$response->valid()){
            return redirect()->back()->withErrors($response->errors);
        }

        // Get the Customer's Credit Card Details from the response
        $creditcard = $response->creditcard();

        /**
         * Accessing the Credit Card Data
         * ------------------------------------------------
         * We can access the credit card data from the response we got
         * when we charged the customer.
         * 
         * Depending on application requirements, it is not reccomended to store any creditcard data
         * other than the last 4.
         * 
         * @var String last4
         * @var String brand (i.e. Visa, Master Card ect..)
         * @var String exp_year
         * @var String exp_month
         */
        $creditcard->last4;
        $creditcard->brand;
        $creditcard->exp_year;
        $creditcard->exp_month;

        /**
         * Retrieve the Billing Address
         * 
         * @return Array
         */
        $billingAddress = $creditcard->getAddress();

    }

}

Interrupting Charges

Before charging the customer, we can interrupt the charge and perform some business logic by overriding the interruptCharge() method in the User Model.

use Stackout\PaymentGateways\Traits\IsChargeable;

class User extends Model{

    use IsChargeable;

    public function interruptCharge(){

        // Perform some business logic before charging the customer.

    }

}

Some more examples of interrupting the charge of customer could be creating software installation keys, or createing the customer's download link before charging them.

Storing Secret Keys in the Database Securly

If you want to store your public, private, secret and passwords in the database, use the HasDefuseableKeys trait in your controller.

Currently this trait only supports a KEY and VALUE form of a setting. Here is a sample key-value settings migration file:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SettingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /**
         * Migrations to create gateway settings table.
         */
        Schema::create('settings', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->string('key')->index();
            $table->text('value')->nullable();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('settings');
    }
}
?>

The HasDefuseableKeys trait here.

<?php

use Stackout\PaymentGateways\Traits\HasDefusableKeys;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{

    use HasDefusableKeys;

    /**
     * Set fillable proeprty
     */
    protected $fillable = ['value'];

    /**
     * Set dates proeprty
     */
    protected $dates = ['created_at', 'updated_at'];

    /**
     * Set defuseable key identifier
     */
    protected $defuseableKeyIdentifier = '_secret';


}

?>

Admin Panel

Admin panel inclustion is still under development. Please use with caution.

Built With

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Inspiration provided by ProYard.com
  • etc

payment-gateways's People

Contributors

stackout avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.