function gdlr_hostel_paymill_payment() { global $hostel_option; $ret = array(); if (!empty($_POST['token']) && !empty($_POST['invoice'])) { global $wpdb; $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hostel_payment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); $apiKey = $hostel_option['paymill-private-key']; $request = new Paymill\Request($apiKey); $payment = new Paymill\Models\Request\Payment(); $payment->setToken($_POST['token']); try { $response = $request->create($payment); $paymentId = $response->getId(); $transaction = new Paymill\Models\Request\Transaction(); $transaction->setAmount(floatval($result->pay_amount) * 100)->setCurrency($hostel_option['paymill-currency-code'])->setPayment($paymentId)->setDescription($payment_info['email']); $response = $request->create($transaction); $wpdb->update($wpdb->prefix . 'gdlr_hostel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d')); $data = unserialize($result->booking_data); $mail_content = gdlr_hostel_mail_content($contact_info, $data, $response, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hostel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hostel_mail($hostel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $ret['status'] = 'success'; $ret['message'] = __('Payment complete', 'gdlr-hotel'); $ret['content'] = gdlrs_booking_complete_message(); } catch (PaymillException $e) { $ret['status'] = 'failed'; $ret['message'] = $e->getErrorMessage(); } } else { $ret['status'] = 'failed'; $ret['message'] = __('Failed to proceed, please try again.', 'gdlr-hotel'); } die(json_encode($ret)); }
function gdlr_ajax_hostel_booking() { if (!empty($_POST['data'])) { parse_str($_POST['data'], $data); } if (!empty($_POST['contact'])) { parse_str($_POST['contact'], $contact); } if (!empty($_POST['service'])) { parse_str($_POST['service'], $service); $data['service'] = empty($service['service-select']) ? array() : $service['service-select']; $data['service-amount'] = empty($service['service-amount']) ? array() : $service['service-amount']; } else { if (empty($data['service'])) { $data['service'] = array(); $data['service-amount'] = array(); } } $ret = array(); // query section if ($_POST['state'] == 2) { $data['gdlr-room-id'] = empty($data['gdlr-room-id']) ? array() : $data['gdlr-room-id']; // check and fill people for private room if (!empty($_POST['room_id'])) { $post_option = json_decode(gdlr_decode_preventslashes(get_post_meta($_POST['room_id'], 'post-option', true)), true); if (!empty($post_option['room-type']) && $post_option['room-type'] == 'private') { $guest_pos = intval($post_option['room-amount']) - 1; for ($i = 0; $i < intval($data['gdlr-room-number']); $i++) { if ($guest_pos <= 0) { break; } if (empty($data['gdlr-room-id'][$i])) { $data['gdlr-room-id'][$i] = $_POST['room_id']; $guest_pos--; } } } } $room_number = gdlrs_get_edited_room($data['gdlr-room-number'], $data['gdlr-room-id']); // room form $ret['room_form'] = gdlrs_get_reservation_room_form($data, $room_number); // content area if (empty($data['gdlr-check-in']) || empty($data['gdlr-check-out']) || $data['gdlr-check-out'] < $data['gdlr-check-in']) { $ret['content'] = '<div class="gdlr-room-selection-complete">'; $ret['content'] .= '<div class="gdlr-room-selection-title" >' . __('Date field invalid', 'gdlr-hotel') . '</div>'; $ret['content'] .= '<div class="gdlr-room-selection-content" >' . __('Please select \'check in\' and \'check out\' date from reservation bar again.', 'gdlr-hotel') . '</div>'; $ret['content'] .= '</div>'; } else { if ($data['gdlr-room-number'] > $room_number) { $ret['content'] = gdlrs_get_booking_room_query($data, $room_number); } else { $data['gdlr-hotel-branches'] = empty($data['gdlr-hotel-branches']) ? '' : $data['gdlr-hotel-branches']; $ret['content'] = '<div class="gdlr-room-selection-complete">'; $ret['content'] .= '<div class="gdlr-room-selection-title" >' . __('Room Selection is Complete', 'gdlr-hotel') . '</div>'; $ret['content'] .= '<div class="gdlr-room-selection-caption" >' . __('You can edit your booking by using the panel on the left', 'gdlr-hotel') . '</div>'; $ret['content'] .= gdlrs_get_booking_services($data['gdlr-hotel-branches'], $data['service']); $ret['content'] .= '<div class="gdlr-room-selection-divider" ></div>'; $ret['content'] .= '<a class="gdlr-button with-border gdlr-room-selection-next">' . __('Go to next step', 'gdlr-hotel') . '</a>'; $ret['content'] .= '</div>'; } } $ret['state'] = 2; } else { if ($_POST['state'] == 3) { if (!empty($data['service'])) { $ret['service'] = ''; foreach ($data['service'] as $key => $service_id) { $ret['service'] .= '<input type="hidden" name="service[]" value="' . $service_id . '" />'; $ret['service'] .= '<input type="hidden" name="service-amount[]" value="' . $data['service-amount'][$key] . '" />'; } } else { $ret['service'] = '<input type="hidden" />'; } if (empty($_POST['contact'])) { $ret['summary_form'] = gdlrs_get_summary_form($data); $ret['content'] = gdlrs_get_booking_contact_form(); $ret['state'] = 3; } else { $validate = gdlr_validate_contact_form($contact); if (!empty($validate)) { $ret['state'] = 3; $ret['error_message'] = $validate; } else { $ret['summary_form'] = gdlrs_get_summary_form($data, false); if ($_POST['contact_type'] == 'contact') { $booking = gdlrs_insert_booking_db(array('data' => $data, 'contact' => $contact, 'payment_status' => 'booking')); global $hostel_option; $mail_content = gdlr_hostel_mail_content($contact, $data, array(), array('total_price' => $booking['total-price'], 'pay_amount' => 0, 'booking_code' => $booking['code'])); gdlr_hostel_mail($contact['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hostel_mail($hostel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $ret['content'] = gdlrs_booking_complete_message(); $ret['state'] = 4; } else { global $hostel_option; $booking = gdlrs_insert_booking_db(array('data' => $data, 'contact' => $contact, 'payment_status' => 'pending')); if ($contact['payment-method'] == 'paypal') { $ret['payment'] = 'paypal'; $ret['payment_url'] = $hostel_option['paypal-action-url']; $ret['addition_part'] = gdlrs_additional_paypal_part(array('title' => __('Room Booking', 'gdlr-hotel'), 'invoice' => $booking['invoice'], 'price' => $booking['pay-amount'])); } else { if ($contact['payment-method'] == 'stripe') { $ret['content'] = gdlrs_get_stripe_form(array('invoice' => $booking['invoice'])); } else { if ($contact['payment-method'] == 'paymill') { $ret['content'] = gdlrs_get_paymill_form(array('invoice' => $booking['invoice'])); } else { if ($contact['payment-method'] == 'authorize') { $ret['content'] = gdlrs_get_authorize_form(array('invoice' => $booking['invoice'], 'price' => $booking['pay-amount'])); } } } } // made payment $ret['state'] = 3; } } } } } if (!empty($data)) { $ret['data'] = $data; } die(json_encode($ret)); }
if (!empty($_GET['state']) && $_GET['state'] == 4 && !empty($_GET['invoice'])) { echo gdlr_booking_process_bar(4); } else { if (!empty($_POST['hotel_data'])) { echo gdlr_booking_process_bar(2); } else { echo gdlr_booking_process_bar(1); } } ?> <div class="gdlr-booking-content-wrapper" > <div class="gdlr-booking-content-inner" id="gdlr-booking-content-inner" > <?php if (!empty($_GET['state']) && $_GET['state'] == 4 && !empty($_GET['invoice'])) { echo gdlrs_booking_complete_message(); } else { if (!empty($_POST['hotel_data'])) { echo gdlrs_get_booking_room_query($_POST, 0); } else { echo gdlr_booking_date_range(); } } ?> </div> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> </div>
function gdlr_hostel_stripe_payment() { global $hostel_option; $ret = array(); Stripe::setApiKey($hostel_option['stripe-secret-key']); if (!empty($_POST['token']) && !empty($_POST['invoice'])) { global $wpdb; $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hostel_payment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); try { $charge = Stripe_Charge::create(array("amount" => floatval($result->pay_amount) * 100, "currency" => $hostel_option['stripe-currency-code'], "card" => $_POST['token'], "description" => $contact_info['email'])); $wpdb->update($wpdb->prefix . 'gdlr_hostel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($charge), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d')); $data = unserialize($result->booking_data); $mail_content = gdlr_hostel_mail_content($contact_info, $data, $charge, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hostel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hostel_mail($hostel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $ret['status'] = 'success'; $ret['message'] = __('Payment complete.', 'gdlr-hotel'); $ret['content'] = gdlrs_booking_complete_message(); } catch (Stripe_CardError $e) { $ret['status'] = 'failed'; $ret['message'] = $e->message; } } else { $ret['status'] = 'failed'; $ret['message'] = __('Failed to proceed, please try again.', 'gdlr-hotel'); } die(json_encode($ret)); }