All Projects → Nevercom → php-ipg-ir

Nevercom / php-ipg-ir

Licence: other
IPG (Internet Payment Gateway) manager for Iran Banking System

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-ipg-ir

BankPayment
Persian Bank Payment Server
Stars: ✭ 37 (+42.31%)
Mutual labels:  banking, mellat, saman, parsian
az-iranian-bank-gateways
درگاه اتصال به بانک های ایرانی ( درگاه پرداخت بانک ملی ایران،بانک سامان، بانک ملت، درگاه پرداخت زرین پال و ... ) با استفاده از پایتون
Stars: ✭ 308 (+1084.62%)
Mutual labels:  iran, mellat, saman
sep-pay
Pay.ir Payment Package for Laravel 5.3+
Stars: ✭ 17 (-34.62%)
Mutual labels:  iran, saman
persian-tools-rs
An anthology of a variety of tools for the Persian language in Rust
Stars: ✭ 17 (-34.62%)
Mutual labels:  banking, iran
iran-payment
a Laravel package to handle Internet Payment Gateways for Iran Banking System
Stars: ✭ 16 (-38.46%)
Mutual labels:  iran, saman
powerauth-crypto
PowerAuth - Open-source solution for authentication, secure data storage and transport security in mobile banking.
Stars: ✭ 48 (+84.62%)
Mutual labels:  banking
magento-2-sample-payment-method
Magento 2 Create Payment Method proves that store admin has rights to generate as many payment methods as they need when your store is based on Magento 2 platform, an great era of ecommerce architecture. Depending on the customer's requirement, you probably plug it in your list of the existing payment method. The additional payment methods surel…
Stars: ✭ 53 (+103.85%)
Mutual labels:  gateway
mobizon-node
Biblioteca NodeJS para trabalhar com os serviços Mobizon API
Stars: ✭ 17 (-34.62%)
Mutual labels:  gateway
open-psd2
An open source framework for using banking API's built for PSD2 regulation.
Stars: ✭ 20 (-23.08%)
Mutual labels:  banking
laravel-multi-payment
Laravel online gateway payment package with multi driver support
Stars: ✭ 22 (-15.38%)
Mutual labels:  gateway
cyclos
Cyclos is a payment platform for large businesses and organisations
Stars: ✭ 15 (-42.31%)
Mutual labels:  banking
iotgateway
iot gateway (modbusTCP,RTU,DLT645...to MQTT)
Stars: ✭ 100 (+284.62%)
Mutual labels:  gateway
bunq2ifttt
bunq2IFTTT creates a self-hosted interface between the bunq banking API and IFTTT.
Stars: ✭ 20 (-23.08%)
Mutual labels:  banking
ipns-link
Expose local http-server (web-app) through IPNS
Stars: ✭ 18 (-30.77%)
Mutual labels:  gateway
apisix-python-plugin-runner
Apache APISIX Python plugin runner
Stars: ✭ 17 (-34.62%)
Mutual labels:  gateway
apisix-java-plugin-runner
APISIX Plugin Runner in Java
Stars: ✭ 57 (+119.23%)
Mutual labels:  gateway
vamp2setup
Vamp Lamia Alpha Setup Guide
Stars: ✭ 33 (+26.92%)
Mutual labels:  gateway
freeioe
FreeIOE is a framework for building IOE (Internet Of Everything) edge-computing gateway 开源的边缘计算网关框架. 讨论群: 291292378
Stars: ✭ 77 (+196.15%)
Mutual labels:  gateway
smart-cloud
基于springboot && springcloud的脚手架,支持服务合并部署与拆分部署、接口加解密签名、日志数据 脱敏、接口数据mock、接口文档自动生成、请求幂等校验、接口日志&&sql日志切面打印、分表分库分布式事务、国际化语言等
Stars: ✭ 167 (+542.31%)
Mutual labels:  gateway
IoT-Technical-Guide
🐝 IoT Technical Guide --- 从零搭建高性能物联网平台及物联网解决方案和Thingsboard源码分析 ✨ ✨ ✨ (IoT Platform, SaaS, MQTT, CoAP, HTTP, Modbus, OPC, WebSocket, 物模型,Protobuf, PostgreSQL, MongoDB, Spring Security, OAuth2, RuleEngine, Kafka, Docker)
Stars: ✭ 2,565 (+9765.38%)
Mutual labels:  gateway

IPG (Internet Payment Gateway) manager for Iran Banking System

Install Using Composer

composer require nevercom/iripg

Usage

This library uses MySQL database by default, and a predefined DB Schema. you should create the required tables in order to use this library. (BTW, you can implement your own DB logic using your own schema if you don't want to use the provided class in this library)

-- phpMyAdmin SQL Dump
-- http://www.phpmyadmin.net
--
-- Generation Time: Feb 02, 2018 at 01:24 PM

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
-- --------------------------------------------------------

--
-- Table structure for table `bank_logs`
--

DROP TABLE IF EXISTS `bank_logs`;
CREATE TABLE IF NOT EXISTS `bank_logs` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `pay_id` int(20) NOT NULL,
  `method` varchar(2048) NOT NULL,
  `status_code` int(11) NOT NULL,
  `input` text NOT NULL,
  `output` text NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `pay_id` (`pay_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Table structure for table `bank_transactions`
--

DROP TABLE IF EXISTS `bank_transactions`;
CREATE TABLE IF NOT EXISTS `bank_transactions` (
  `pay_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `transaction_id` bigint(20) NOT NULL,
  `bank_name` varchar(255) NOT NULL,
  `bank_id` tinyint(4) NOT NULL,
  `amount` bigint(20) NOT NULL,
  `reference_id` varchar(256) NOT NULL,
  `authority_id` varchar(255) DEFAULT NULL,
  `status` tinyint(3) NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`pay_id`),
  KEY `transaction_id` (`transaction_id`),
  KEY `reference_id` (`reference_id`(255)),
  KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

First, you need to extend each Gateway class you want to use, and provide authentication info for that Gateway

<?php

namespace Test;

use IPG\Gateways\Mellat\MellatIPG;

class MyMellat extends MellatIPG {
    protected $terminalId   = '123456789';
    protected $userName     = 'username';
    protected $userPassword = 'P4$$w0rD';
}

Now, this class can be used with IPGManager as payment Gateway.

Then, IPGManager should be initialized

$man = new IPGManager(new MyMellat(), new IPGDatabase('username', 'password', 'db_name'));

Next step is to start the payment proccess

$res = $man->startPayment(time(), 10000, 'http://your-site.ir/callback.php');

Then the required data should be POSTed to the targetURL

if (!$res->isIsSuccessful()) {
    echo 'FAILED';
    exit();
}
$location = 'poster.php?data=' . json_encode($res->getData()) . '&url=' . $res->getTargetUrl();
header("Location: {$location}");

Here is a sample poster.php if you need one

<html>
<head>
    <script>
        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex   = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                results = regex.exec(location.search);
            return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
        }

        var jsondata = getParameterByName("data");
        var obj = JSON.parse(jsondata);
        var form = document.createElement("form");
        form.setAttribute("method", "POST");
        form.setAttribute("target", "_self");
        form.setAttribute("action", getParameterByName("url"));

        var len = count = Object.keys(obj).length;

        for (var key in obj) {
            var hiddenField1 = document.createElement("input");
            hiddenField1.setAttribute("name", key);
            hiddenField1.setAttribute("value", obj[key]);

            form.appendChild(hiddenField1);

        }

        form.submit();
        document.body.removeChild(form);

    </script>

</head>
<body></body>
</html>

Now, user is redirected to IPG website. after Payment completetion (or cancelation), the IPG will send the required data to the callback address you have provided.

In the callback file, you need to check that the payment is successful, if so deliver the product. you can reverse the payment if the product can not be delivered

<?php

require_once 'vendor/autoload.php';
use IPG\IPGDatabase;
use IPG\IPGManager;

$man = IPGManager::fromCallback($_REQUEST, new IPGDatabase('user', 'pass', 'db'));

$v = $man->validatePayment($_REQUEST);
if ($v->isValid()) {
    // You should deliver the product now

    // transactionId is the unique id that you provided in the startPayment method
    // and is used to associate a payment transaction to a product order in your database
    // you can use this id to find which order this payment is for, and deliver that product
    $transactionId = $v->getTransactionId();

    if (productDeliverIsSuccessful()) {
        // Optionally you can settle the payment, if you dont it will settled automatically
        $man->settle($v->getPayId(), $v->getReferenceId());
    } else {
        // if any error occured upon delivering the product
        // you can reverse the payment, which will return the money to the customer
        $man->reversal($v->getPayId(), $v->getReferenceId());
    }

} else {
    // you can get the last error after calling each method
    $errorCode    = $man->getErrorCode();
    $errorMessage = $man->getErrorMessage();
}

// render the result page

Adding another Gateway

if you want to use another IPG that is not implemented in this library, you should create a new class and extend it from IPG\Contract\AbstractIPG and provide the logic for that particular IPG.

Not using MySQL or you want to use your own DB Schema and logic

You can extend the IPG\Contract\AbstractIPGDatabaseManager and provide the logic for database interaction.

Operation logging

Operation logging is activated by default, which will log each method call with its input and output. If you wish to turn this feature off, you should call the setLoggingEnabled method.

$man->setLoggingEnabled(false);

License

MIT License

Copyright (c) 2016 Mohammad Azam Rahmanpour

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].