Ejemplo n.º 1
0
<?php

require_once dirname(__FILE__) . "/config.php";
$client = new PayApiClient(INVIPAY_API_URL, INVIPAY_API_KEY, INVIPAY_SIGNATURE_KEY);
$paymentId = null;
Logger::info('Getting object received through callback');
$data = $client->paymentOperationStateFromCallbackPost();
Logger::debug('Received from callback: {0}', $data);
$paymentId = $data->getPaymentId();
if ($data->getDataType() == 'PaymentDetails') {
    $file = dirname(__FILE__) . "/repository/" . $paymentId;
    $newData = array('version' => 0, 'data' => $data);
    if (file_exists($file)) {
        $oldData = unserialize(file_get_contents($file));
        if (!empty($oldData)) {
            $newData['version'] = $oldData['version'] + 1;
        }
    }
    Logger::info("Putting new data into repository {0}:\r\n{1}", $file, $newData);
    file_put_contents($file, serialize($newData));
} else {
    if ($data->getDataType() == 'PaymentOperationFinalizationInfo') {
        // Call transactions api to confirm this event and fetch full transaction details
        $transactionsApiClient = new TransactionsApiClient(INVIPAY_API_URL, INVIPAY_API_KEY, INVIPAY_SIGNATURE_KEY);
        $transactionDetails = $transactionsApiClient->getTransaction($data->getData()->getTransactionId());
        $file = dirname(__FILE__) . "/repository/" . $paymentId . "_finalization_info.txt";
        Logger::info("Putting transaction data into file {0}\r\n{1}", $file, $transactionDetails);
        file_put_contents($file, Logger::format('{0}', $transactionDetails));
    } else {
        if ($data->getDataType() == 'ApiOperationException') {
            $file = dirname(__FILE__) . "/repository/" . $paymentId . "_exception.txt";
Ejemplo n.º 2
0
<?php

require_once 'config.php';
session_start();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'index';
$apiClient = new PayApiClient(INVIPAY_API_URL, INVIPAY_API_KEY, INVIPAY_SIGNATURE_KEY);
if ($action == 'index') {
    include DIR_VIEWS . '/index.php';
} else {
    if ($action == 'checkout') {
        $request = new PaymentStartRequest();
        $request->setStatusUrl(URL_ROOT . '/status_listener.php');
        $request->setDocumentNumber(uniqid('Order/'));
        $request->setBuyerGovId($_REQUEST['buyer_gov_id']);
        $request->setPriceGross($_REQUEST['price_gross']);
        $request->setSubscribedEvents(PayOperationEvents::EMPLOYEES_LIST_CHANGE | PayOperationEvents::PAYMENT_CONFIRMATION);
        $paymentInfo = $apiClient->startPayment($request);
        $paymentId = $paymentInfo->getPaymentId();
        $data = array('version' => 0, 'data' => null);
        file_put_contents(DIR_REPOSITORY . '/' . $paymentId, serialize($data));
        $_SESSION[SESSION_KEY] = $paymentId;
        header('Location: ' . URL_ROOT . '/index.php?action=paygate');
    } else {
        if ($action == 'paygate') {
            $paymentId = $_SESSION[SESSION_KEY];
            $paymentOperationData = unserialize(file_get_contents(DIR_REPOSITORY . '/' . $paymentId));
            $paymentData = null;
            $paymentDataVersion = $paymentOperationData !== null ? $paymentOperationData['version'] : 0;
            if ($paymentOperationData !== null && $paymentOperationData['data'] !== null) {
                $paymentData = $paymentOperationData['data']->getData();
            }