function gdlr_paypal_ipn() { if (isset($_GET['paypal'])) { global $hotel_option; // STEP 1: read POST data $raw_post_data = file_get_contents('php://input'); $raw_post_array = explode('&', $raw_post_data); $myPost = array(); foreach ($raw_post_array as $keyval) { $keyval = explode('=', $keyval); if (count($keyval) == 2) { $myPost[$keyval[0]] = urldecode($keyval[1]); } } // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' $req = 'cmd=_notify-validate'; if (function_exists('get_magic_quotes_gpc')) { $get_magic_quotes_exists = true; } foreach ($myPost as $key => $value) { if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { $value = urlencode(stripslashes($value)); } else { $value = urlencode($value); } $req .= "&{$key}={$value}"; } // Step 2: POST IPN data back to PayPal to validate $ch = curl_init($hotel_option['paypal-action-url']); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); if (!($res = curl_exec($ch))) { curl_close($ch); exit; } curl_close($ch); // inspect IPN validation result and act accordingly if (strcmp($res, "VERIFIED") == 0) { global $wpdb; $_POST['invoice'] = substr($_POST['invoice'], 8); $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($_POST), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d')); $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); $data = unserialize($result->booking_data); $mail_content = gdlr_hotel_mail_content($contact_info, $data, $_POST, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); } } }
function gdlr_apply_hotel_transaction() { global $wpdb; if (!empty($_POST['tid'])) { foreach ($_POST['tid'] as $id) { if ($_POST['transaction-type'] == 'cancel') { $wpdb->delete($wpdb->prefix . 'gdlr_hotel_payment', array('id' => $id), array('%d')); $wpdb->delete($wpdb->prefix . 'gdlr_hotel_booking', array('payment_id' => $id), array('%d')); } else { if ($_POST['transaction-type'] == 'read' || $_POST['transaction-type'] == 'unread') { if ($_POST['transaction-type'] == 'read') { $status = 'read'; } else { if ($_POST['transaction-type'] == 'unread') { $status = ''; } } $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('read_status' => $status), array('id' => $id), array('%s'), array('%d')); } else { if ($_POST['transaction-type'] == 'paid') { $status = 'paid'; } else { if ($_POST['transaction-type'] == 'booking') { $status = 'booking'; } } // send email to user $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment "; $temp_sql .= "WHERE id = " . $id; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); $data = unserialize($result->booking_data); $mail_content = gdlr_hotel_mail_content($contact_info, $data, '', array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('payment_status' => $status), array('id' => $id), array('%s'), array('%d')); } } } } }
function gdlr_ajax_hotel_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']; $room_number = gdlr_get_edited_room($data['gdlr-room-number'], $data['gdlr-room-id']); // room form $ret['room_form'] = gdlr_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'] = gdlr_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'] .= gdlr_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] . '" />'; } } if (empty($_POST['contact'])) { $ret['summary_form'] = gdlr_get_summary_form($data); $ret['content'] = gdlr_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'] = gdlr_get_summary_form($data, false); if ($_POST['contact_type'] == 'contact') { $booking = gdlr_insert_booking_db(array('data' => $data, 'contact' => $contact, 'payment_status' => 'booking')); global $hotel_option; $mail_content = gdlr_hotel_mail_content($contact, $data, array(), array('total_price' => $booking['total-price'], 'pay_amount' => 0, 'booking_code' => $booking['code'])); gdlr_hotel_mail($contact['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $ret['content'] = gdlr_booking_complete_message(); $ret['state'] = 4; } else { global $hotel_option; $booking = gdlr_insert_booking_db(array('data' => $data, 'contact' => $contact, 'payment_status' => 'pending')); if ($contact['payment-method'] == 'paypal') { $ret['payment'] = 'paypal'; $ret['payment_url'] = $hotel_option['paypal-action-url']; $ret['addition_part'] = gdlr_additional_paypal_part(array('title' => __('Room Booking', 'gdlr-hotel'), 'invoice' => $booking['invoice'], 'price' => $booking['pay-amount'])); } else { if ($contact['payment-method'] == 'stripe') { $ret['content'] = gdlr_get_stripe_form(array('invoice' => $booking['invoice'])); } else { if ($contact['payment-method'] == 'paymill') { $ret['content'] = gdlr_get_paymill_form(array('invoice' => $booking['invoice'])); } else { if ($contact['payment-method'] == 'authorize') { $ret['content'] = gdlr_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)); }
function gdlr_hotel_paymill_payment() { global $hotel_option; $ret = array(); if (!empty($_POST['token']) && !empty($_POST['invoice'])) { global $wpdb; $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment "; $temp_sql .= "WHERE id = " . $_POST['invoice']; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); $apiKey = $hotel_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($hotel_option['paymill-currency-code'])->setPayment($paymentId)->setDescription($payment_info['email']); $response = $request->create($transaction); $wpdb->update($wpdb->prefix . 'gdlr_hotel_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_hotel_mail_content($contact_info, $data, $response, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $ret['status'] = 'success'; $ret['message'] = __('Payment complete', 'gdlr-hotel'); $ret['content'] = gdlr_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)); }
<?php if (!empty($_GET['invoice']) && !empty($_GET['response']) && $_GET['response'] == 1) { include_once '../../../../wp-load.php'; include_once 'payment-api/authorize-php/autoload.php'; global $hotel_option, $wpdb; $response = new AuthorizeNetSIM($hotel_option['authorize-api-id'], $hotel_option['authorize-md5-hash']); if ($response->isAuthorizeNet()) { if ($response->approved) { $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_GET['invoice']), array('%s', '%s', '%s'), array('%d')); $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment "; $temp_sql .= "WHERE id = " . $_GET['invoice']; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); $data = unserialize($result->booking_data); $mail_content = gdlr_hotel_mail_content($contact_info, $data, $response, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice']), home_url()); } else { $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice'], 'response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text), home_url()); } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { die("Error. Check your MD5 Setting."); $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice'], 'response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text), home_url()); ?> <html> <head> <script type='text/javascript'charset='utf-8'>window.location='<?php
function gdlr_hotel_stripe_payment() { global $hotel_option; $ret = array(); Stripe::setApiKey($hotel_option['stripe-secret-key']); if (!empty($_POST['token']) && !empty($_POST['invoice'])) { global $wpdb; $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_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" => $hotel_option['stripe-currency-code'], "card" => $_POST['token'], "description" => $contact_info['email'])); $wpdb->update($wpdb->prefix . 'gdlr_hotel_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_hotel_mail_content($contact_info, $data, $charge, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $ret['status'] = 'success'; $ret['message'] = __('Payment complete.', 'gdlr-hotel'); $ret['content'] = gdlr_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)); }