Giter VIP home page Giter VIP logo

nette-comgate's Introduction

Comgate

Comgate payment gateway

inspired: https://github.com/renat-magadiev/comgate-client , https://github.com/LZaplata/Comgate

comgate info pdf: https://www.comgate.cz/files/informacni-brozura-comgate-payments.pdf

list test payment: https://portal.comgate.cz/cs/testovaci-platby

api: https://platebnibrana.comgate.cz/cz/protokol-api

need set in:

https://portal.comgate.cz/cs/propojeni-obchodu-detail/id/**XXmerchantIdXX**

  • Url zaplacený
  • Url zrušený
  • Url nevyřízený
  • Url pro předání výsledku platby
  • Povolené IP adresy

thanks for code review: @AdamSmid


example url for production:

redirect url (GET redirect from Comgate): https://example.cz/summary/result/${id}?refId=${refId}

status url (POST check from Comgate): https://example.cz/summary/status

Installation

$ composer require geniv/nette-comgate

or

"geniv/nette-comgate": ">=1.0.0"

require:

"php": ">=7.0.0",
"nette/nette": ">=2.4.0",
"renat-magadiev/comgate-client": "^1.0"

Include in application

neon configure:

# comgate
comgate:
    merchantId: "xxxyyy"
    secret: "******"
    sandbox: true

neon configure extension:

extensions:
    comgate: Comgate\Bridges\Nette\Extension

presenter create payment:

/** @var Comgate @inject */
public $comgate;

create payment:

try {
    // process Comgate
    $payment = $this->comgate->createPayment($values['order_price'] * 100, $values['order_id'], $values['email'], $game['name']);
    $payment->setPrepareOnly(true);

    $response = $this->comgate->sendResponse($payment);
    if ($response->isOk()) {
        // edit checkout_id
        $this->model->editItem($id, ['checkout_id' => $response->getTransId()]);
        $this->redirectUrl($response->getRedirectUrl());
    }
} catch (\Comgate\Exception\InvalidArgumentException $e) {
    Debugger::log($e);
    $this->redirect('error');
} catch (\Comgate\Exception\LabelTooLongException $e) {
    Debugger::log($e);
    $this->redirect('error');
}

status payment:

public function actionStatus()
{
    $this->getHttpResponse()->setContentType('application/javascript');
    $request = $this->getHttpRequest();
    if ($request->isMethod('POST')) {
        $transId = $request->getPost('transId');
        $status = $request->getPost('status');
        if ($transId && $status) {
            $item = $this->model->getByCheckoutId($transId);
            if ($item) {
                if ($this->model->editItem((int) $item['id'], ['status' => $status, 'checkout_date%sql' => 'NOW()', 'active' => ($status == PaymentStatus::PAID)])) {
                    $this->sendResponse(new ComgateResponse('code=0&message=OK'));
                }
                $this->sendResponse(new ComgateResponse('code=1&message=SAVE_ERROR'));
            }
            $this->sendResponse(new ComgateResponse('code=1&message=TRANS_ID_NOT_FOUND'));
        }
        $this->sendResponse(new ComgateResponse('code=1&message=MISSING_PARAMETERS'));
    }
    $this->sendResponse(new ComgateResponse('code=1&message=FAIL'));
}

result payment:

public function actionResult(string $id, string $refId)
{
    $item = $this->model->getByCheckoutId($id);
    if ($item) {
        if ($item['status'] == PaymentStatus::PAID) {
            //success
        } else {
            //danger
        }
    }
    $this->redirect('Homepage:');
}

nette-comgate's People

Contributors

geniv avatar

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.