34853-vm/api/update_payment_intent.php
2025-10-11 05:03:50 +00:00

33 lines
989 B
PHP

<?php
require_once __DIR__ . '/../vendor/autoload.php';
\Stripe\Stripe::setApiKey('sk_test_51Hh9Y2L9s5P2Q8Z4sYgY8Z4sYgY8Z4sYgY8Z4sYgY8Z4sYgY8Z4sYgY8Z4sYgY8Z4sYgY8Z4sYgY8Z4');
header('Content-Type: application/json');
try {
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
if (empty($json_obj->payment_intent_id) || empty($json_obj->name) || empty($json_obj->email) || empty($json_obj->address)) {
throw new Exception("Missing required parameters.");
}
$paymentIntent = \Stripe\PaymentIntent::update(
$json_obj->payment_intent_id,
[
'receipt_email' => $json_obj->email,
'metadata' => [
'customer_name' => $json_obj->name,
'customer_address' => $json_obj->address
]
]
);
echo json_encode(['status' => 'success']);
} catch (Exception $e) {
http_response_code(400);
echo json_encode(['error' => $e->getMessage()]);
}