简体   繁体   中英

Implement 3rd party class in Laravel 4.2

I am trying to integrate a middle east based payment gateway for payments via debit card in a Laravel project for first time. I have used this payment gateway in custom PHP projects in past but facing issues integrating it in a Laravel project.

Basically this payment gateway files consist of a class called e24PaymentPipe and a resource/resource.cgn . The brief structure of these two files is as follows:

e24PaymentPipe

Full class source code: here !

class e24PaymentPipe {
    var $SUCCESS = 0;
    var $FAILURE = -1;
    var $BUFFER = 2320;
    var $strIDOpen = "<id>";
    var $strPasswordOpen = "<password>";
    ..... some more vars ......

    function e24PaymentPipe() {
        $this->webAddress = "";
        $this->port = "443";
        $this->id = "";
        $this->password = "";
        ... some more vars
    }

    function getWebAddress() {
        return webAddress;
    }

    function setWebAddress($s) {
        $this->webAddress = $s;
    }

    ... sme more functions ...
}

resource/resource.cgn

This file contains some strings:

13d6 acd1 35e2 f54d 2dab 7d9d 63bc 9bb2
6f8f 1fd9 2fc2 aa41 4a8e 873e 98a6 2304

Implementation

In the page where the Payment button will be displayed, the following code needs to be added:

// BENEFIT PAYMENT Code 

require('e24PaymentPipe.inc.php');
date_default_timezone_set('Asia/Bahrain');

$accATM = new e24PaymentPipe;
$accATM->resourcePath = 'resource/';
$accATM->alias = 'SECRET_ALIAS_OF_MERCHANT';
$accATM->action = '1';
$accATM->currency = '048';
$accATM->language = 'USA';
$accATM->amt = 'PRICE_HERE';
$accATM->responseURL = '/response.php';
$accATM->errorURL = '/error_page.php';
$accATM->trackId = date('YmdHis');

$TransVal = $accATM->performPaymentInitialization();
$varRawResponse = $accATM->getRawResponse();
$varPaymentId = $accATM->getPaymentId();
$varPaymentPage = $accATM->getPaymentPage();
$varErrorMsg = $accATM->getErrorMsg();

HTML FORM (that displays button which will take user to Payment Gateways page to complete debit card payments, upon completion user will be redirected back to site)

<!-- Benefit Debit Card Payment Button -->
<form action="<?php echo $varPaymentPage; ?>" method="get" class="pull-left" style="margin-left:20px;">
    <input id="PaymentID" name="PaymentID" type="hidden" value="<?php echo $varPaymentId; ?>" />
    <input type="submit" class="btn btn-warning btn-lg" value="Debit Card Payment" />
</form>

I am new to Laravel, this is one of my first projects. Please help, Thanks.

EDIT

By the way, here is GitHub repo for this e24PaymentPipe class, you can view full code of this class and its implementation here:

https://github.com/TigerWolf/e24PaymentPipe-php

Hope this could help.


@Angel M. here's what I'm doing:

Controller Function

public function payment() {
    $accATM = new \e24PaymentPipe;

    return View::make('site.payment', compact('accATM'));
}

payment.blade.php

<?php
$accATM->resourcePath = app_path().'/views/site/resource';
$accATM->alias = 'SECRET_ALIAS_HERE';
$accATM->action = '1';
$accATM->currency = '048';
$accATM->language = 'USA';
$accATM->amt = $participant->price;
$accATM->responseURL = '/response.php';
$accATM->errorURL = '/error_page.php';
$accATM->trackId = date('YmdHis');

$accATM->udf2 = 'ud2465665';
$accATM->udf3 = 'ud3231213';
$accATM->udf4 = 'ud4785653';
$accATM->udf5 = 'ud5554788';

$TransVal = $accATM->performPaymentInitialization();
$varRawResponse = $accATM->getRawResponse();
$varPaymentId = $accATM->getPaymentId();
$varPaymentPage = $accATM->getPaymentPage();
$varErrorMsg = $accATM->getErrorMsg();

?>

!-- Benefit Debit Card Payment -->
<form action="<?php echo $varPaymentPage; ?>" method="get" class="pull-left" style="margin-left:20px;">
    <input id="PaymentID" name="PaymentID" type="hidden" value="<?php echo $varPaymentId; ?>" />
    <input type="submit" class="btn btn-warning btn-lg" value="Debit Card Payment" />
</form>

Create e24PaymentPipe in your App root directory
Open composer.json

 "classmap": [
     "database",
     "app/e24PaymentPipe" <-- add this line to classmap
  ],

run composer dump-autoload; in your controller

public function __construct(){
    $e24payment = new \e24PaymentPipe;  
}

I would add the payment class in special folder like payments inside app folder, or whatever you would prefer.

Then would add the path in composer to autoload section:

   "autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
      ... etc..
        "app/payments"
    ],

and then run

composer dump-autoload, so the file would be loaded and then add form and the rest of the code into the appropriate class/views.

in the controller when you will manage the payment (I don't know which one you will use)

inside a method add: $payment = new e24PaymentPipe;

public function payment()
{
  $accATM = new e24PaymentPipe;
    $accATM->resourcePath = 'resource/';
    $accATM->alias = 'SECRET_ALIAS_OF_MERCHANT';
    $accATM->action = '1';
    $accATM->currency = '048';
    $accATM->language = 'USA';
    $accATM->amt = 'PRICE_HERE';
    $accATM->responseURL = '/response.php';
    $accATM->errorURL = '/error_page.php';
    $accATM->trackId = date('YmdHis');

    $TransVal = $accATM->performPaymentInitialization();
    $varRawResponse = $accATM->getRawResponse();
    $varPaymentId = $accATM->getPaymentId();
    $varPaymentPage = $accATM->getPaymentPage();
    $varErrorMsg = $accATM->getErrorMsg();

  return View::make('myfolder/payment')->with(... here you will list array of data you will send to the view...);
}

where myfolder/payment will be myfolder/payment.blade.php file

EDIT: try to send:

View::make('site.payment')->with('accATM',$accATM);

and in view you should use something like:

check in view, if data were sent:

@if($accATM) ...

I suggest you create a custom service provider like this

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class YourServiceProvider extends ServiceProvider
{
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
        $this->app->bind('YOUR_CUSTOM_CLASS_NAMESPACE_PATH');
    }
}

Then register your service provider in your config/app.php file

YOUR_SERVICE_PROVIDER_NAMESPACE_YOU_CREATED::class,

Then in anywhere you can use your YOUR_CUSTOM_CLASS like it,

$class = new YOUR_CUSTOM_CLASS();//use use to import the class namespace path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM