Giter Site home page Giter Site logo

fruitware / victoriabankgateway Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 11.0 426 KB

Victoria bank e-Commerce Gateway merchant interface

PHP 100.00%
bank-integration moldova gateway-client php-library composer-package bank-responses commerce-transactions packagist php

victoriabankgateway's Introduction

Welcome to VictoriaBank Merchant e-Commerce Library ๐Ÿ‘‹

GitHub issues Version Packagist Donate


Packagist package (library) to give any php-based website an access to the interface of VictoriaBank (Republic Of Moldova) that merchant systems use to process credit card based e- commerce transactions using the standard CGI/WWW forms posting method. This interface transparently supports various cardholder authentication protocols such as 3-D Secure and Secure Code as well as legacy unauthenticated SSL commerce transactions.

๐Ÿ  Homepage

Install

composer require fruitware/victoria-bank-gateway

Requirements

  • PHP >= 5.5
  • OpenSSL >=0.9.8

Usage

Step 1. Environment configuration (not required)

You can use one of the composer packages

composer require vlucas/phpdotenv

or

composer require symfony/dotenv

.env file

# Merchant ID assigned by bank
VICTORIA_BANK_MERCHANT_ID=xxxxxxxxxxxxxxx

# Merchant Terminal ID assigned by bank 
VICTORIA_BANK_MERCHANT_TERMINAL=xxxxxxxx

# Merchant primary web site URL
VICTORIA_BANK_MERCHANT_URL='http://example.com'

# Merchant name (recognizable by cardholder)
VICTORIA_BANK_MERCHANT_NAME='Merchant company name'

# Merchant company registered office address
VICTORIA_BANK_MERCHANT_ADDRESS='Merchant address'

# Security options - provided by the bank
VICTORIA_BANK_SECURITY_SIGNATURE_FIRST='0001'
VICTORIA_BANK_SECURITY_SIGNATURE_PREFIX='A00B00C00D00EA864886F70D020505000410'
VICTORIA_BANK_SECURITY_SIGNATURE_PADDING='00'

# Merchant public rsa key
VICTORIA_BANK_MERCHANT_PUBLIC_KEY=public.pem

# Merchant private rsa key
VICTORIA_BANK_MERCHANT_PRIVATE_KEY=private.pem

# The public part of the bank key that P_SIGN is encrypted in the response in PEM format.
VICTORIA_BANK_MERCHANT_BANK_PUBLIC_KEY=victoria_pub.pem

# Default Merchant shop timezone
# Used to calculate the timezone offset sent to VictoriaBank
VICTORIA_BANK_MERCHANT_TIMEZONE_NAME='Europe/Chisinau'

# Merchant shop 2-character country code. 
# Must be provided if merchant system is located 
# in a country other than the gateway server's country. 
VICTORIA_BANK_MERCHANT_COUNTRY_CODE=MD

# Default currency for all operations: 3-character currency code 
VICTORIA_BANK_MERCHANT_DEFAULT_CURRENCY=MDL

# Default forms language
# By default are available forms in en, ro, ru. 
# If need forms in another languages please contact gateway
# administrator
VICTORIA_BANK_MERCHANT_DEFAULT_LANGUAGE=ro

Step 2. Init Gateway client

Init Gateway client through configureFromEnv method

<?php

use Fruitware\VictoriaBankGateway\VictoriaBankGateway;

$victoriaBankGateway = new VictoriaBankGateway();

$certDir = '/path/to/cert/dir';
$victoriaBankGateway
    ->configureFromEnv($certDir)
;

Init Gateway client manually

You can reproduce implementation of the configureFromEnv() method

Step 3. Request payment authorization - redirects to the banks page

<?php

use Fruitware\VictoriaBankGateway\VictoriaBankGateway;
$backRefUrl = getenv('VICTORIA_BANK_MERCHANT_URL').'/after-payment/';

/** @var VictoriaBankGateway $victoriaBankGateway */
$victoriaBankGateway
    ->requestAuthorization($orderId = 1, $amount = 1, $backRefUrl, $currency = null, $description = null, $clientEmail = null, $language = null)
;

Step 4. Receive bank responses - all bank responses are asynchronous server to server and are handled by same URI

<?php

use Fruitware\VictoriaBankGateway\VictoriaBankGateway;
use Fruitware\VictoriaBankGateway\VictoriaBank\Exception;
use Fruitware\VictoriaBankGateway\VictoriaBank\Response;
use Fruitware\VictoriaBankGateway\VictoriaBank\AuthorizationResponse;

/** @var VictoriaBankGateway $victoriaBankGateway */
$bankResponse = $victoriaBankGateway->getResponseObject($_POST);

if (!$bankResponse->isValid()) {
    throw new Exception('Invalid bank Auth response');
}

