[www-doc] [Git][VideoLAN.org/websites][master] donation: add stripe as an option

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sat May 2 20:55:03 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN organization / websites


Commits:
25880bc2 by Felix Paul Kühne at 2026-05-02T22:40:04+02:00
donation: add stripe as an option

- - - - -


3 changed files:

- www.videolan.org/contribute.php
- + www.videolan.org/include/donate_stripe.php
- + www.videolan.org/stripe/checkout.php


Changes:

=====================================
www.videolan.org/contribute.php
=====================================
@@ -3,6 +3,7 @@ $title = "Contribute to the project";
 $lang = "en";
 $menu = array( "project", "contribute" );
 require($_SERVER["DOCUMENT_ROOT"]."/include/header.php");
+require_once($_SERVER["DOCUMENT_ROOT"]."/include/donate_stripe.php");
 ?>
 
 <div id="fullwidth">
@@ -87,6 +88,23 @@ require($_SERVER["DOCUMENT_ROOT"]."/include/header.php");
                 <p> VideoLAN is a non-profit organization, under French law.
                     VideoLAN has its own bank account and is responsible for running and maintaining the VideoLAN servers. </p>
 
+                <h3>Donate to VideoLAN via card, Apple Pay, Google Pay or SEPA</h3>
+                <a id="stripe"></a>
+
+                <p> You can donate by credit or debit card, Apple Pay, Google Pay,
+                    or SEPA Direct Debit (for EUR donations from eligible European bank accounts).
+                    Payments are processed securely by <a href="https://stripe.com/">Stripe</a>;
+                    no account is required. </p>
+
+                <div style="margin-left: 60px;">
+                    <p><span style="font-size: 10pt;"><strong>Euros €</strong></span></p>
+                    <?php draw_stripe_donate('EUR'); ?>
+                </div>
+                <div style="margin-left: 60px;">
+                    <p><span style="font-size: 10pt;"><strong>Dollars $</strong></span></p>
+                    <?php draw_stripe_donate('USD'); ?>
+                </div>
+
                 <h3>Donate to VideoLAN via PayPal</h3>
                 <a id="paypal"></a>
 


=====================================
www.videolan.org/include/donate_stripe.php
=====================================
@@ -0,0 +1,29 @@
+<?php
+/*
+ * Renders a donation form that redirects to Stripe Checkout.
+ * Supported $currency_code values: 'EUR', 'USD'.
+ */
+function draw_stripe_donate( $currency_code, $amount = null ) {
+    switch ($currency_code) {
+        case 'EUR':
+            $class = 'euros';
+            $amount = !is_null($amount) ? $amount : '4.00';
+            break;
+        case 'USD':
+            $class = 'dollars';
+            $amount = !is_null($amount) ? $amount : '5.00';
+            break;
+        default:
+            return;
+    }
+?>
+<form class="donate2" action="/stripe/checkout.php" method="post">
+    <fieldset>
+        <input name="currency" value="<?php echo $currency_code ?>" type="hidden"/>
+        <input class="<?php echo $class ?>" type="text" name="amount" value="<?php echo $amount ?>" inputmode="decimal" pattern="[0-9]+([.,][0-9]{1,2})?" required/>
+        <button type="submit"><?php echo _("donate"); ?></button>
+    </fieldset>
+</form>
+<?php
+}
+?>


=====================================
www.videolan.org/stripe/checkout.php
=====================================
@@ -0,0 +1,99 @@
+<?php
+/*
+ * Creates a Stripe Checkout Session and 303-redirects the donor to it.
+ */
+
+if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
+    header('Location: /contribute.html#money', true, 303);
+    exit;
+}
+
+require_once '/home/videolan/etc/stripe.inc.php';
+if (empty($secret_key)) {
+    http_response_code(500);
+    echo 'Donations via card are temporarily unavailable. Please use one of the other donation methods on the contribute page.';
+    error_log('donate_stripe: $secret_key not set');
+    exit;
+}
+
+$currency = isset($_POST['currency']) ? strtoupper(trim($_POST['currency'])) : '';
+if ($currency !== 'EUR' && $currency !== 'USD') {
+    http_response_code(400);
+    echo 'Invalid currency.';
+    exit;
+}
+
+$raw_amount = isset($_POST['amount']) ? str_replace(',', '.', trim($_POST['amount'])) : '';
+if (!preg_match('/^\d+(\.\d{1,2})?$/', $raw_amount)) {
+    http_response_code(400);
+    echo 'Invalid amount.';
+    exit;
+}
+$unit_amount = (int) round(((float) $raw_amount) * 100);
+if ($unit_amount < 100 || $unit_amount > 10000000) {
+    http_response_code(400);
+    echo 'Amount out of range (minimum 1.00, maximum 100000.00).';
+    exit;
+}
+
+$params = [
+    'mode' => 'payment',
+    'submit_type' => 'donate',
+    'success_url' => 'https://www.videolan.org/thank_you.html?session_id={CHECKOUT_SESSION_ID}',
+    'cancel_url' => 'https://www.videolan.org/contribute.html#money',
+    'line_items' => [
+        [
+            'quantity' => 1,
+            'price_data' => [
+                'currency' => strtolower($currency),
+                'unit_amount' => $unit_amount,
+                'product_data' => [
+                    'name' => 'Donation to VideoLAN',
+                    'description' => 'Development and communication of VideoLAN',
+                    'images' => [
+                        'https://images.videolan.org/images/goodies/Cone-Video-small.png',
+                    ],
+                ],
+            ],
+        ],
+    ],
+    'metadata' => [
+        'item_name' => 'Development and communication of VideoLAN',
+    ],
+];
+
+$ch = curl_init('https://api.stripe.com/v1/checkout/sessions');
+curl_setopt_array($ch, [
+    CURLOPT_RETURNTRANSFER => true,
+    CURLOPT_POST => true,
+    CURLOPT_POSTFIELDS => http_build_query($params, '', '&'),
+    CURLOPT_HTTPHEADER => [
+        'Authorization: Bearer ' . $secret_key,
+        'Content-Type: application/x-www-form-urlencoded',
+    ],
+    CURLOPT_TIMEOUT => 15,
+]);
+$response = curl_exec($ch);
+$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
+$err = curl_error($ch);
+unset($ch);
+
+if ($response === false) {
+    http_response_code(502);
+    error_log('donate_stripe: curl error: ' . $err);
+    echo 'Could not reach payment provider. Please try again later.';
+    exit;
+}
+
+$body = json_decode($response, true);
+if ($status >= 400 || !isset($body['url'])) {
+    http_response_code(502);
+    $msg = isset($body['error']['message']) ? $body['error']['message'] : 'unknown error';
+    error_log('donate_stripe: Stripe API error (HTTP ' . $status . '): ' . $msg);
+    echo 'Could not start the payment session. Please try again later.';
+    exit;
+}
+
+header('Location: ' . $body['url'], true, 303);
+exit;
+?>



View it on GitLab: https://code.videolan.org/VideoLAN.org/websites/-/commit/25880bc2a73f8c2aa5421f7ba01a628259d1f11b

-- 
View it on GitLab: https://code.videolan.org/VideoLAN.org/websites/-/commit/25880bc2a73f8c2aa5421f7ba01a628259d1f11b
You're receiving this email because of your account on code.videolan.org.




More information about the www-doc mailing list