$id = filter_input(INPUT_POST, 'custID'); $firstName = filter_input(INPUT_POST, 'fName'); $lastName = filter_input(INPUT_POST, 'lName'); $street = filter_input(INPUT_POST, 'street'); $postalCode = filter_input(INPUT_POST, 'postalCode'); $province = filter_input(INPUT_POST, 'province'); $phone = filter_input(INPUT_POST, 'phone'); $email_account = filter_input(INPUT_POST, 'email_account'); $password = filter_input(INPUT_POST, 'password'); $confirm_password = filter_input(INPUT_POST, 'confirm_password'); $action = filter_input(INPUT_POST, 'action'); $remember = filter_input(INPUT_POST, 'remember'); //create customer if ($action == "register") { if (is_valid_password($password, $confirm_password)) { create_customer($firstName, $lastName, $street, $postalCode, $province, $phone, $email_account, $password); echo "thank you for registering"; } else { echo "Please make sure your password is the same"; } } else { if ($action == "login") { if (is_valid_customer_login($email_account, $password)) { echo "Logged in<br/>"; echo $remember . "<br/>"; if ($remember) { echo "Email remembered!<br/>"; setcookie("email", $email_account, 0, "/"); } start_cart_session(); header("location:" . $home_path . "catalog/products.php");
if (isset($_POST['customer_id'])) { $charge = Stripe_Charge::create(array('customer' => $_POST['customer_id'], 'amount' => 53500, 'currency' => 'usd', 'description' => 'Single quote purchase after login')); } else { if (isset($_POST['stripeToken'])) { // Simple uniqueness check on the email address $existing_customer = get_customer($_POST['email']); if ($existing_customer) { throw new Exception("That e-mail address already exists"); } if (isset($_POST['subscription_purchase'])) { $customer = Stripe_Customer::create(array('card' => $_POST['stripeToken'], 'email' => $_POST['email'], 'plan' => 'monthly')); } else { $customer = Stripe_Customer::create(array('card' => $_POST['stripeToken'], 'email' => $_POST['email'])); $charge = Stripe_Charge::create(array('customer' => $customer->id, 'amount' => 53500, 'currency' => 'usd', 'description' => 'Single quote purchase')); } create_customer($_POST['email'], $_POST['password'], $customer->id); } else { throw new Exception("The Stripe Token or customer was not generated correctly"); } } } catch (Exception $e) { $error = $e->getMessage(); } if ($error == NULL) { if (isset($_POST['subscription_purchase'])) { echo "<h2>Thank you for signing up! You'll be getting your Wilde quotes daily in your e-mail</h2>"; } else { $wildeQuotes = array("A little sincerity is a dangerous thing, and a great deal of it is absolutely fatal.", "Always forgive your enemies; nothing annoys them so much.", "America is the only country that went from barbarism to decadence without civilization in between.", "I think that God in creating Man somewhat overestimated his ability.", "I am not young enough to know everything.", "Fashion is a form of ugliness so intolerable that we have to alter it every six months.", "Most modern calendars mar the sweet simplicity of our lives by reminding us that each day that passes is the anniversary of some perfectly uninteresting event.", "Scandal is gossip made tedious by morality."); echo "<h1>Here's your quote!</h1>"; echo "<h2>" . $wildeQuotes[array_rand($wildeQuotes)] . "</h2>"; }
// Simple uniqueness check on the email address $existing_customer = get_customer($_POST['stripeEmail']); if ($existing_customer) { throw new Exception("That e-mail address already exists"); } if (isset($_POST['ticket_type'])) { $customer = \Stripe\Customer::create(array('source' => $_POST['stripeToken'], 'email' => $_POST['stripeEmail'])); if ($_POST['ticket_type'] == 'player_ticket') { $charge = \Stripe\Charge::create(array('customer' => $customer->id, 'amount' => 7000, 'currency' => 'gbp', 'description' => 'Player Ticket')); } else { $charge = \Stripe\Charge::create(array('customer' => $customer->id, 'amount' => 1700, 'currency' => 'gbp', 'description' => 'Crew Ticket')); } } else { throw new Exception("No ticket type supplied"); } create_customer($_POST['stripeEmail'], $_POST['password'], $customer->id); } else { throw new Exception("The Stripe Token or customer was not generated correctly"); } } } catch (Exception $e) { $error = $e->getMessage(); } if (!$error) { if ($_POST['ticket_type'] == 'player_ticket') { echo "<h3>You're signed up as a player</h3>"; } else { echo "<h3>You're signed up as crew</h3>"; } } else { echo "<div class=\"error\">" . $error . "</div>";
{ try { $customer = \Stripe\Customer::retrieve($customer_id); $subscription = $customer->subscriptions->retrieve($suscription_id); $subscription->cancel(); } catch (Exception $e) { http_response_code(404); return $e->getJsonBody(); } } if (!empty($_REQUEST['requestedOption'])) { $requestedOption = $_REQUEST['requestedOption']; header('Content-Type: application/json'); switch ($requestedOption) { case "create_customer": $customer_id = create_customer($_REQUEST['planID'], $_REQUEST['email'], $_REQUEST["stripeToken"]); echo json_encode($customer_id, JSON_PRETTY_PRINT); break; case "create_plan": $plan_id = create_plan($_REQUEST['amount'], $_REQUEST['interval'], $_REQUEST["name"], $_REQUEST["currency"], $_REQUEST["id"]); echo json_encode($plan_id, JSON_PRETTY_PRINT); break; case "cancel_suscription": $cancel_suscription_response = cancel_suscription($_REQUEST['customer_id'], $_REQUEST['suscription_id']); echo json_encode($cancel_suscription_response, JSON_PRETTY_PRINT); break; case "update_suscription": $update_suscription_response = update_suscription($_REQUEST['customer_id'], $_REQUEST['planID']); echo json_encode($update_suscription_response, JSON_PRETTY_PRINT); break; default:
} function charge_subscription($stripeToken) { try { if (!isset($stripeToken)) { throw new Exception("The Stripe Token was not generated correctly"); } \Stripe\Charge::create(array("amount" => 1000, "currency" => "usd", "card" => $stripeToken)); $success = 'Your payment was successful.'; } catch (Exception $e) { $error = $e->getMessage(); } } //create_plan(); //subscribe_to_plan($_REQUEST['stripeToken'],$_REQUEST['planID'],$_REQUEST['email']); $customer_id = create_customer("year_suscription", "*****@*****.**", $_REQUEST["stripeToken"]); echo json_encode($customer_id, JSON_PRETTY_PRINT); //$customer_id //charge_subscription($_REQUEST['stripeToken'],$customer_id); } else { ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Stripe Getting Started Form</title> <script type="text/javascript" src="https://js.stripe.com/v1/"></script> <!-- jQuery is used only for this example; it isn't required to use Stripe --> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript">