Advertisement
enbaltasar

charge.php

Aug 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. <?php
  2. require_once('stripe-php/init.php');
  3. require_once('config/db.php');
  4. require_once('lib/pdo_db.php');
  5. require_once('models/customer.php');
  6. require_once('models/transaction.php');
  7.  
  8. \Stripe\Stripe::setApiKey('sk_live_xxxxxxxxxxxxx');
  9.  
  10. // Sanitize POST Array
  11. $POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
  12.  
  13. // Getting VALUES
  14. $property = "";
  15. $bedroom = "";
  16. $bathroom = "";
  17. $equipment = "";
  18. $extra = "";
  19. $area = "";
  20. $location_requirement = $POST['location_requirement'];
  21. $maximum_amount = $POST['maximum_amount'];
  22. $arrival_month = $POST['arrival_month'];
  23. $contract_time = $POST['contract_time'];
  24. $other_preferences = $POST['other_preferences'];
  25. $full_name = $POST['full_name'];
  26. $email = $POST['email'];
  27. $phone = $POST['phone'];
  28. $token = $POST['stripeToken'];
  29.  
  30. if(!empty($POST['property'])) // Loop to store and display values of individual checked checkbox.
  31. {
  32. foreach($POST['property'] as $selected)
  33. {
  34. $property .= $selected . " / ";
  35. }
  36. }
  37.  
  38.  
  39. if(!empty($POST['bedroom'])) // Loop to store and display values of individual checked checkbox.
  40. {
  41. foreach($POST['bedroom'] as $selected)
  42. {
  43. $bedroom .= $selected . " / ";
  44. }
  45. }
  46.  
  47.  
  48.  
  49. if(!empty($POST['bathroom'])) // Loop to store and display values of individual checked checkbox.
  50. {
  51. foreach($POST['bathroom'] as $selected)
  52. {
  53. $bathroom .= $selected . " / ";
  54. }
  55. }
  56.  
  57.  
  58.  
  59. if(!empty($POST['equipment'])) // Loop to store and display values of individual checked checkbox.
  60. {
  61. foreach($POST['equipment'] as $selected)
  62. {
  63. $equipment .= $selected . " / ";
  64. }
  65. }
  66.  
  67.  
  68.  
  69. if(!empty($POST['extra'])) // Loop to store and display values of individual checked checkbox.
  70. {
  71. foreach($POST['extra'] as $selected)
  72. {
  73. $extra .= $selected . " / ";
  74. }
  75. }
  76.  
  77.  
  78.  
  79. if(!empty($POST['area'])) // Loop to store and display values of individual checked checkbox.
  80. {
  81. foreach($POST['area'] as $selected)
  82. {
  83. $area .= $selected . " / ";
  84. }
  85. }
  86.  
  87.  
  88.  
  89. // Create Customer In Stripe
  90. $customer = \Stripe\Customer::create(array(
  91. "email" => $email,
  92. "source" => $token
  93. ));
  94.  
  95. // Charge Customer
  96. $charge = \Stripe\Charge::create(array(
  97. "amount" => 1500,
  98. "currency" => "eur",
  99. "description" => "Doraway - Market analysis",
  100. "customer" => $customer->id
  101. ));
  102.  
  103. // Customer Data
  104. $customerData = [
  105. 'id' => $charge->customer,
  106.  
  107. 'property' => $property,
  108. 'bedroom' => $bedroom,
  109. 'bathroom' => $bathroom,
  110. 'equipment' => $equipment,
  111. 'extra' => $extra,
  112. 'area' => $area,
  113. 'location_requirement' => $location_requirement,
  114. 'maximum_amount' => $maximum_amount,
  115. 'arrival_month' => $arrival_month,
  116. 'contract_time' => $contract_time,
  117. 'other_preferences' => $other_preferences,
  118. 'full_name' => $full_name,
  119. 'email' => $email,
  120. 'phone' => $phone
  121. ];
  122.  
  123. // Instantiate Customer
  124. $customer = new Customer();
  125.  
  126. // Add Customer To DB
  127. $customer->addCustomer($customerData);
  128.  
  129.  
  130. // Transaction Data
  131. $transactionData = [
  132. 'id' => $charge->id,
  133. 'customer_id' => $charge->customer,
  134. 'product' => $charge->description,
  135. 'amount' => $charge->amount,
  136. 'currency' => $charge->currency,
  137. 'status' => $charge->status,
  138. ];
  139.  
  140. // Instantiate Transaction
  141. $transaction = new Transaction();
  142.  
  143. // Add Transaction To DB
  144. $transaction->addTransaction($transactionData);
  145.  
  146. // Redirect to thank you page
  147. header('Location: thank-you.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement