2017 © Pedro Peláez
 

library laravel-amplify

Amplify payments library for laravel

image

dubems/laravel-amplify

Amplify payments library for laravel

  • Sunday, June 24, 2018
  • by nriagudubem
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

laravel-amplify

Laravel Library for integrating Amplify pay, (*1)

Installation

PHP 5.4+ and Composer are required., (*2)

To get the latest version of Laravel Amplify, require like below, (*3)

" composer require dubems/laravel-amplify"

You'll then need to run composer install or composer update to download it and have the autoloader updated., (*4)

Once Laravel Amplify is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key., (*5)

  • Dubems\Amplify\AmplifyServiceProvider::class,

Also, register the Facade like so:, (*6)

'aliases' => [
    ...
    'Amplify' => Dubems\Amplify\Facades\Amplify::class,
    ...
]

Configuration

You can publish the configuration file using this command:, (*7)

php artisan vendor:publish --provider="Dubems\Amplify\AmplifyServiceProvider"

A configuration-file named amplify.php with some defaults will be placed in your config directory:, (*8)

<?php

return [
   /**
    * Merchant ID gotten from your Amplify dashboard
    */

  'merchantId'=> getenv('AMPLIFY_MERCHANT_ID'),

    /**
     *  API Key from amplify dashboard
     */
    'apiKey' => getenv('AMPLIFY_API_KEY'),

    /**
     * Amplify payment Url
     */
    'paymentUrl' => getenv('AMPLIFY_PAYMENT_URL'),

    /**
     * Redirect Url after successful transaction
     */
    'redirectUrl' => getenv('AMPLIFY_REDIRECT_URL')

];

General payment flow

Though there are multiple ways to pay an order, most payment gateways expect you to follow the following flow in your checkout process:, (*9)

1. The customer is redirected to the payment provider

After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to site of the payment provider., (*10)

The redirection is accomplished by submitting a form with some hidden fields. The form must post to the site of the payment provider. The hidden fields minimally specify the amount that must be paid and some other fields, (*11)

2. The customer pays on the site of the payment provider

The customer arrives on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider., (*12)

3. The customer gets redirected back

After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned., (*13)

Usage

Open your .env file and add your public key, secret key, merchant email and payment url like so:, (*14)

AMPLIFY_MERCHANT_ID=XXXXXXX
AMPLIFY_API_KEY=XXXXXX
AMPLIFY_PAYMENT_URL=https://api.amplifypay.com
AMPLIFY_REDIRECT_URL=https://xxxxx

Set up routes and controller methods like so:, (*15)

Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay'); // Laravel 5.1.17 and above

Route::get('/payment/callback', 'PaymentController@handleGatewayCallback');
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Amplify;

class PaymentController extends Controller
{

    /**
     * Redirect the User to Amplify Payment Page
     * @return Url
     */
    public function redirectToGateway()
    {
           return Amplify::getAuthorizationUrl()->redirect();
    }

    /**
     * Get Amplify payment information
     * @return void
     */
     public function handleGatewayCallback()
      {
           $response = Amplify::handlePaymentCallback();
           dd($response);

        // Now you have the payment details,
        // you can store the authorization_code in your db to allow for recurrent subscriptions
        // you can then redirect or do whatever you want
     }
}

Other methods and example usage can be found below, (*16)

    /** Create Subscription */
  public function createSubscription()
    {
        $data = ['planName' => 'Sliver members', 'frequency' => 'Weekly'];
        $response = Amplify::createSubscription($data);
        dd($response);
    }

    /** Delete a particular subscription */  */
    public function deleteSubscription()
    {
        $id = 'xyz';
        $response = Amplify::deleteSubscription($id);
        dd($response);
    }

    /** Update a particular subscription */
 public function updateSubscription()
    {
        $data = ['planName' => 'Gold members', 'frequency' => 'Weekly'];
        $planId = 'xyz';
        $response = Amplify::updateSubscription($planId, $data);
        dd($response);
    }

    /** Get a particular subscription */
public function fetchSubscription()
   {
       $id = 'id';
       $response = Amplify::fetchSubscription($id);
       dd($response);
   }

    /** Fetch all subscription */
public function fetchAllSubscription()
    {
        $allSub = Amplify::fetchAllSubscription();
        dd($allSub);
    }




A sample form will look like so:, (*17)



, (*18)

A cup of coffee ₦ 800
{{-- required --}} {{-- required in naira --}} {{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}} {{-- employ this in place of csrf_field only in laravel 5.0 --}}

, (*19)

PAN = 5060 9905 8000 0217 499
EXPYEAR = 20
EXPMONTH = 04
CVV = 111

If prompted for Amount Validation, Enter 1.10

Todo

  • Add Comprehensive Tests

Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities., (*20)

How can I thank you?

Star the github repo, I'd love the attention! You can also share the link for this repository on Twitter or HackerNews? Spread the word!, (*21)

Don't forget to follow me on twitter!, (*22)

Thanks! Nriagu Chidubem., (*23)

License

The MIT License (MIT). Please see License File for more information., (*24)

The Versions

24/06 2018

dev-master

9999999-dev

Amplify payments library for laravel

  Sources   Download

The Requires

 

The Development Requires

by dubems

23/06 2018

1.0

1.0.0.0

Amplify payments library for laravel

  Sources   Download

The Requires

 

The Development Requires

by dubems