From 8a43dac46d51c691b9208c4580aa05fbd1937ef7 Mon Sep 17 00:00:00 2001 From: Dorian Vabre Date: Mon, 19 Apr 2021 15:21:16 +0200 Subject: [PATCH] now giving the invoice id to the payment validation page so it can validate the payment --- htdocs/public/payment/newpayment.php | 6 ++--- htdocs/public/payment/paymentok.php | 33 +++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index d03f004f317..75d72b4bbea 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -363,7 +363,7 @@ if ($action == 'dopayment') { // A redirect is added if API call successfull if ($source == 'conferencesubscription') { - $PAYPAL_API_OK .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id); + $PAYPAL_API_OK .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id).'&invoice='.dol_encode($invoice->id, $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); @@ -384,7 +384,7 @@ if ($action == 'dopayment') { $urlko = preg_replace('/securekey=[^&]+/', '', $urlko); if ($source == 'conferencesubscription') { - $urlok .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id); + $urlok .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id).'&invoice='.dol_encode($invoice->id, $dolibarr_main_instance_unique_id); } $mesg = ''; @@ -742,7 +742,7 @@ if ($action == 'charge' && !empty($conf->stripe->enabled)) { exit; } else { if ($source == 'conferencesubscription') { - $urlok .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id); + $urlok .= '&conferencesubscription='.dol_encode('subscriptionok'.$ref, $dolibarr_main_instance_unique_id).'&invoice='.dol_encode($invoice->id, $dolibarr_main_instance_unique_id); } header("Location: ".$urlok); exit; diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 7e11944c243..d9cfdc28b69 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -103,6 +103,7 @@ if (empty($FULLTAG)) { } $source = GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha'); $ref = GETPOST('ref'); +$invoiceref = GETPOST('invoice'); $suffix = GETPOST("suffix", 'aZ09'); $membertypeid = GETPOST("membertypeid", 'int'); @@ -112,15 +113,35 @@ $uncryptedconferencesubscription = dol_decode($conferencesubscription, $dolibarr $subscription = substr($uncryptedconferencesubscription, 0, strlen($uncryptedconferencesubscription)-strlen($ref)); $reffrompayment = substr($uncryptedconferencesubscription, -strlen($ref), strlen($ref)); -// Validation of an attendee after his payment +// After a conference attendee payment if ($subscription == 'subscriptionok' && $ref == $reffrompayment) { - $attendeetovalidate = new ConferenceOrBoothAttendee($db); - $resultattendee = $attendeetovalidate->fetch($ref); - if ($resultattendee < 0) { - setEventMessages(null, $attendeetovalidate->errors, "errors"); + // 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 { - $attendeetovalidate->setStatut(1); + // Creation of payment line + $paiement = new Paiement($db); + $paiement->datepaye = dol_now(); + $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id + $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching + $paiement->paiementid = dol_getIdFromCode($db, GETPOST('paiementcode'), 'c_paiement', 'code', 'id', 1); + $paiement->num_payment = GETPOST('num_paiement', 'alpha'); + $paiement->note_private = GETPOST('comment', 'alpha'); + + // Validating the attendee + $attendeetovalidate = new ConferenceOrBoothAttendee($db); + $resultattendee = $attendeetovalidate->fetch($ref); + if ($resultattendee < 0) { + setEventMessages(null, $attendeetovalidate->errors, "errors"); + } else { + $attendeetovalidate->setStatut(1); + } } + + + } // Detect $paymentmethod