switch ($bankResponse::TRX_TYPE) {
    case VictoriaBankGateway::TRX_TYPE_AUTHORIZATION:
        $amount         = $bankResponse->{Response::AMOUNT};
        $bankOrderCode  = $bankResponse->{Response::ORDER};
        $rrn            = $bankResponse->{Response::RRN};
        $intRef         = $bankResponse->{Response::INT_REF};

        #
        # You must save $rrn and $intRef from the response here for reversal requests
        #

        # Funds locked on bank side - transfer the product/service to the customer and request completion
        $victoriaBankGateway->requestCompletion($bankOrderCode, $amount, $rrn, $intRef, $currency = null);
        break;

    case VictoriaBankGateway::TRX_TYPE_COMPLETION:
        # Funds successfully transferred on bank side
        break;

    case VictoriaBankGateway::TRX_TYPE_REVERSAL:
        # Reversal successfully applied on bank size
        break;

    default:
        throw new Exception('Unknown bank response transaction type');
}

Step 5. Request reversal (refund)

$rrn and $intRef must be saved on the step 4

<?php

use Fruitware\VictoriaBankGateway\VictoriaBankGateway;

/** @var VictoriaBankGateway $victoriaBankGateway */
$victoriaBankGateway
    ->requestReversal($orderId = 1, $amount = 1, $rrn = 'xxx', $intRef = 'yyy', $currency = null)
;

Author

๐Ÿ‘ค Lovely handcrafted by Fruitware team

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a โญ if this project helped you!

Donate

victoriabankgateway's People

Contributors

alexminza avatar keriat avatar ruscon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

victoriabankgateway's Issues

Add detailed documentation and references to the terms and conditions of VB e-commerce

To make sure the library is easy-to-use and it's fit some industry-grade requirements ๐Ÿค˜ it definitely needs:

  • Detailed documentation (e.g. wiki);
  • Examples of how to work with it;
  • Some community-call to build an open-source list of libraries, develop and maintain it for the good of the society;
  • references to the bank-specific services;
  • contacts of the commercial and technical support teams of the bank (need some help with bank-connection, please advised if any);
  • links to the VB's website (like this one);
  • some creative touch of the Fruitware's Design Department to re-born this repository from some internal-use piece of code into the industry-grade product;

๐Ÿ‘จโ€๐Ÿ’ป Will release it in next couple of weeks (related milestone attached)

Class 'Fruitware\VictoriaBankGateway\VictoriaBank\Request' not found

When initializing the gateway client according to the demo code from README.md using manual procedure an unhandled exception is thrown:

  1. Installation - via composer
  2. Step 2. Init Gateway client
  3. Init Gateway client manually
  4. calling VictoriaBankGateway->setSecurityOptions

Fatal error: Uncaught Error: Class 'Fruitware\VictoriaBankGateway\VictoriaBank\Request' not found in .../vendor/fruitware/victoria-bank-gateway/src/VictoriaBankGateway.php:334

Stack trace: Fruitware\VictoriaBankGateway\VictoriaBankGateway->setSecurityOptions(...

Allow setting test gateway url

Victoriabank have introduced a test gateway for new clients to test and debug their integrations before going live with the current production gateway: https://ecomt.victoriabank.md/cgi-bin/cgi_link

To allow users to use the new test gateway a new option to set the gateway url should be introduced.

At the VictoriaBankGateway class level? VictoriaBankGateway->setGatewayUrl(gatewayUrl)

Code upgrade

To make sure the code is actual and php7-ready code-review should be done.

  • Extend composer's description and add support of all features
  • Make code-review and fix any outdated ways of coding
  • choose some PSR-standart for the library and format the code accordingly

Victoriabank test payment gateway has incomplete SSL certificate chain and breaks onboarding tests

https://www.ssllabs.com/ssltest/analyze.html?d=ecomt.victoriabank.md&latest

Screenshot 2019-11-20 at 11 48 26

Screenshot 2019-11-20 at 11 48 34

Compare to the production gateway configuration: https://www.ssllabs.com/ssltest/analyze.html?d=egateway.victoriabank.md&latest

Screenshot 2019-11-20 at 11 52 11

The problem arises only for the Complete/Reverse payments steps because they use the PHP file_get_contents function to perform the web request, while the Authorize functionality is performed by the user browser, which will fallback and complete the certificate chain in such cases.

A way to disable SSL verification for test gateway only is needed to allow new users to perform the onboarding technical tests and promote their project into production payment gateway.

This could be achieved by conditionally (only in DEBUG/TEST modes) adding the following parameters on the request() function stream context options for the CompletionRequest and ReversalRequest classes:

'ssl' => [
    "verify_peer" => false,
    "verify_peer_name" => false,
]

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.