First Commit

This commit is contained in:
mark committed 2026-10-19 15:22:52 -07:00
1 parent 5eb9dd037d
commit 2e62c0e60b
11877 files changed
+2035312

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
<?php
$config = require __DIR__ . '/config.php';
require __DIR__ . '/lib/PayPalClient.php';
require __DIR__ . '/lib/Storage.php';
$orderId = $_GET['token'] ?? $_GET['orderId'] ?? null; // token param from PayPal return
if (!$orderId) {
http_response_code(400);
echo 'Missing orderId/token';
exit;
}
$client = new PayPalClient($config);
$storage = new Storage($config['storage_path']);
// Capture the order
$resp = $client->api('POST', '/v2/checkout/orders/' . urlencode($orderId) . '/capture');
if ($resp['status'] < 200 || $resp['status'] >= 300) {
http_response_code(500);
echo 'Capture failed: ' . htmlspecialchars(json_encode($resp));
exit;
}
$capture = $resp['body'];
// Update local order store
$orders = $storage->get('orders', []);
if (isset($orders[$orderId])) {
$orders[$orderId]['status'] = $capture['status'] ?? 'CAPTURED';
$storage->set('orders', $orders);
}
// Redirect back to home with a status indicator
$baseUrl = rtrim($config['base_url'], '/');
$status = isset($capture['status']) ? $capture['status'] : 'CAPTURED';
header('Location: ' . $baseUrl . '/index.php?captured=1&order=' . urlencode($orderId) . '&status=' . urlencode($status));
exit;