-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharge.php
More file actions
52 lines (43 loc) · 1.59 KB
/
charge.php
File metadata and controls
52 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once('vendor/autoload.php');
$stripe_secret_key = "sk_test_51P5BWqSGjdbQxRsmxAUTdULLeON7Y9s2RGBFSqg9mLBDCESaB3CaNcm61BlCpgb3nEEVsvVpD994W99rcPiDId6g00kz9F3hca";
$eventPrice = $_POST["eventCost"];
$eventId = $_POST["eventId"];
\Stripe\Stripe::setApiKey($stripe_secret_key);
// Create a new customer
$customer = \Stripe\Customer::create([
"name" => "Charusat",
"address" => [
"line1" => "123, Sample Street",
"city" => "New York",
"state" => "NY",
"postal_code" => "10001",
"country" => "US", // Billing address outside India
]
]);
// Get the customer ID
$customer_id = $customer->id;
$checkout_session = \Stripe\Checkout\Session::create([
"mode" => "payment",
"success_url" => "http://localhost/miniprojectV2/success.php?eventId={$eventId}&session_id={CHECKOUT_SESSION_ID}",
// Replace {PAYMENT_INTENT_ID} with the actual Payment Intent ID
"line_items" => [
[
"quantity" => "1",
"price_data" => [
"currency" => "inr", // Use USD for non-INR transactions
"unit_amount" => $eventPrice * 100, // Dummy unit amount (in cents)
"product_data" => [
"name" => $eventId
]
]
]
],
// Use the customer ID in the checkout session
"customer" => $customer_id,
]);
// Replace {PAYMENT_INTENT_ID} with the actual Payment Intent ID
$redirect_url = str_replace("{CHECKOUT_SESSION_ID}", $checkout_session->payment_intent, $checkout_session->url);
http_response_code(303);
header("Location:".$redirect_url);
?>