Exemplo n.º 1
0
function booking_cron()
{
    global $DB, $USER, $CFG;
    mtrace('Starting cron for Booking ...');
    $toProcess = $DB->count_records_select('booking_options', "sent = 0 AND daystonotify > 0 AND coursestarttime > 0");
    if ($toProcess > 0) {
        $allToSend = $DB->get_records_select('booking_options', "sent = 0 AND daystonotify > 0 AND coursestarttime > 0");
        foreach ($allToSend as $value) {
            $dateEvent = new DateTime();
            $dateEvent->setTimestamp($value->coursestarttime);
            $dateNow = new DateTime();
            $dateEvent->modify('-' . $value->daystonotify . ' day');
            if ($dateEvent < $dateNow) {
                //$booking = $DB->get_record('booking', array('id' => $value->bookingid));
                $value->sent = 1;
                booking_send_notification($value->id, get_string('notificationsubject', 'booking'));
                $DB->update_record("booking_options", $value);
            }
        }
    }
    mtrace('Ending cron for Booking ...');
    return true;
}
Exemplo n.º 2
0
function bizz_check_ipn_response()
{
    if (isset($_GET['paypalListener']) && $_GET['paypalListener'] == 'paypal_standard_IPN') {
        // variables
        $listener = new IpnListener();
        $listener->use_sandbox = TEST_MODE;
        $listener->use_ssl = true;
        $listener->use_curl = false;
        try {
            $listener->requirePostMethod();
            $verified = $listener->processIpn();
        } catch (Exception $e) {
            error_log($e->getMessage(), 3, 'error_log');
            exit(0);
        }
        if ($verified) {
            // Get transaction details
            $posted = $listener->getPostData();
            // Post ID
            $order_id = $posted['custom'];
            $order_key = $posted['invoice'];
            // Save details
            $r = '';
            foreach ($posted as $key => $value) {
                $r .= str_pad($key, 25) . "{$value}<br/>";
            }
            $transaction_details = get_post_meta($order_id, 'bizzthemes_booking_paypal_details', 1);
            $transaction_details = !empty($transaction_details) ? $transaction_details . '<br/><hr/><br/>' . $r : $r;
            update_post_meta($order_id, 'bizzthemes_booking_paypal_details', $transaction_details);
            // get booking meta
            $booking_custom = get_post_custom($order_id);
            foreach ($booking_custom as $key => $value) {
                $bookopts[$key] = $value[0];
            }
            // Lowercase
            $posted['payment_status'] = strtolower($posted['payment_status']);
            $posted['txn_type'] = strtolower($posted['txn_type']);
            // Sandbox fix
            if ($posted['test_ipn'] == 1 && $posted['payment_status'] == 'pending') {
                $posted['payment_status'] = 'completed';
            }
            // We are here so lets check status and do actions
            switch ($posted['payment_status']) {
                case 'completed':
                    // Check valid txn_type
                    $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money');
                    if (!in_array($posted['txn_type'], $accepted_types)) {
                        if (DEBUG_MODE) {
                            error_log('Invalid type:' . $posted['txn_type'], 3, 'error_log');
                        }
                        exit;
                    }
                    // Saved booking
                    $deposit_amount = get_post_meta($order_id, 'bizzthemes_car_pay_deposit', 1);
                    $total_amount = get_post_meta($order_id, 'bizzthemes_car_pay_total', 1);
                    // Validate Amount
                    if (round($deposit_amount, 2) != $posted['mc_gross']) {
                        if (DEBUG_MODE) {
                            error_log('Payment error: Amounts do not match (gross ' . $posted['mc_gross'] . ', saved ' . round($deposit_amount, 2) . ')', 3, 'error_log');
                        }
                        exit;
                    }
                    // Store PP Details
                    if (!empty($posted['payer_email'])) {
                        update_post_meta($order_id, 'bizzthemes_bookings_email', $posted['payer_email']);
                    }
                    if (!empty($posted['txn_id'])) {
                        update_post_meta($order_id, 'bizzthemes_car_transaction_id', $posted['txn_id']);
                    }
                    if (!empty($posted['first_name'])) {
                        update_post_meta($order_id, 'bizzthemes_bookings_fname', $posted['first_name']);
                    }
                    if (!empty($posted['last_name'])) {
                        update_post_meta($order_id, 'bizzthemes_bookings_lname', $posted['last_name']);
                    }
                    // Paid
                    update_post_meta($order_id, 'bizzthemes_car_pay_paid', round($posted['mc_gross'], 2));
                    // Completed?
                    if (round($total_amount, 2) == $posted['mc_gross']) {
                        update_post_meta($order_id, 'bizzthemes_bookings_status', 'approved');
                    }
                    break;
                case 'denied':
                case 'expired':
                case 'failed':
                case 'voided':
                    // Only handle full refunds, not partial
                    update_post_meta($order_id, 'bizzthemes_bookings_status', 'cancelled');
                    break;
                case "refunded":
                    // Only handle full refunds, not partial
                    update_post_meta($order_id, 'bizzthemes_bookings_status', 'refunded');
                    update_post_meta($order_id, 'bizzthemes_car_pay_paid', '0');
                    booking_send_notification('refunded', $bookopts);
                    break;
                case "reversed":
                case "chargeback":
                    // Mark order as refunded
                    update_post_meta($order_id, 'bizzthemes_bookings_status', 'refunded');
                    update_post_meta($order_id, 'bizzthemes_car_pay_paid', '0');
                    break;
                default:
                    // No action
                    break;
            }
            exit;
            // error_log('getPaymentData: '.$r, 3, 'error_log');
            //error_log('getTextReport: '.$listener->getTextReport(), 3, 'error_log');
            // mail('*****@*****.**', 'Verified IPN', $listener->getTextReport());
        } else {
            /* zapis v bazo o napačni transakciji */
            // mail('*****@*****.**', 'Invalid IPN', $listener->getTextReport());
            error_log('getTextReport: ' . $listener->getTextReport(), 3, 'error_log');
        }
    }
}
Exemplo n.º 3
0
function booking_save_post($id)
{
    global $post;
    $post_type = isset($post) ? get_post_type($post->ID) : '';
    if ($post_type == 'bizz_bookings') {
        $status = $_POST['bizzthemes_bookings_status'];
        $saved_status = get_post_meta($post->ID, 'bizzthemes_bookings_status', true);
        $status_change = $status != $saved_status ? true : false;
        if ($status_change && ($status == 'approved' || $status == 'cancelled' || $status == 'refunded')) {
            booking_send_notification($status, $_POST);
        }
        if ($status_change && $status == 'approved') {
            booking_send_notification('reminder', $_POST);
        }
    }
}
Exemplo n.º 4
0
function bizz_check_mollie_response()
{
    if (isset($_GET['mollie']) && $_GET['mollie'] != '') {
        // variables
        try {
            // Initialize
            require_once dirname(__FILE__) . "/mollie-api/src/Mollie/API/Autoloader.php";
            $mollie = new Mollie_API_Client();
            $api = $opt_s['pay_mollie_api'] != '' ? $opt_s['pay_mollie_api'] : 'test_W9vJrPAB2Jv4LGRZkGZgLmkznzDAs2';
            $mollie->setApiKey($api);
            // Retrieve the payment's current state.
            $payment = $mollie->payments->get($_POST["id"]);
            $order_id = $payment->metadata->order_id;
            $post_id = $payment->metadata->post_id;
            // get booking meta
            $booking_custom = get_post_custom($post_id);
            foreach ($booking_custom as $key => $value) {
                $bookopts[$key] = $value[0];
            }
            // Update the order in the database.
            if ($payment->isPaid() == TRUE) {
                /*
                 * At this point you'd probably want to start the process of delivering the product to the customer.
                 */
                update_post_meta($post_id, 'bizzthemes_bookings_status', 'approved');
                booking_send_notification('approved', $bookopts);
            } elseif ($payment->isOpen() == FALSE) {
                /*
                 * The payment isn't paid and isn't open anymore. We can assume it was aborted.
                 */
                update_post_meta($post_id, 'bizzthemes_bookings_status', 'cancelled');
                booking_send_notification('cancelled', $bookopts);
            }
        } catch (Mollie_API_Exception $e) {
            echo "API call failed: " . htmlspecialchars($e->getMessage());
        }
    }
}