diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php
index 90cf38a6051..950d68560b5 100644
--- a/htdocs/public/payment/paymentok.php
+++ b/htdocs/public/payment/paymentok.php
@@ -156,45 +156,6 @@ $object = new stdClass(); // For triggers
$error = 0;
-// After a conference attendee payment
-if ($subscription == 'subscriptionok' && $ref == $reffrompayment) {
- // Looking for the invoice to which add a payment
- $paidinvoice = new Facture($db);
- $resultinvoice = $paidinvoice->fetch($invoiceref);
- if ($resultinvoice < 0) {
- setEventMessages(null, $paidinvoice->errors, "errors");
- } else {
- // Finding thirdparty
- $thirdparty = new Societe($db);
- $resultthirdparty = $thirdparty->fetch($paidinvoice->socid);
- if ($resultthirdparty <= 0) {
- $mesg = $thirdparty->error;
- $error++;
- } else {
- // Creation of payment line
- $paiement = new Paiement($db);
- $paiement->facid = $paidinvoice->id;
- $paiement->datepaye = dol_now();
- $paiement->amount = $paidinvoice->total_ttc;
- $paiement->amounts[] = $paidinvoice->total_ttc;
- $paiement_id = $paiement->create($user, 1, $thirdparty); // This include closing invoices and regenerating documents
- if ($paiement_id < 0) {
- setEventMessages($paiement->error, $paiement->errors, 'errors');
- $error++;
- } else {
- // Validating the attendee
- $attendeetovalidate = new ConferenceOrBoothAttendee($db);
- $resultattendee = $attendeetovalidate->fetch($ref);
- if ($resultattendee < 0) {
- setEventMessages(null, $attendeetovalidate->errors, "errors");
- } else {
- $attendeetovalidate->setStatut(1);
- }
- }
- }
- }
-}
-
/*
* Actions
*/
@@ -822,6 +783,129 @@ if ($ispaymentok) {
$postactionmessages[] = 'Invoice paid '.$tmptag['INV'].' was not found';
$ispostactionok = -1;
}
+ } elseif (array_key_exists('ATT', $tmptag) && $tmptag['INV'] > 0) {
+ // Record payment
+ include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+ $object = new Facture($db);
+ $result = $object->fetch($tmptag['INV']);
+ if ($result) {
+ $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
+
+ $paymentTypeId = 0;
+ if ($paymentmethod == 'paybox') {
+ $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
+ }
+ if ($paymentmethod == 'paypal') {
+ $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
+ }
+ if ($paymentmethod == 'stripe') {
+ $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
+ }
+ if (empty($paymentTypeId)) {
+ $paymentType = $_SESSION["paymentType"];
+ if (empty($paymentType)) {
+ $paymentType = 'CB';
+ }
+ $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
+ }
+
+ $currencyCodeType = $_SESSION['currencyCodeType'];
+
+ // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
+ if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
+ $db->begin();
+
+ // Creation of payment line
+ include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+ $paiement = new Paiement($db);
+ $paiement->datepaye = $now;
+ if ($currencyCodeType == $conf->currency) {
+ $paiement->amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
+ } else {
+ $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching
+
+ $postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
+ $ispostactionok = -1;
+ $error++; // Not yet supported
+ }
+ $paiement->paiementid = $paymentTypeId;
+ $paiement->num_payment = '';
+ $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress;
+ $paiement->ext_payment_id = $TRANSACTIONID;
+ $paiement->ext_payment_site = $service;
+
+ if (!$error) {
+ $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
+ if ($paiement_id < 0) {
+ $postactionmessages[] = $paiement->error.' '.join("
\n", $paiement->errors);
+ $ispostactionok = -1;
+ $error++;
+ } else {
+ $postactionmessages[] = 'Payment created';
+ $ispostactionok = 1;
+ }
+ }
+
+ if (!$error && !empty($conf->banque->enabled)) {
+ $bankaccountid = 0;
+ if ($paymentmethod == 'paybox') {
+ $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
+ } elseif ($paymentmethod == 'paypal') {
+ $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
+ } elseif ($paymentmethod == 'stripe') {
+ $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
+ }
+
+ if ($bankaccountid > 0) {
+ $label = '(CustomerInvoicePayment)';
+ if ($object->type == Facture::TYPE_CREDIT_NOTE) {
+ $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
+ }
+ $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
+ if ($result < 0) {
+ $postactionmessages[] = $paiement->error.' '.join("
\n", $paiement->errors);
+ $ispostactionok = -1;
+ $error++;
+ } else {
+ $postactionmessages[] = 'Bank transaction of payment created';
+ $ispostactionok = 1;
+ }
+ } else {
+ $postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. No way to record the payment.';
+ $ispostactionok = -1;
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ $db->commit();
+
+ // Validating the attendee
+ $attendeetovalidate = new ConferenceOrBoothAttendee($db);
+ $resultattendee = $attendeetovalidate->fetch($ref);
+ if ($resultattendee < 0) {
+ setEventMessages(null, $attendeetovalidate->errors, "errors");
+ } else {
+ $attendeetovalidate->setStatut(1);
+ }
+ $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?idthirdparty='.dol_encode($thirdparty->id, $dolibarr_main_instance_unique_id).'&securekey='.dol_encode($conf->global->EVENTORGANIZATION_SECUREKEY, $dolibarr_main_instance_unique_id);
+ Header("Location: ".$redirection);
+ exit;
+
+ } else {
+ $db->rollback();
+ }
+ } else {
+ $postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type" ('.$paymentType.') to record the payment of invoice '.$tmptag['INV'].'. May be payment was already recorded.';
+ $ispostactionok = -1;
+ }
+
+ } else {
+ $postactionmessages[] = 'Invoice paid '.$tmptag['INV'].' was not found';
+ $ispostactionok = -1;
+ }
+ } elseif (array_key_exists('BOO', $tmptag) && $tmptag['INV'] > 0) {
+ // BOOTH CASE (to copy and adapt from above)
} else {
// Nothing done
}