diff --git a/htdocs/public/eventorganization/attendee_subscription.php b/htdocs/public/eventorganization/attendee_subscription.php index a40c836f0b3..a7f68a7ddab 100644 --- a/htdocs/public/eventorganization/attendee_subscription.php +++ b/htdocs/public/eventorganization/attendee_subscription.php @@ -86,7 +86,7 @@ $id = dol_decode($encodedid, $dolibarr_main_instance_unique_id); $conference = new ConferenceOrBooth($db); $resultconf = $conference->fetch($id); if ($resultconf < 0) { - setEventMessages(null, $object->errors, "errors"); + setEventMessages(null, $conference->errors, "errors"); } $project = new Project($db); @@ -295,21 +295,31 @@ if (empty($reshook) && $action == 'add') { $db->commit(); global $dolibarr_main_url_root; if (!empty(floatval($project->price_registration))) { - $facture = new Facture($db); - $facture->type = 0; - $facture->socid = $thirdparty->id; - $facture->paye = 0; - //@todo price and taxes to add - $tva = get_default_tva($mysoc, $thirdparty); - $facture->date = dol_now(); - $resultfacture = $facture->create($user); - if ($resultfacture < 0) { + $productforinvoicerow = new Product($db); + $resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION); + if ($resultprod < 0) { $error++; - $errmsg .= $facture->error; + $errmsg .= $productforinvoicerow->error; } else { - $redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source=conferencesubscription&ref='.$confattendee->id; - Header("Location: ".$redirection); - exit; + $facture = new Facture($db); + $facture->type = 0; + $facture->socid = $thirdparty->id; + $facture->paye = 0; + // @todo complete + //$baseprice = $productforinvoicerow-> + $facture->total_ht = 10; + $facture->total_vat = $productforinvoicerow->tva_tx*10; + $facture->total_ttc = $facture->total_ht + $facture->total_ttc; + $facture->date = dol_now(); + $resultfacture = $facture->create($user); + if ($resultfacture < 0) { + $error++; + $errmsg .= $facture->error; + } else { + $redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source=conferencesubscription&ref='.$confattendee->id; + Header("Location: ".$redirection); + exit; + } } } else { // No price has been set diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 9fba38962b4..d4bf295db10 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -69,6 +69,9 @@ include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager = new HookManager($db); $hookmanager->initHooks(array('newpayment')); +// For encryption +global $dolibarr_main_instance_unique_id; + // Load translation files $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox", "paypal", "stripe")); // File with generic data @@ -375,6 +378,9 @@ if ($action == 'dopayment') { dol_syslog("SCRIPT_URI: ".(empty($_SERVER["SCRIPT_URI"]) ? '' : $_SERVER["SCRIPT_URI"]), LOG_DEBUG); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO // A redirect is added if API call successfull + if ($source == 'conferencesubscription') { + $PAYPAL_API_OK .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id); + } $mesg = print_paypal_redirect($PAYPAL_API_PRICE, $PAYPAL_API_DEVISE, $PAYPAL_PAYMENT_TYPE, $PAYPAL_API_OK, $PAYPAL_API_KO, $FULLTAG); // If we are here, it means the Paypal redirect was not done, so we show error message @@ -393,6 +399,10 @@ if ($action == 'dopayment') { $urlok = preg_replace('/securekey=[^&]+/', '', $urlok); $urlko = preg_replace('/securekey=[^&]+/', '', $urlko); + if ($source == 'conferencesubscription') { + $urlok .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id); + } + $mesg = ''; if (empty($PRICE) || !is_numeric($PRICE)) { $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")); @@ -747,7 +757,9 @@ if ($action == 'charge' && !empty($conf->stripe->enabled)) { header("Location: ".$urlko); exit; } else { - $attendee->setStatut(1); + if ($source == 'conferencesubscription') { + $urlok .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id); + } header("Location: ".$urlok); exit; } diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 1942635001f..7e11944c243 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -56,6 +56,8 @@ if (!empty($conf->paypal->enabled)) { require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php'; } +global $dolibarr_main_instance_unique_id; + $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal")); // Clean parameters @@ -105,6 +107,21 @@ $ref = GETPOST('ref'); $suffix = GETPOST("suffix", 'aZ09'); $membertypeid = GETPOST("membertypeid", 'int'); +$conferencesubscription = GETPOST('conferencesubscription'); +$uncryptedconferencesubscription = dol_decode($conferencesubscription, $dolibarr_main_instance_unique_id); +$subscription = substr($uncryptedconferencesubscription, 0, strlen($uncryptedconferencesubscription)-strlen($ref)); +$reffrompayment = substr($uncryptedconferencesubscription, -strlen($ref), strlen($ref)); + +// Validation of an attendee after his payment +if ($subscription == 'subscriptionok' && $ref == $reffrompayment) { + $attendeetovalidate = new ConferenceOrBoothAttendee($db); + $resultattendee = $attendeetovalidate->fetch($ref); + if ($resultattendee < 0) { + setEventMessages(null, $attendeetovalidate->errors, "errors"); + } else { + $attendeetovalidate->setStatut(1); + } +} // Detect $paymentmethod $paymentmethod = '';