Add PayPal webhook handler and marketing styles
- Implemented PayPal webhook for handling payment notifications, including signature verification and transaction updates. - Created invoice generation and license management for software upgrades upon successful payment. - Added comprehensive logging for debugging purposes. - Introduced new CSS styles for the marketing file management system, including layout, toolbar, breadcrumb navigation, search filters, and file management UI components.
This commit is contained in:
@@ -20,6 +20,72 @@ $bearertoken = createCommunicationToken($_SESSION['userkey']);
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
$payment_return = isset($_GET['order_id']) ? $_GET['order_id'] : null;
|
||||
$payment_return_status = isset($_GET['payment_return']) ? $_GET['payment_return'] : null;
|
||||
$paypal_token = isset($_GET['token']) ? $_GET['token'] : null; // PayPal returns with ?token=
|
||||
|
||||
// Handle PayPal return - capture the order directly
|
||||
if ($paypal_token && $payment_return) {
|
||||
try {
|
||||
// Get PayPal access token
|
||||
$ch = curl_init(PAYPAL_URL . '/v1/oauth2/token');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
|
||||
curl_setopt($ch, CURLOPT_USERPWD, PAYPAL_CLIENT_ID . ':' . PAYPAL_CLIENT_SECRET);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$token_data = json_decode($response, true);
|
||||
$access_token = $token_data['access_token'] ?? '';
|
||||
|
||||
if ($access_token) {
|
||||
// Capture the PayPal order
|
||||
$capture_url = PAYPAL_URL . "/v2/checkout/orders/{$paypal_token}/capture";
|
||||
$ch = curl_init($capture_url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer ' . $access_token
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if (debug) {
|
||||
debuglog("PayPal Capture: HTTP $http_code - $response");
|
||||
}
|
||||
|
||||
// Update transaction status based on capture result
|
||||
if ($http_code == 200 || $http_code == 201) {
|
||||
$capture_result = json_decode($response, true);
|
||||
$capture_status = $capture_result['status'] ?? '';
|
||||
|
||||
$payment_status = null;
|
||||
if ($capture_status === 'COMPLETED') {
|
||||
$payment_status = 1; // Paid
|
||||
} elseif ($capture_status === 'PENDING') {
|
||||
$payment_status = 101; // Pending
|
||||
}
|
||||
|
||||
if ($payment_status !== null) {
|
||||
$pdo = dbConnect($dbname);
|
||||
$sql = 'UPDATE transactions SET payment_status = ? WHERE txn_id = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$payment_status, $payment_return]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to clean URL
|
||||
header("Location: ?page=softwaretool&payment_return=1&order_id={$payment_return}");
|
||||
exit;
|
||||
|
||||
} catch (Exception $e) {
|
||||
if (debug) {
|
||||
debuglog("PayPal Capture Error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template_header('Softwaretool', 'softwaretool','view');
|
||||
|
||||
@@ -205,6 +271,9 @@ echo '
|
||||
<script>
|
||||
var link = "'.$baseurl.'";
|
||||
var DEBUG = '.(debug ? 'true' : 'false').';
|
||||
var MOLLIE_ENABLED = '.(mollie_enabled ? 'true' : 'false').';
|
||||
var PAYPAL_ENABLED = '.(paypal_enabled ? 'true' : 'false').';
|
||||
var PAY_ON_DELIVERY_ENABLED = '.(pay_on_delivery_enabled ? 'true' : 'false').';
|
||||
var port, textEncoder, writableStreamClosed, writer, historyIndex = -1;
|
||||
const lineHistory = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user