adyen-magento2 icon indicating copy to clipboard operation
adyen-magento2 copied to clipboard

[PW-1915] Debug payments in local env with proxy like ngrok to receive webhooks

Open rvitaliy opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. I'm always frustrated when i need to debug payments in local env.

Describe the solution you'd like When I execute a payment in local env i can configure a ngrok url for webhooks.

rvitaliy avatar Apr 17 '20 13:04 rvitaliy

Hello @rvitaliy,

Indeed the local processing of the notification webhooks is a situation that we'd like to address. We're considering your report in our internal issue tracker and we'll update you when progress is made.

Thanks.

acampos1916 avatar Apr 24 '20 06:04 acampos1916

Update the title with the internal ticket number

AlexandrosMor avatar Jul 29 '20 07:07 AlexandrosMor

Hi @rvitaliy,

We are currently using the following for local env webhook processing:

  1. In the Adyen customer area, set webhook notifications to use a thirdparty intermediary service, such as https://notification.ninja
  2. On this thirdparty service, forward incoming notifications to your {magento_url}
  3. Change the constant variables WEBHOOK_USERNAME & WEBHOOK_PASSWORD according to your Magento 2 configuration.
  4. Run script from terminal php -S {magento_url} webhookRelay.php using the PHP built-in server.
    const WEBHOOK_USERNAME = “WEBHOOK_USERNAME";
    const WEBHOOK_PASSWORD = "WEBHOOK_PASSWORD";
    const WEBHOOK_ENDPOINT = “{magento_url}/adyen/process/json";

    function addHeaders()
    {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Credentials: true");
        header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
        header('Access-Control-Allow-Headers: Content-Type, Accept');
    }

    function sendToMagento($notification)
    {
        $curl = curl_init(WEBHOOK_ENDPOINT);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
        curl_setopt($curl, CURLOPT_USERPWD, WEBHOOK_USERNAME . ":" . WEBHOOK_PASSWORD);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $notification);

        curl_exec($curl);
        curl_close($curl);
    }

    function run()
    {
        addHeaders();

        $notificationBody = file_get_contents('php://input');
        sendToMagento($notificationBody);

        return true;
    }

    run();

Feel free to drop any feedback related to this script.

Thanks, Jean Adyen

Morerice avatar Aug 30 '22 09:08 Morerice

Thank you for replay to this thread after 2 years, i hope that this solution can be useful for someone. Personally i changed the project and i hope never come back to Magento ecosystem 🤞

rvitaliy avatar Aug 30 '22 11:08 rvitaliy