header('Location: ../user/sign_in.php'); exit; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $order = $_REQUEST['order']; try { if ($order['payment_method'] == 'credit_card') { // Make a payment using credit card. $user = getUser(getSignedInUser()); $payment = makePaymentUsingCC($user['creditcard_id'], $order['amount'], 'USD', $order['description']); $orderId = addOrder(getSignedInUser(), $payment->getId(), $payment->getState(), $order['amount'], $order['description']); $message = "Your order has been placed successfully. Your Order id is <b>{$orderId}</b>"; $messageType = "success"; } else { if ($order['payment_method'] == 'paypal') { $orderId = addOrder(getSignedInUser(), NULL, NULL, $order['amount'], $order['description']); // Create the payment and redirect buyer to paypal for payment approval. $baseUrl = getBaseUrl() . "/order_completion.php?orderId={$orderId}"; $payment = makePaymentUsingPayPal($order['amount'], 'USD', $order['description'], "{$baseUrl}&success=true", "{$baseUrl}&success=false"); updateOrder($orderId, $payment->getState(), $payment->getId()); header("Location: " . getLink($payment->getLinks(), "approval_url")); exit; } } } catch (\PayPal\Exception\PPConnectionException $ex) { $message = parseApiError($ex->getData()); $messageType = "error"; } catch (Exception $ex) { $message = $ex->getMessage(); $messageType = "error"; }
<?php /* * User profile page. User can view/edit his * password and credit card information from here. */ require_once __DIR__ . '/../bootstrap.php'; session_start(); if (!isSignedIn()) { header('Location: sign_in.php'); exit; } try { $user = getUser(getSignedInUser()); if (isset($user['creditcard_id']) && $user['creditcard_id'] != NULL) { $card = getCreditCard($user['creditcard_id']); } // Sign in form postback if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Confirm that the user has provided the correct current password if (validateLogin($_POST['user']['email'], $_POST['user']['current_password'])) { $creditCardId = NULL; $newPassword = NULL; $newCard = array_map('trim', $_POST['user']['credit_card']); $newValues = count(array_filter($newCard, 'strlen')); // Update credit card info if new credit card data has been provided if ($newValues > 0 && $newValues < 5) { $message = "Please fill in all required credit card values."; $messageType = "error"; } else { if ($newValues == 5) {
<?php /* * Order listing page. We rely on the local database * to retrieve the order history of this buyer. */ require_once __DIR__ . '/../bootstrap.php'; if (!isset($_SESSION)) { session_start(); } if (!isSignedIn()) { header('Location: ../user/sign_in.php'); exit; } try { $orders = getOrders(getSignedInUser()); } catch (Exception $ex) { // Don't overwrite any message that was already set if (!isset($message)) { $message = $ex->getMessage(); $messageType = "error"; } $orders = array(); } ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <meta content='IE=Edge,chrome=1' http-equiv='X-UA-Compatible'> <meta content='width=device-width, initial-scale=1.0' name='viewport'>