Skip to content

Commit

Permalink
Gestione migliorata della ricerca e creazione payment_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
websuvius committed Jan 31, 2025
1 parent bef805a commit 27521f5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fattureincloud/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>fattureincloud</name>
<displayName><![CDATA[FattureInCloud]]></displayName>
<version><![CDATA[2.2.0]]></version>
<version><![CDATA[2.2.1]]></version>
<description><![CDATA[Collega il tuo negozio Prestashop al tuo account FattureInCloud! Sincronizza gli ordini, le anagrafiche ed emetti fatture!]]></description>
<author><![CDATA[FattureInCloud]]></author>
<tab><![CDATA[billing_invoicing]]></tab>
Expand Down
36 changes: 31 additions & 5 deletions fattureincloud/fattureincloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
{
$this->name = 'fattureincloud';
$this->tab = 'billing_invoicing';
$this->version = '2.2.0';
$this->version = '2.2.1';
$this->author = 'FattureInCloud';
$this->need_instance = 1;

Expand Down Expand Up @@ -973,7 +973,11 @@ public function getPaymentAccountIDByName($payment_name)
return $payment_details['payment_account_id'];
}

$payment_accounts_request = $fic_client->getPaymentAccounts();
$payment_accounts_fieldset = array(
"fieldset" => "detailed"
);

$payment_accounts_request = $fic_client->getPaymentAccounts($payment_accounts_fieldset);

if (isset($payment_accounts_request['error'])) {
$this->writeLog("ERROR - Ricerca conti di pagamento fallita: " . json_encode($payment_accounts_request));
Expand All @@ -985,6 +989,13 @@ public function getPaymentAccountIDByName($payment_name)
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);

$payment_id_to_return = 0;
$favorite_payment_id = 0;

$this->writeLog("DEBUG - Payment accounts: " . json_encode($payment_accounts_request));

if ($payment_accounts_request['data'][0] != null) {
$favorite_payment_id = $payment_accounts_request['data'][0]['id'];
}

foreach ($payment_accounts_request['data'] as $payment_account) {

Expand All @@ -997,12 +1008,17 @@ public function getPaymentAccountIDByName($payment_name)

Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);

if (strtolower($payment_account['name']) == strtolower($payment_name)) {
if (trim(strtolower($payment_account['name'])) == trim(strtolower($payment_name))) {

$this->writeLog("INFO - Conto di pagamento trovato su FattureInCloud: " . json_encode($payment_account));

$payment_id_to_return = $payment_account['id'];
}

if ($payment_account['favorite'] == true) {
$favorite_payment_id = $payment_account['id'];
}

}

if ($payment_id_to_return != 0) {
Expand All @@ -1015,6 +1031,11 @@ public function getPaymentAccountIDByName($payment_name)

if (isset($create_payment_account_request['error'])) {
$this->writeLog("ERROR - Creazione conto di pagamento fallita: " . json_encode($create_payment_account_request));

if ($favorite_payment_id != 0) {
return $favorite_payment_id;
}

} else {
$this->writeLog("INFO: Conto di pagamento creato: #" . $create_payment_account_request['data']['id']);

Expand Down Expand Up @@ -1404,6 +1425,8 @@ public function mapPrestashopToFicDocument($document_type, $order_id)

if ($order_state->paid) {

$payment['status'] = "paid";

$paid_date_time = strtotime($order->invoice_date);

if ($paid_date_time > 0) {
Expand All @@ -1412,8 +1435,11 @@ public function mapPrestashopToFicDocument($document_type, $order_id)
$payment['paid_date'] = date("Y-m-d");
}

$payment['status'] = "paid";
$payment['payment_account'] = array("id" => $this->getPaymentAccountIDByName($order->payment));
$payment_account_id = $this->getPaymentAccountIDByName($order->payment);

if ($payment_account_id != null) {
$payment['payment_account'] = array("id" => $payment_account_id);
}

} else {
$payment['status'] = "not_paid";
Expand Down
4 changes: 2 additions & 2 deletions fattureincloud/libs/fattureincloudClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ public function getVatTypes()
return $return;
}

public function getPaymentAccounts()
public function getPaymentAccounts($params = null)
{
$return = $this->makeCompanyRequest("settings/payment_accounts");
$return = $this->makeCompanyRequest("settings/payment_accounts", $params);

return $return;
}
Expand Down

0 comments on commit 27521f5

Please sign in to comment.