slevomat/csob-gateway

CSOB payment gateway client

3.1.0 2016-10-03 11:21 UTC

README

Build Status Build status Code Coverage Scrutinizer Code Quality Latest Stable Version Composer Downloads

This repository provides a client library for ČSOB Payment Gateway.

Library supports all endpoints of eAPI 1.6 and response extensions.

  • Version 3.* supports eAPI 1.6. If you need eAPI 1.5, use version 2.*.
  • Version 2.* supports PHP 7 or higher only. If you need support for PHP 5.6, use version 1.*.

Installation

The best way to install slevomat/csob-gateway is using Composer:

> composer require slevomat/csob-gateway

Usage

First you have to initialize the payment in gateway and redirect customer to its interface.

WARNING: Please note, that all the prices are in hundredths of currency units. It means that when you wanna init a payment for 1.9 EUR, you should pass here the integer 190.

$apiClient = new ApiClient(
	new CurlDriver(),
	new CryptoService(
		$privateKeyFile,
		$bankPublicKeyFile
	),
	'https://api.platebnibrana.csob.cz/api/v1.6/'
);

$requestFactory = new RequestFactory('012345');

// cart has to have at least 1 but most of 2 items
$cart = new Cart(Currency::get(Currency::EUR));
$cart->addItem('Nákup', 1, 1.9 * 100);

$paymentResponse = $requestFactory->createInitPayment(
	123,
	PayOperation::get(PayOperation::PAYMENT),
	PayMethod::get(PayMethod::CARD),
	true,
	$returnUrl,
	HttpMethod::get(HttpMethod::POST),
	$cart
)->send($apiClient);
$payId = $paymentResponse->getPayId();

$processPaymentResponse = $requestFactory->createProcessPayment($payId)->send($apiClient);

// redirect to gateway
header('Location: ' . $processPaymentResponse->getGatewayLocationUrl());

After customer returns from gateway, he is redirected to $returnUrl where you have to process the payment.

$paymentResponse = $requestFactory->createReceivePaymentRequest()->send($apiClient, $_POST);
if ($paymentResponse->getPaymentStatus()->equalsValue(PaymentStatus::S7_AWAITING_SETTLEMENT)) {
	// payment was successful!
}

Please refer to the CSOB documentation and learn what states you should to check, they are all available as PaymentStatus::S* constants.

Custom ApiClientDriver

API calls are made through ApiClientDriver interface. Library contains two default implementations of driver - CurlDriver and GuzzleDriver. You can also create your own driver by implementing the ApiClientDriver interface, and passing it to ApiClient constructor.

CurlDriver communicates via curl PHP extension, GuzzleDriver uses guzzlehttp/guzzle library. If you want to use GuzzleDriver you need to require guzzlehttp/guzzle package in your composer.json.