lzaplata/csobpaymentgateway

ČSOB payment gateway wrapper for Nette Framework.

dev-master 2021-12-09 08:32 UTC

This package is auto-updated.

Last update: 2024-05-09 13:16:57 UTC


README

This is small Nette Framework wrapper for ČSOB payment gateway.

Installation

The easiest way to install library is via Composer.

$ composer require lzaplata/csobpaymentgateway: dev-master

or edit composer.json in your project

"require": {
        "lzaplata/csobpaymentgateway": "dev-master"
}

You have to register the library as extension in config.neon file.

extensions:
        csobPaymentGateway: LZaplata\CsobPaymentGateway\DI\Extension

Now you can set parameters...

csobPaymentGateway:
        merchantId      : *
        sandbox         : true
        currency        : CZK
        privateKey:
            path        : *                        
            password    : *
        publicKey       : *                      

...and autowire library to presenter

use LZaplata\CsobPaymentGateway\Service;

/** @var Service @inject */
public $csobPaymentGateway;

Usage

Create cart instance and add items.

$cart = new Cart();
$cart->setItem(
        $name,                          
        $quantity,                      
        $amount,                        // item price * quantity in lowest currency unit (1 CZK = 100)
        $description
);

Create payment.

$payment = $this->csobPaymentGateway->createPayment(
        $orderNo,          
        $totalAmount,                    // payment price + transport price in lowest currency unit (1 CZK = 100)
        $returnUrl,                  
        $cart,                           // cart instace from step above
        $payOperation                    // type of payment operation - default Payment::NORMAL_PAYMENT
);

Send payment.

$response = $payment->send();

Get payment ID and save it to database.

$payId = $response->getPayId();

Redirect to payment gateway.

$this->sendResponse($response->getRedirectResponse());

...or get redirect url.

$response->getRedirectUrl();

After return from gateway

Get response and check if payment was successful

$response = $this->csobPaymentGateway->getReturnResponse();

if ($response->isOk()) {
    // do something
}

Reverse payment

Sometimes you must reverse your payment

$response = $this->csobPaymentGateway->reversePayment($payId);

if ($response->isReversed()) {
    // do something
}