Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('stripe-php/init.php');
- require_once('config/db.php');
- require_once('lib/pdo_db.php');
- require_once('models/customer.php');
- require_once('models/transaction.php');
- \Stripe\Stripe::setApiKey('sk_live_xxxxxxxxxxxxx');
- // Sanitize POST Array
- $POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
- // Getting VALUES
- $property = "";
- $bedroom = "";
- $bathroom = "";
- $equipment = "";
- $extra = "";
- $area = "";
- $location_requirement = $POST['location_requirement'];
- $maximum_amount = $POST['maximum_amount'];
- $arrival_month = $POST['arrival_month'];
- $contract_time = $POST['contract_time'];
- $other_preferences = $POST['other_preferences'];
- $full_name = $POST['full_name'];
- $email = $POST['email'];
- $phone = $POST['phone'];
- $token = $POST['stripeToken'];
- if(!empty($POST['property'])) // Loop to store and display values of individual checked checkbox.
- {
- foreach($POST['property'] as $selected)
- {
- $property .= $selected . " / ";
- }
- }
- if(!empty($POST['bedroom'])) // Loop to store and display values of individual checked checkbox.
- {
- foreach($POST['bedroom'] as $selected)
- {
- $bedroom .= $selected . " / ";
- }
- }
- if(!empty($POST['bathroom'])) // Loop to store and display values of individual checked checkbox.
- {
- foreach($POST['bathroom'] as $selected)
- {
- $bathroom .= $selected . " / ";
- }
- }
- if(!empty($POST['equipment'])) // Loop to store and display values of individual checked checkbox.
- {
- foreach($POST['equipment'] as $selected)
- {
- $equipment .= $selected . " / ";
- }
- }
- if(!empty($POST['extra'])) // Loop to store and display values of individual checked checkbox.
- {
- foreach($POST['extra'] as $selected)
- {
- $extra .= $selected . " / ";
- }
- }
- if(!empty($POST['area'])) // Loop to store and display values of individual checked checkbox.
- {
- foreach($POST['area'] as $selected)
- {
- $area .= $selected . " / ";
- }
- }
- // Create Customer In Stripe
- $customer = \Stripe\Customer::create(array(
- "email" => $email,
- "source" => $token
- ));
- // Charge Customer
- $charge = \Stripe\Charge::create(array(
- "amount" => 1500,
- "currency" => "eur",
- "description" => "Doraway - Market analysis",
- "customer" => $customer->id
- ));
- // Customer Data
- $customerData = [
- 'id' => $charge->customer,
- 'property' => $property,
- 'bedroom' => $bedroom,
- 'bathroom' => $bathroom,
- 'equipment' => $equipment,
- 'extra' => $extra,
- 'area' => $area,
- 'location_requirement' => $location_requirement,
- 'maximum_amount' => $maximum_amount,
- 'arrival_month' => $arrival_month,
- 'contract_time' => $contract_time,
- 'other_preferences' => $other_preferences,
- 'full_name' => $full_name,
- 'email' => $email,
- 'phone' => $phone
- ];
- // Instantiate Customer
- $customer = new Customer();
- // Add Customer To DB
- $customer->addCustomer($customerData);
- // Transaction Data
- $transactionData = [
- 'id' => $charge->id,
- 'customer_id' => $charge->customer,
- 'product' => $charge->description,
- 'amount' => $charge->amount,
- 'currency' => $charge->currency,
- 'status' => $charge->status,
- ];
- // Instantiate Transaction
- $transaction = new Transaction();
- // Add Transaction To DB
- $transaction->addTransaction($transactionData);
- // Redirect to thank you page
- header('Location: thank-you.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement