'Symfony 5 - Mangopay post card info's request take too much time

I have a problem with a POST to add the informations of a credit card. I'm using MangoPay's API to implement the payment method.

I've installed mangopay/php-sdk-v2 et http-client pour gérer les API.

To add a credit card, I have to create a token.
The resulted token is an object with these keys:

{
    "Id": "136943412",
    "Tag": null,
    "CreationDate": 1649425095,
    "UserId": "135643537",
    "AccessKey": "1X0m87dmM2LiwFgxPLBJ",
    "PreregistrationData": "Qi7oou23Q8d9B3xUpjdMucwiSczJqPyOPNZWThaZUKnrBt3dR9IXdzkIKyiibnTP2ddFLVXdicolcUIkv_kKEA",
    "RegistrationData": null,
    "CardId": null,
    "CardType": "CB_VISA_MASTERCARD",
    "CardRegistrationURL": "https://homologation-webpayment.payline.com/webpayment/getToken",
    "ResultCode": null,
    "ResultMessage": null,
    "Currency": "EUR",
    "Status": "CREATED"
}

After that, I have to do a POST with the URL give by the CardRegistrationURL. Its body will have five keys to enter: data (its value => PreregistrationData), accessKeyRef, cardNumber, cardExpirationDate and cardCvx.

// ApiUser.php

    public function Registration($id, $form)
    {
      $CardRegistration = new \MangoPay\CardRegistration();
      $CardRegistration->UserId = $id;
      $CardRegistration->Currency = "EUR";
      $CardRegistration->CardType = "CB_VISA_MASTERCARD";
      $Result = $this->mangoPayApi->CardRegistrations->Create($CardRegistration);
      $this->registration = $Result;

      $respose = $this->client->request(
        'POST',
        $Result->CardRegistrationURL,
        [
          'headers' => [
            'Content-Type' => [
              'application/x-www-form-urlencoded',
              'application/json',
            ],
            'Connection' => 'keep-alive'
          ],
          'json' => [
            'data' => $Result->PreregistrationData,
            'accessKeyRef' => $Result->AccessKey,
            'cardNumber' => $form['cardnumber']->getData(),
            'cardExpirationDate ' => $form['cardexpdate']->getData(),
            'cardCvx' => $form['cardcvx']->getData(),
          ]
        ]
      );

      return [
        $response,
        $Result
      ];
    }

If it worked, I should have as a result a string that start by data=.

But an error occurs: All query attempts failed for homologation-webpayment.payline.com: No response for 'homologation-webpayment.payline.com' (A) from any nameserver within 3000 ms after 2 attempts, tried udp://192.168.1.254:53, udp://192.168.1.254:53, No response for 'homologation-webpayment.payline.com' (AAAA) from any nameserver within 3000 ms after 2 attempts, tried udp://192.168.1.254:53, udp://192.168.1.254:53



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source