further implementation work for stripe integration
This commit is contained in:
@@ -871,13 +871,11 @@ function _booking_deposit_amount($person, $include_fees = TRUE)
|
||||
/**
|
||||
* Calculate exactly how much a person has already paid
|
||||
*/
|
||||
function _booking_amount_paid($nid, $person = NULL)
|
||||
{
|
||||
function _booking_amount_paid($nid, $person = NULL) {
|
||||
$amount_paid = 0;
|
||||
|
||||
//fetch details about the person if we don't already have them
|
||||
if ($person == NULL)
|
||||
{
|
||||
if ($person == NULL) {
|
||||
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
|
||||
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id " .
|
||||
"FROM {booking_person} person, {booking_price} price " .
|
||||
@@ -888,15 +886,13 @@ function _booking_amount_paid($nid, $person = NULL)
|
||||
}
|
||||
|
||||
//check for a spouse
|
||||
if ($person->booking_partner_id > 0)
|
||||
{
|
||||
if ($person->booking_partner_id > 0) {
|
||||
//watchdog('booking', "Checking total paid for married person");
|
||||
|
||||
//look for payments in the payment transaction table
|
||||
|
||||
//if we're combining the payment for married couples
|
||||
if (variable_get('booking_enable_combined_pricing', 0) == 1)
|
||||
{
|
||||
if (variable_get('booking_enable_combined_pricing', 0) == 1) {
|
||||
//check for payments in the paypal transaction table from either spouse
|
||||
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
|
||||
"WHERE booking_person_nid = :nid OR booking_person_nid = :spousenid",
|
||||
@@ -910,17 +906,16 @@ function _booking_amount_paid($nid, $person = NULL)
|
||||
}
|
||||
|
||||
//add up all the payments
|
||||
foreach ($query as $payment)
|
||||
foreach ($query as $payment) {
|
||||
$amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee);
|
||||
}
|
||||
|
||||
//watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
|
||||
|
||||
//there were no payment transactions, so rely on what the amount is set to in the individual registration records
|
||||
if ($amount_paid == 0)
|
||||
{
|
||||
//if we're combining the payment for married couples
|
||||
if (variable_get('booking_enable_combined_pricing', 0) == 1)
|
||||
{
|
||||
if ($amount_paid == 0) {
|
||||
//if we're combining the payment for married couples
|
||||
if (variable_get('booking_enable_combined_pricing', 0) == 1) {
|
||||
$spouse = db_query("SELECT person.booking_amount_paid " .
|
||||
"FROM {booking_person} person " .
|
||||
"WHERE person.nid = :nid ",
|
||||
@@ -929,17 +924,15 @@ function _booking_amount_paid($nid, $person = NULL)
|
||||
$amount_paid = $person->booking_amount_paid + $spouse->booking_amount_paid;
|
||||
//watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid);
|
||||
}
|
||||
else
|
||||
{
|
||||
$amount_paid = $person->booking_amount_paid;
|
||||
else {
|
||||
$amount_paid = $person->booking_amount_paid;
|
||||
//watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid);
|
||||
}
|
||||
//end combined payments check
|
||||
}
|
||||
}
|
||||
//no spouse found
|
||||
else
|
||||
{
|
||||
else {
|
||||
//Check if there are payment records in the paypal transaction table for this unmarried person
|
||||
//if so, base their payments on the gross amount in there rather than what the person booking_person database says
|
||||
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
|
||||
@@ -951,8 +944,9 @@ function _booking_amount_paid($nid, $person = NULL)
|
||||
//watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
|
||||
|
||||
//if there were no results, $amount_paid will still be 0
|
||||
if ($amount_paid == 0)
|
||||
if ($amount_paid == 0) {
|
||||
$amount_paid = $person->booking_amount_paid;
|
||||
}
|
||||
//in case there has been some manual adjustment
|
||||
//elseif ($amount_paid < $person->booking_amount_paid)
|
||||
// $amount_paid = $person->booking_amount_paid;
|
||||
@@ -1021,26 +1015,11 @@ function _booking_total_due($person)
|
||||
*
|
||||
* @param $person - the object relating to the registration node
|
||||
* @param $amount_paid - if we have previously calculated the amount paid, this can be passed as a value
|
||||
* @param $include_paypal_fees - boolean to indicate whether we want the net amount or the amount owing including paypal fees
|
||||
* @param $include_fees - boolean to indicate whether we want the net amount or the amount owing including paypal fees
|
||||
* @return amount owing as a decimal value
|
||||
*/
|
||||
function _booking_amount_owing($person, $amount_paid = 0, $include_paypal_fees = TRUE)
|
||||
{
|
||||
//$amount_paid = 0;
|
||||
//$total_due = 0;
|
||||
|
||||
//fetch details about the person
|
||||
/*
|
||||
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
|
||||
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id, person.booking_country, person.booking_welfare_required, person.booking_committee_member " .
|
||||
"FROM {booking_person} person, {booking_price} price " .
|
||||
"WHERE person.nid = :nid " .
|
||||
"AND person.booking_payment_id = price.pid",
|
||||
array(':nid' => $nid))
|
||||
->fetchObject();
|
||||
|
||||
//$person = node_load($nid);
|
||||
*/
|
||||
function _booking_amount_owing($person, $amount_paid = 0, $include_fees = TRUE) {
|
||||
global $event;
|
||||
//quick sanity check
|
||||
if (! $person->nid) {
|
||||
watchdog('booking', "Unable to find matching person relating to registration id. Details were '" . var_export($person, TRUE) . "' .");
|
||||
@@ -1050,43 +1029,80 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_paypal_fees =
|
||||
$total_due = _booking_total_due($person);
|
||||
|
||||
//if we didn't get the amount paid as a command line parameter, check it now
|
||||
if ($amount_paid == 0)
|
||||
{
|
||||
if ($amount_paid == 0) {
|
||||
$amount_paid = _booking_amount_paid($person->nid, $person);
|
||||
}
|
||||
|
||||
//check if there is anything outstanding
|
||||
//use the original total amount required rather than the late-rate, to cater for people that paid before the late rate
|
||||
if ($amount_paid >= $person->booking_total_pay_reqd)
|
||||
{
|
||||
if ($amount_paid >= $person->booking_total_pay_reqd) {
|
||||
//watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
//@todo - use booking_payment_processor instead. 0 is paypal, 1 is stripe, 2 is manual
|
||||
|
||||
//if we're using paypal, add the transaction fee
|
||||
if (variable_get('booking_use_paypal', 0) == 1 && $include_paypal_fees == TRUE)
|
||||
{
|
||||
if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE) {
|
||||
$amount_owing = _booking_add_paypal_fees($total_due - $amount_paid, $person->booking_country);
|
||||
/*
|
||||
//add the 30 cent fixed cost
|
||||
$amount_owing = $total_due - $amount_paid + 0.3;
|
||||
//and the 2.4 percent transaction fee
|
||||
if ($person->booking_country === "Australia")
|
||||
$amount_owing = $amount_owing / (1 - 0.026);
|
||||
//paypal charges 3.4 percent if they're doing a currency conversion
|
||||
//assume that everyone not based in Australia will be doing a currency conversion
|
||||
else
|
||||
{
|
||||
$amount_owing = $amount_owing / (1 - 0.036);
|
||||
//watchdog('booking', "This is an international registration.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
else {
|
||||
$amount_owing = $total_due - $amount_paid;
|
||||
}
|
||||
return number_format($amount_owing, 2, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update the person object when a payment has been made
|
||||
* payment details should be inserted into booking_payment prior to calling this function
|
||||
*
|
||||
* @param $person - the populated node object representing this person including related price information
|
||||
* @param $payment_amount - the gross payment amount that is being processed
|
||||
* @param $balance_payment - boolean to indicate if this transaction was to complete a payment
|
||||
* @return nothing
|
||||
*/
|
||||
function _booking_process_payment($person, $payment_amount, $balance_payment) {
|
||||
global $event;
|
||||
|
||||
//calculate their total payment amount
|
||||
$total = $person->booking_amount_paid + $payment_amount;
|
||||
|
||||
//only recalculate their booking status if this is the initial payment, not a payment of the outstanding balance
|
||||
if ($balance_payment == FALSE) {
|
||||
watchdog('booking', 'Processing an initial payment. Booking status is currently ' . $person->booking_status);
|
||||
if ($person->booking_status == 1) {
|
||||
watchdog('booking', 'This registration has been manually assigned to the booked-in list.');
|
||||
$status = 1;
|
||||
}
|
||||
elseif (_booking_check_bookings_full() == True || $person->booking_status == 2) {
|
||||
watchdog('booking', 'This registration belongs on the waiting list.');
|
||||
$status = 2;
|
||||
}
|
||||
else {
|
||||
watchdog('booking', 'This registration made it to the booked-in list.');
|
||||
$status = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//this is a balance payment
|
||||
watchdog('booking', 'Processing a balance payment.');
|
||||
//if this is a payment of outstanding balance, keep the booking_status the same
|
||||
$status = $person->booking_status;
|
||||
}
|
||||
|
||||
//update the database for this person
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
'booking_amount_paid' => $total,
|
||||
'booking_status' => $status,
|
||||
))
|
||||
->condition('nid', $nid)
|
||||
->execute();
|
||||
|
||||
//handle workflow emails and spouse payment updates
|
||||
_booking_postpayment_trigger($nid, $person, $balance_payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to handle any post-payment notification emails for either paypal or manual payment
|
||||
* still a WIP
|
||||
|
Reference in New Issue
Block a user