Componette

Componette

slevomat

slevomat / csob-gateway 6.2.0

Client library for CSOB card payment gateway

download-cloud-line composer require slevomat/csob-gateway

CSOB gateway

Build status Code coverage Latest Stable Version Composer Downloads

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

Library supports all endpoints of eAPI 1.9 except NEJsplátku (loan@shop). Pull requests are welcome.

Older available versions (not actively maintained):

  • Version 5.* supports PHP 7.2 and eAPI 1.8
  • Version 4.* supports PHP 7.2 and eAPI 1.7
  • Version 3.* supports PHP 7 and eAPI 1.6.
  • Version 2.* supports PHP 7 and eAPI 1.5.
  • Version 1.* supports PHP 5.6 and eAPI 1.5.

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.8'
);

$requestFactory = new RequestFactory('012345');

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

$customer = new Customer(
    'Jan Novák',
    'jan.novak@example.com',
    mobilePhone: '+420.800300300',
    customerAccount: new CustomerAccount(
        new DateTimeImmutable('2022-01-12T12:10:37+01:00'),
        new DateTimeImmutable('2022-01-15T15:10:12+01:00'),
    ),
    customerLogin: new CustomerLogin(
        CustomerLoginAuth::ACCOUNT,
        new DateTimeImmutable('2022-01-25T13:10:03+01:00'),
    ),
);

$order = new Order(
    OrderType::PURCHASE,
    OrderAvailability::NOW,
    null,
    OrderDelivery::SHIPPING,
    OrderDeliveryMode::SAME_DAY,
    addressMatch: true,
    billing: new OrderAddress(
        'Karlova 1',
        null,
        null,
        'Praha',
        '11000',
        null,
        Country::CZE,
    ),
);

$paymentResponse = $requestFactory->createInitPayment(
	123,
	PayOperation::PAYMENT,
	PayMethod::CARD,
	true,
	$returnUrl,
	HttpMethod::POST,
	$cart,
    $customer,
    $order,
    'some-base64-encoded-merchant-data',
    '123',
    Language::CZ,
    1800,
    1,
    2,
)->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.

try {
    $receivePaymentResponse = $requestFactory->createReceivePaymentRequest()->send($apiClient, $_POST /* $_GET */);
    if ($receivePaymentResponse->getPaymentStatus() === PaymentStatus::S7_AWAITING_SETTLEMENT) {
        // payment was successful!
    }
} catch (VerificationFailedException | InvalidSignatureException $e) {
    // request was not send from csob api
}

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.

  • 6.2.0 6.2.0

    • add low value payment method option #70
  • 6.1.0 6.1.0

    • Added new language options to googlepay/init, applepay/init and oneclick/init [#68]
  • 6.0.2

    Fix mallpay VAT ID validation #63

  • 6.0.1

    • fixed gateway signature validation when fields contains null - payment/refund - #60
  • 6.0.0 6.0.0

    PHP 8.1 & Latest version of ČSOB eAPI 1.9

    BC breaks

    • Minimal PHP version is now 8.1
    • Enums are now native. Instead of Enum::get(Enum::FOO) use just Enum::FOO
    • Major changes is payment processing required by new ČSOB API and 3D Secure 2.2. See ČSOB documentation and related pull request for details.
  • 5.3.1

    Fixed - mallpay item can have negative price #57

  • 5.3.0

    Implemented payment by Google Pay and mallpay

  • 5.2.1

    • Bug fix: Add missing merchantData element to oneclick/init request #48
  • 5.2.0

    Due to lack of PHP 8 support in consistence/consistence, we replaced it with our fork slevomat/consistence. Fork is replacing upstream package with full compatibility.

  • 5.1.0 5.1.0

    Allow installation on PHP 8

  • 5.0.0

    Ported to latest ČSOB eAPI 1.8 - contains Apple Pay, custom payment and some changes is request parameters - see ČSOB wiki https://github.com/csob/paymentgateway/wiki

    BC breaks:

    • Removed description from payment/init
    • Added clientIp to oneclick/init
    • Changed namespace of request related to one click payment
    • Payment button request was changed significantly, see ČSOB documentation for new parameters description and also changed flow of payment processing
  • 4.3.0 4.3.0

    • PHP 7.2+ is required
    • Updated consistence/consistence
  • 4.2.0

    Added more supported currencies 5b932a7

  • 4.1.0

    • added response time logging #33
  • 4.0.0

    • Requires PHP 7.1 - #31
    • Ported to latest ČSOB eAPI v1.7 (masterpass@shop, ČSOB and Era payment buttons) - #32
    • BC break enums now use consistence/consistence - instead of new Currency (Currency::CZK) use Currency::get(Currency::CZK) - #28
    • Fixed expiration parsing in MaskedCardNumberExtension - 16a3d2e
  • 3.1.0

    Added response headers to logging - #23
    Added optional parameter totalAmount to payment/close request - #22

  • 3.0.1

    Fixed keys order for signature verification in MaskedCardNumberExtension

  • 3.0.0

  • 2.2.0

    • Support for request/response logging via PSR-3 Log interface
    • Fixed merchant data field length check
  • 2.1.0 2.1.0

  • 2.0.0 2.0.0

    • Usage of PHP 7 scalar typehints a return types and strict type checks
    • Drop support for PHP 5.6
  • 1.0.1

    • added payment result code 999 and HTTP response code 502 to enums
    • fixed handling of expired or unknown payment in payment/process API endpoint - see csob/paymentgateway#135
  • 1.0.0

    Initial public release

price-tag-2-line

Badges

guide-fill

Dependencies

ext-openssl (*)
php (^7.2)
Componette Componette felix@nette.org