Move post-payment triggers to a separate function, and improve paypal verification attempts
This commit is contained in:
@@ -1096,6 +1096,95 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_paypal_fees =
|
||||
return number_format($amount_owing, 2, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to handle any post-payment notification emails for either paypal or manual payment
|
||||
* still a WIP
|
||||
*
|
||||
* @param $nid - the node ID relating to this person
|
||||
* @param $person - the populated node object representing this person including related price information
|
||||
* @param $balance_payment - boolean to indicate if this transaction was to complete a payment
|
||||
* @return nothing
|
||||
*/
|
||||
function _booking_postpayment_trigger($nid, $person, $balance_payment)
|
||||
{
|
||||
global $event;
|
||||
|
||||
//If there is no outstanding balance, send a payment complete email
|
||||
$amount_owing = _booking_amount_owing($person);
|
||||
//if ($total >= $person->booking_total_pay_reqd)
|
||||
if ($amount_owing == 0)
|
||||
{
|
||||
//set the payment complete flag
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
'booking_payment_complete' => 'Y',
|
||||
))
|
||||
->condition('nid', $nid)
|
||||
->execute();
|
||||
|
||||
//this should always be a balance payment type email, since that tells the user that their payment is completed
|
||||
_booking_registration_email($nid, TRUE);
|
||||
|
||||
//if we are combining payments, and this person has a linked spouse
|
||||
if ((variable_get('booking_enable_combined_pricing', 0) == 1) && ($person->booking_partner_id > 0))
|
||||
{
|
||||
//check spouse booking_status and payment info
|
||||
$spouse = db_select('booking_person', 'p')
|
||||
->condition('p.nid', $person->booking_partner_id,'=')
|
||||
->fields('p', array('booking_amount_paid', 'booking_status', 'booking_total_pay_reqd'))
|
||||
->execute()
|
||||
->fetchObject();
|
||||
|
||||
//update the spouse's status from "not paid" if required
|
||||
$spouse_status = $spouse->booking_status == 0 ? 1 : $spouse->booking_status;
|
||||
watchdog('booking', 'Setting status for spouse id !id to !new from !status', array('!id' => $person->booking_partner_id,
|
||||
'!new' => $spouse_status, '!status' => $spouse->booking_status));
|
||||
|
||||
//set the spouse's payment required to be zero or equal to their previous payment total
|
||||
$spouse_new_amount_reqd = $spouse->booking_amount_paid > 0 ? $spouse->booking_amount_paid : 0;
|
||||
watchdog('booking', 'Setting amount owing for spouse id !id to !new from !old.', array('!id' => $person->booking_partner_id,
|
||||
'!new' => $spouse_new_amount_reqd, '!old' => $spouse->booking_total_pay_reqd));
|
||||
|
||||
//update the database for this person
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
'booking_total_pay_reqd' => $spouse_new_amount_reqd,
|
||||
'booking_status' => $spouse_status,
|
||||
'booking_payment_complete' => 'Y',
|
||||
))
|
||||
->condition('nid', $person->booking_partner_id)
|
||||
->execute();
|
||||
|
||||
//send an email to the spouse
|
||||
_booking_registration_email($person->booking_partner_id, TRUE);
|
||||
}
|
||||
/*
|
||||
elseif (variable_get('booking_enable_combined_pricing', 0) == 1)
|
||||
{
|
||||
watchdog('booking', 'Combined pricing is enabled, but this person has a partner id of !id.', array('!id' => $person->booking_partner_id));
|
||||
} //end spouse check
|
||||
*/
|
||||
}
|
||||
//if this was an initial payment we might need to send a notification
|
||||
elseif ($balance_payment == FALSE)
|
||||
{
|
||||
//send a notification email if we didn't automatically send one earlier
|
||||
if (variable_get('booking_auto_confirm_email', 0) == 0)
|
||||
{
|
||||
_booking_registration_email($nid, FALSE);
|
||||
}
|
||||
}
|
||||
else //this person still has an outstanding balance so just send a confirmation email
|
||||
{
|
||||
watchdog('booking', 'This balance payment of !payment was insufficient for !id to completely pay the total outstanding of !outstanding.',
|
||||
array('!id' => $nid, '!payment' => $data['mc_gross'], '!outstanding' => $amount_owing));
|
||||
//send the person an email thanking them for their partial payment
|
||||
_booking_partialbalance_payment_email($nid);
|
||||
//TODO: create an email specifically for partial-balance payments
|
||||
//_booking_registration_email($nid, $balance_payment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to process the amount to refund a person when they withdraw their registration
|
||||
*
|
||||
|
Reference in New Issue
Block a user