Skip to content

Commit

Permalink
test all case activatePaymentNotice REQ/RESP
Browse files Browse the repository at this point in the history
  • Loading branch information
esposimo committed Mar 12, 2024
1 parent 67f6178 commit 5606cd1
Show file tree
Hide file tree
Showing 14 changed files with 2,036 additions and 50 deletions.
22 changes: 13 additions & 9 deletions src/src/crawler/paymentlist/req/activatePaymentNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ public function runCreatePayment(int $index = 0): array

$cache_key = base64_encode(sprintf('payment_%s_%s_%s', $date_x_cache, $iuv, $pa_emittente));
$cache_value = [
'date_event' => $date_event,
'id' => $last_inserted_id,
'iuv' => $iuv,
'pa_emittente' => $pa_emittente
'date_event' => $date_event,
'id' => $last_inserted_id,
'iuv' => $iuv,
'pa_emittente' => $pa_emittente,
'transfer_added' => false,
'amount_update' => false
];
$this->addValueCache($cache_key, $cache_value);

Expand Down Expand Up @@ -246,11 +248,13 @@ public function runCreateAttempt(int $index = 0): array

$cache_key = base64_encode(sprintf('attempt_%s_%s_%s_%s', $date_x_cache, $iuv, $pa_emittente, $token));
$cache_value = [
'date_event' => $date_event,
'id' => $last_inserted_id,
'iuv' => $iuv,
'pa_emittente' => $pa_emittente,
'token_ccp' => $token
'date_event' => $date_event,
'id' => $last_inserted_id,
'iuv' => $iuv,
'pa_emittente' => $pa_emittente,
'token_ccp' => $token,
'transfer_added' => false,
'amount_update' => false
];
$this->addValueCache($cache_key, $cache_value);

Expand Down
120 changes: 99 additions & 21 deletions src/src/crawler/paymentlist/resp/activatePaymentNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public function runCreatePayment(int $index = 0): array
'date_event' => $date_event,
'id' => $last_inserted_id,
'iuv' => $iuv,
'pa_emittente' => $pa_emittente
'pa_emittente' => $pa_emittente,
'transfer_added' => false,
'amount_update' => false
];
$this->addValueCache($cache_key, $cache_value);

Expand Down Expand Up @@ -251,7 +253,7 @@ public function runCreateAttempt(int $index = 0): array
$transaction_details->setNewColumnValue('date_event', $date_event);
$transaction_details->setPaTransfer($this->getEvent()->getMethodInterface()->getTransferPa($i, 0));
$transaction_details->setAmountTransfer($this->getEvent()->getMethodInterface()->getTransferAmount($i, 0));
$transaction_details->setTransferIban($this->getEvent()->getMethodInterface()->getTransferAmount($i, 0));
$transaction_details->setTransferIban($this->getEvent()->getMethodInterface()->getTransferIban($i, 0));
$transaction_details->setIdTransfer($this->getEvent()->getMethodInterface()->getTransferId($i, 0));
$transaction_details->insert();
DB::statement($transaction_details->getQuery(), $transaction_details->getBindParams());
Expand All @@ -267,7 +269,8 @@ public function runCreateAttempt(int $index = 0): array
'iuv' => $iuv,
'pa_emittente' => $pa_emittente,
'token_ccp' => $token,
'transfer_add' => true
'transfer_add' => true,
'amount_update' => true
];
$this->addValueCache($cache_key, $cache_value);

Expand Down Expand Up @@ -303,20 +306,69 @@ public function runPaymentAlreadyEvaluated(int $index = 0): void
$cached_attempts = []; // fix per la get dalla cache
}

foreach($cached_attempts as $attempt)
foreach($cached_attempts as $key => $attempt)
{
$id = $attempt['id'];
$date = $attempt['date_event'];
$transfer_added = $attempt['transfer_added'];
$amount_import = $attempt['amount_update'];

if (!$this->getEvent()->getMethodInterface()->isFaultEvent())
{
if ($amount_import === false)
{
// se non è un faultCode, e non ho aggiornato l'importo, lo faccio
$transaction = new Transaction($this->getEvent()->getInsertedTimestamp(), $attempt);
$transaction->setNewColumnValue('importo', $this->getEvent()->getMethodInterface()->getImportoTotale());
$transaction->update();
DB::statement($transaction->getQuery(), $transaction->getBindParams());
$attempt['amount_update'] = true;
}

if ($transfer_added === false)
{
for($i=0;$i<$this->getEvent()->getTransferCount($index);$i++)
{
$transaction_details = new TransactionDetails($this->getEvent()->getInsertedTimestamp());
$transaction_details->setFkPayment($id);
$transaction_details->setNewColumnValue('date_event', $date_event);
$transaction_details->setPaTransfer($this->getEvent()->getMethodInterface()->getTransferPa($i, 0));
$transaction_details->setAmountTransfer($this->getEvent()->getMethodInterface()->getTransferAmount($i, 0));
$transaction_details->setTransferIban($this->getEvent()->getMethodInterface()->getTransferIban($i, 0));
$transaction_details->setIdTransfer($this->getEvent()->getMethodInterface()->getTransferId($i, 0));
$transaction_details->insert();
DB::statement($transaction_details->getQuery(), $transaction_details->getBindParams());
$attempt['transfer_added'] = true;
}
}
}

$cached_attempts[$key] = $attempt; // aggiorno la cache con le nuove info (se aggiornate) di aggiunta transfer e aggiornamento importo


$workflow = new Workflow($this->getEvent()->getInsertedTimestamp());
$workflow->setNewColumnValue('date_event', $date);
$workflow->setFkPayment($id);
$workflow->setEventTimestamp($this->getEvent()->getInsertedTimestamp());
$workflow->setEventId($this->getEvent()->getUniqueId());
$workflow->setFkTipoEvento(2);
if (!is_null($this->getEvent()->getMethodInterface()->getFaultCode()))
{
$workflow->setFaultCode($this->getEvent()->getMethodInterface()->getFaultCode());
}
$workflow->insert();
DB::statement($workflow->getQuery(), $workflow->getBindParams());
}

