} $self_url .= $_SERVER["REQUEST_URI"]; $request->RedirectUrl = $self_url; $request->CancelUrl = $self_url; $request->Method = $_POST['ddlMethod']; $request->TransactionType = $_POST['ddlTransactionType']; $request->LogoUrl = $_POST['txtLogoUrl']; $request->HeaderText = $_POST['txtHeaderText']; $request->CustomerReadOnly = true; // Call RapidAPI $eway_params = array(); if ($_POST['ddlSandbox']) { $eway_params['sandbox'] = true; } $service = new eWAY\RapidAPI($_POST['txtUsername'], $_POST['txtPassword'], $eway_params); $result = $service->CreateAccessCodesShared($request); // Check if any error returns if (isset($result->Errors)) { // Get Error Messages from Error Code. Error Code Mappings are in the Config.ini file $ErrorArray = explode(",", $result->Errors); $lblError = ""; foreach ($ErrorArray as $error) { $error = $service->getMessage($error); $lblError .= $error . "<br />\n"; } } else { $_SESSION['eWAY_username'] = $_POST['txtUsername']; $_SESSION['eWAY_password'] = $_POST['txtPassword']; $_SESSION['eWAY_sandbox'] = $_POST['ddlSandbox']; header("Location: " . $result->SharedPaymentUrl); exit;
/** * Booking 4/4 */ public static function carrental_confirm_reservation() { $order_hash = self::save_booking($_POST); if ((int) $_POST['paypal'] == 1 && (double) $_POST['total_rental'] > 0) { $paypal = get_option('carrental_paypal'); $available_payments = unserialize(get_option('carrental_available_payments')); if (isset($available_payments) && isset($available_payments['carrental-paypal-security-deposit']) && (double) $available_payments['carrental-paypal-security-deposit'] > 0) { // if paypal security deposit is set $_POST['total_rental'] = $_POST['total_rental'] * ((double) $available_payments['carrental-paypal-security-deposit'] / 100); if (isset($available_payments['carrental-paypal-security-deposit-round'])) { if ($available_payments['carrental-paypal-security-deposit-round'] == 'up') { $_POST['total_rental'] = ceil($_POST['total_rental']); } elseif ($available_payments['carrental-paypal-security-deposit-round'] == 'down') { $_POST['total_rental'] = floor($_POST['total_rental']); } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } // Redirect to PayPal $query = array(); $query['cmd'] = '_xclick'; $query['business'] = $paypal; $query['email'] = $_POST['email']; $query['item_name'] = 'Car Rental Reservation #' . $order_hash; $query['quantity'] = 1; $query['return'] = home_url() . '?page=carrental&payment=paypal&summary=' . $order_hash; $query['item_number'] = $order_hash; $query['custom'] = isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language']) ? $_SESSION['carrental_language'] : 'en_GB'; $query['notify_url'] = CARRENTAL__PLUGIN_URL . 'paypal_ipn.php'; $query['cancel_return'] = $_SERVER['HTTP_REFERER'] . '&paymentError=1'; $query['amount'] = number_format((double) $_POST['total_rental'], 2, '.', ''); $query['currency_code'] = $_POST['currency_code']; // Prepare query string $query_string = http_build_query($query); Header('Location: https://www.paypal.com/cgi-bin/webscr?' . $query_string); return; } // is it eway payment? if ($_POST['payment_option'] == 'eway' && (double) $_POST['total_rental'] > 0) { $payments_others = unserialize(get_option('carrental_available_payments_others')); if ($payments_others && !empty($payments_others) && isset($payments_others['eway']) && $payments_others['eway']['enabled'] == 'yes' && (double) $payments_others['eway']['security-deposit'] > 0) { $_POST['total_rental'] = $_POST['total_rental'] * ((double) $payments_others['eway']['security-deposit'] / 100); if (isset($payments_others['eway']['security-deposit-round'])) { if ($payments_others['eway']['security-deposit-round'] == 'up') { $_POST['total_rental'] = ceil($_POST['total_rental']); } elseif ($payments_others['eway']['security-deposit-round'] == 'down') { $_POST['total_rental'] = floor($_POST['total_rental']); } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } require_once dirname(dirname(__FILE__)) . '/carrental-payments-eway/RapidAPI.php'; $request = new eWAY\CreateAccessCodesSharedRequest(); $request->Payment->TotalAmount = number_format((double) $_POST['total_rental'], 2, '.', '') * 100; // Amount is in cents, 100 = $1.00 //$request->Payment->CurrencyCode = 'AUD';//$_POST['currency_code']; $request->Payment->InvoiceReference = $order_hash; $request->Options->Option[] = isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language']) ? $_SESSION['carrental_language'] : 'en_GB'; $request->RedirectUrl = CARRENTAL__PLUGIN_URL . 'eway_ipn.php'; $request->CancelUrl = $_SERVER['HTTP_REFERER'] . '&ewayError=1'; $service = new eWAY\RapidAPI($payments_others['eway']['api-key'], $payments_others['eway']['api-password']); //print_r($request);die(); // Get the AccessCode $result = $service->CreateAccessCodesShared($request); if (!empty($result->Errors)) { die(eWAY\ResponseCode::getMessage($result->Errors)); } // Send the customer to eWAY to pay header("Location: " . $result->SharedPaymentUrl); exit; } } // is it mercadopago payment? if ($_POST['payment_option'] == 'mercadopago' && (double) $_POST['total_rental'] > 0) { $payments_others = unserialize(get_option('carrental_available_payments_others')); if ($payments_others && !empty($payments_others) && isset($payments_others['mercadopago']) && $payments_others['mercadopago']['enabled'] == 'yes' && (double) $payments_others['mercadopago']['security-deposit'] > 0) { $_POST['total_rental'] = $_POST['total_rental'] * ((double) $payments_others['mercadopago']['security-deposit'] / 100); if (isset($payments_others['mercadopago']['security-deposit-round'])) { if ($payments_others['mercadopago']['security-deposit-round'] == 'up') { $_POST['total_rental'] = ceil($_POST['total_rental']); } elseif ($payments_others['mercadopago']['security-deposit-round'] == 'down') { $_POST['total_rental'] = floor($_POST['total_rental']); } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } } else { $_POST['total_rental'] = round($_POST['total_rental'], 2); } require_once dirname(dirname(__FILE__)) . '/carrental-payments-mercadopago/mercadopago.php'; $mp = new MP($payments_others['mercadopago']['client-id'], $payments_others['mercadopago']['client-secret']); $sandbox = false; $mp->sandbox_mode($sandbox); $preference_data = array("items" => array(array("id" => $order_hash, "title" => 'Car Rental Reservation #' . $order_hash, "currency_id" => 'ARS', "category_id" => "Category", "quantity" => 1, "unit_price" => (double) number_format((double) $_POST['total_rental'], 2, '.', ''))), "back_urls" => array("success" => home_url() . '?page=carrental&payment=paypal&summary=' . $order_hash, "failure" => $_SERVER['HTTP_REFERER'] . '&paymentError=1', "pending" => home_url() . '?page=carrental&payment=paypal&summary=' . $order_hash), "auto_return" => "approved", "notification_url" => CARRENTAL__PLUGIN_URL . 'mercadopago_ipn.php', "external_reference" => $order_hash . '#' . (isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language']) ? $_SESSION['carrental_language'] : 'en_GB'), "expires" => false, "expiration_date_from" => null, "expiration_date_to" => null); try { $preference = $mp->create_preference($preference_data); } catch (Exception $e) { echo 'Error during MercadoPago payment: ' . $e->getMessage() . '. Please contact the administrator.'; exit; } Header('Location: ' . $preference['response'][($sandbox ? 'sandbox_' : '') . 'init_point']); exit; } } do_action('carrental_after_save_booking', $order_hash); Header('Location: ' . home_url() . '?page=carrental&summary=' . $order_hash); exit; }