コード例 #1
0
require_once dirname(__FILE__) . "/../../PaygateApiClient.class.php";
require_once dirname(__FILE__) . "/../config.php";
$client = new PaygateApiClient(INVIPAY_API_URL, INVIPAY_API_KEY, INVIPAY_SIGNATURE_KEY);
$repository = dirname(__FILE__) . "/repository/";
$payments = scandir($repository);
Logger::info('Scanning payments repository');
foreach ($payments as $paymentFile) {
    if ($paymentFile != '.' && $paymentFile != '..') {
        Logger::info('Found payment data {0}', $paymentFile);
        $paymentData = unserialize(file_get_contents($repository . $paymentFile));
        $paymentId = $paymentData->getPaymentId();
        Logger::info('Payment {0} has status {1}', $paymentId, $paymentData->getStatus());
        if ($paymentData->getStatus() == PaymentRequestStatus::COMPLETED) {
            Logger::info('Finalizing payment {0}', $paymentId);
            $request = new PaymentManagementData();
            $request->setPaymentId($paymentId);
            $request->setDoConfirmDelivery(true);
            $conversionData = new OrderToInvoiceData();
            $conversionData->setInvoiceDocumentNumber("TestInvoice/1/2/3/" . uniqid());
            $conversionData->setIssueDate(date('Y-m-d', time()));
            $conversionData->setDueDate(date('Y-m-d', time() + 14 * 24 * 60 * 60));
            $request->setConversionData($conversionData);
            $document = new FileData();
            $document->setFromFile(dirname(__FILE__) . '/../test.pdf');
            $request->setDocument($document);
            $result = $client->managePayment($request);
            Logger::info('Result is: {0}', $result);
        }
    }
}
コード例 #2
0
Logger::info('Searching for an order transaction');
$filter = new TransactionsFilter();
$filter->setSide(TransactionSide::SALE);
$filter->setType(TransactionType::ORDER);
$result = $client->listTransactions($filter);
$ordersCount = count($result);
Logger::info('Found {0} orders', $ordersCount);
if ($ordersCount > 0) {
    $orderId = $result[0]->getId();
    Logger::info('Using order {0} for further processing', $orderId);
}
// Convert order to invoice
if ($orderId !== null) {
    Logger::info('Converting order {0} into invoice', $orderId);
    $pdf = new FileData();
    $pdf->setFromFile(dirname(__FILE__) . '/../test.pdf');
    $data = new OrderConversionData();
    $data->setTransactionId($orderId);
    $data->setInvoiceDocumentNumber("Converted from order " . uniqid());
    $data->setIssueDate(date('Y-m-d', time()));
    $data->setDueDate(date('Y-m-d', time() + 30 * 24 * 60 * 60));
    $data->setInvoiceDocument($pdf);
    $result = $client->convertOrderToInvoice($data);
    Logger::info('Result is: {0}', $result);
}
// Confirm delivery
if ($orderId !== null) {
    Logger::info('Confirming delivery for transaction {0}', $orderId);
    $result = $client->confirmDelivery($orderId);
    Logger::info('Result is: {0}', $result);
}