mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
550 stars 189 forks source link

Issue with missing payment ID #740

Closed 3stragon closed 3 weeks ago

3stragon commented 3 weeks ago

Specifications

Describe the issue

My log indicates that when return.php is executed, the QUERY_STRING is empty, and there are no GET parameters being passed. This means that Mollie is redirecting to my return.php without appending the payment ID (id) to the URL. It looks like Mollie might not be properly configured to append the id parameter to the redirectUrl??

This is my base:

$payment = $mollie->payments->create([
    "amount" => [
        "currency" => "EUR",
        "value" => "10.00"
    ],
    "description" => "Test Payment",
    "redirectUrl" => "https://xx.com/testmollie/return.php", // No 'id' parameter here
    "webhookUrl"  => "https://xx.com/testmollie/webhook.php", // Optional
]);

return.php

<?php
echo "return.php is being executed";

$logFile = '/xxx/return_log.txt';

file_put_contents($logFile, "Server Variables:\n" . print_r($_SERVER, true), FILE_APPEND);

file_put_contents($logFile, "GET Parameters:\n" . print_r($_GET, true), FILE_APPEND);

if (isset($_GET['id']) && !empty($_GET['id'])) {
    $paymentId = $_GET['id'];
    echo "Payment ID: " . $paymentId;
} else {
    echo "Invalid or missing payment ID.";
}
?>

Error is always: Invalid or missing payment ID Whatever i do. What do i miss?

sandervanhooft commented 3 weeks ago

Mollie will call your webhook url with the payment id. The payment id will not be included in the redirectUrl.

However...

If you do the following you are able to add the payment id to the redirectUrl yourself:

  1. Create the Mollie Payment
  2. Update the payment redirectUrl to include the payment id
  3. Redirect the customer to the payment's checkout url
  4. After completing the checkout the customer will be redirected to your provided redirectUrl including the payment id.
$payment = $mollie->payments->create(...);
$payment->redirectUrl = $newUrl;
// now redirect the customer
sandervanhooft commented 3 weeks ago

Small mistake

$payment = $mollie->payments->create(...);
$payment->redirectUrl = $newUrl;
$payment->update();
// now redirect the customer
3stragon commented 3 weeks ago

return.php is being executedPayment ID: tr_KT......

Thank you ;)