if (count($cached_attempts) > 0)
{
// se ho valori in cache , la aggiorno
$this->delFromCache($cache_key);
foreach($cached_attempts as $v)
{
$this->addValueCache($cache_key, $v);
}
}
}

/**
Expand All @@ -338,31 +390,46 @@ public function runAttemptAlreadyEvaluated(int $index = 0): void
$cached_attempts = [];
}

foreach($cached_attempts as $attempt)
foreach($cached_attempts as $key => $attempt)
{
// scorrro tutta la cache per questa transazione
$id = $attempt['id'];
$date = $attempt['date_event'];
$transfer_added = $attempt['transfer_added'];
$amount_import = $attempt['amount_update'];


if (!$this->getEvent()->getMethodInterface()->isFaultEvent())
{
$transaction = new Transaction($this->getEvent()->getInsertedTimestamp(), $attempt);
$transaction->setNewColumnValue('importo', $this->getEvent()->getMethodInterface()->getImportoTotale());
$transaction->update();
DB::statement($transaction->getQuery(), $transaction->getBindParams());
if ($amount_import === false)
{
// se non è un faultCode, e non ho aggiornato l'importo, lo faccio
$transaction = new Transaction($this->getEvent()->getInsertedTimestamp(), $attempt);
$transaction->setNewColumnValue('importo', $this->getEvent()->getMethodInterface()->getImportoTotale());
$transaction->update();
DB::statement($transaction->getQuery(), $transaction->getBindParams());
$attempt['amount_update'] = true;
}

if ($transfer_added === false)
{
for($i=0;$i<$this->getEvent()->getTransferCount($index);$i++)
{
$transaction_details = new TransactionDetails($this->getEvent()->getInsertedTimestamp());
$transaction_details->setFkPayment($id);
$transaction_details->setNewColumnValue('date_event', $date_event);
$transaction_details->setPaTransfer($this->getEvent()->getMethodInterface()->getTransferPa($i, 0));
$transaction_details->setAmountTransfer($this->getEvent()->getMethodInterface()->getTransferAmount($i, 0));
$transaction_details->setTransferIban($this->getEvent()->getMethodInterface()->getTransferIban($i, 0));
$transaction_details->setIdTransfer($this->getEvent()->getMethodInterface()->getTransferId($i, 0));
$transaction_details->insert();
DB::statement($transaction_details->getQuery(), $transaction_details->getBindParams());
$attempt['transfer_added'] = true;
}
}
}

for($i=0;$i<$this->getEvent()->getTransferCount($index);$i++)
{
$transaction_details = new TransactionDetails($this->getEvent()->getInsertedTimestamp());
$transaction_details->setFkPayment($id);
$transaction_details->setNewColumnValue('date_event', $date_event);
$transaction_details->setPaTransfer($this->getEvent()->getMethodInterface()->getTransferPa($i, 0));
$transaction_details->setAmountTransfer($this->getEvent()->getMethodInterface()->getTransferAmount($i, 0));
$transaction_details->setTransferIban($this->getEvent()->getMethodInterface()->getTransferIban($i, 0));
$transaction_details->setIdTransfer($this->getEvent()->getMethodInterface()->getTransferId($i, 0));
$transaction_details->insert();
DB::statement($transaction_details->getQuery(), $transaction_details->getBindParams());
}
$cached_attempts[$key] = $attempt; // aggiorno la cache con le nuove info (se aggiornate) di aggiunta transfer e aggiornamento importo

$workflow = new Workflow($this->getEvent()->getInsertedTimestamp());
$workflow->setNewColumnValue('date_event', $date);
Expand All @@ -378,6 +445,17 @@ public function runAttemptAlreadyEvaluated(int $index = 0): void
$workflow->insert();
DB::statement($workflow->getQuery(), $workflow->getBindParams());
}

if (count($cached_attempts) > 0)
{
// se ho valori in cache , la aggiorno
$this->delFromCache($cache_key);
foreach($cached_attempts as $v)
{
$this->addValueCache($cache_key, $v);
}
}

}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/test_date.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php

$memcache = new \Memcached();
$memcache->addServer('172.17.0.3', 11211);

$memcache->append('a', '2');
$memcache->append('a', '3');

$memcache->set('b', 5);

print_r($memcache->get('YXR0ZW1wdF8yMDI0MDMxMF8wMTAwMDAwMDAwMDAwMDAxMV83Nzc3Nzc3Nzc3N190MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMQ=='));




die();

require_once './vendor/autoload.php';

Expand Down
Loading

0 comments on commit 5606cd1

Please sign in to comment.