Mangopay / mangopay2-php-sdk

PHP SDK for MANGOPAY
https://packagist.org/packages/mangopay/php-sdk-v2
MIT License
123 stars 134 forks source link

Can't get an Id when try to make a new PayIn method. #574

Closed M-Adrien74 closed 2 years ago

M-Adrien74 commented 2 years ago

Hi there , it's me again!

I face a problem when i try to make a new PayIn. (I'm on Symfony 5 and I pass through a service) I'm not able to receive an Id. I've tried to dump line by line. I gave to the method an userId, walletId and a cardId fresh registred. But in my dump I don't receive the id for the payIn.

 public function createPayin(User $user, $cardId)
    {
$ip = ".......a right Ip";
        $idMangoPayUser = $user->getIdMangopay();
        $idWalletUser = $user->getidWallet();

        $payIn = new PayIn();
        $payIn->AuthorId = $idMangoPayUser;
        $payIn->CreditedWalletId = $idWalletUser;
        $payIn->DebitedFunds = new Money();
        $payIn->DebitedFunds->Currency = 'EUR';
        $payIn->DebitedFunds->Amount = 1500;
        $payIn->Fees = new Money();
        $payIn->Fees->Amount = 0;
        $payIn->Fees->Currency = 'EUR';
        $payIn->ExecutionDetails = new PayInExecutionDetailsDirect();
        $payIn->ExecutionDetails->SecureModeReturnURL = "http://www.my-site.com/returnURL";
        $payIn->ExecutionDetails->SecureMode = "DEFAULT";
        $payIn->PaymentDetails = new PayInPaymentDetailsCard();
        $payIn->PaymentDetails->CardId = $cardId;
        $payIn->PaymentDetails->IpAddress = $ip;
        $payIn->PaymentDetails->CardType = 'CB_VISA_MASTERCARD';
        $payIn->PaymentDetails->BrowserInfo = new BrowserInfo();
        $payIn->PaymentDetails->BrowserInfo->AcceptHeader = $_SERVER['HTTP_ACCEPT'];
        $payIn->PaymentDetails->BrowserInfo->Language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
        $payIn->PaymentDetails->BrowserInfo->JavascriptEnabled = true;
        $payIn->PaymentDetails->BrowserInfo->TimeZoneOffset = 60;
        $payIn->PaymentDetails->BrowserInfo->ScreenWidth = 400;
        $payIn->PaymentDetails->BrowserInfo->ScreenHeight = 1800;
        $payIn->PaymentDetails->BrowserInfo->ColorDepth = 4;
        $payIn->PaymentDetails->BrowserInfo->UserAgent = $_SERVER['HTTP_USER_AGENT'];
        $payIn->PaymentDetails->BrowserInfo->JavaEnabled = true;

        dump($payIn);
        $result = $this->mangoPayApi->PayIns->Create($payIn);
        dump($result);
        return $result;

This one return me a bad request because the Id is missing.

MangoPay\PayIn {#134 ▼
  +Id: null
  +Tag: null
  +CreationDate: null
  +AuthorId: "153954101"
  +CreditedUserId: "153954101"
  +DebitedFunds: MangoPay\Money {#445 ▼
    +Currency: "EUR"
    +Amount: 1500
  }
  +CreditedFunds: null
  +Fees: MangoPay\Money {#507 ▼
    +Currency: "EUR"
    +Amount: 0
  }
  +Status: null
  +ResultCode: null
  +ResultMessage: null
  +ExecutionDate: null
  +Type: null
  +Nature: null
  +DebitedWalletId: null
  +CreditedWalletId: "153954102"
  +PaymentType: null
  +PaymentDetails: MangoPay\PayInPaymentDetailsCard {#503 ▼
    +CardType: "CB_VISA_MASTERCARD"
    +CardId: "154103376"
    +StatementDescriptor: null
    +IpAddress: "........a right IP"
    +BrowserInfo: MangoPay\BrowserInfo {#547 ▼
      +AcceptHeader: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
      +JavaEnabled: true
      +Language: "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"
      +ColorDepth: 4
      +ScreenHeight: 1800
      +ScreenWidth: 400
      +TimeZoneOffset: 60
      +UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 OPR/91.0.4516.72"
      +JavascriptEnabled: true
    }
    +Shipping: null
  }
  +ExecutionType: null
  +ExecutionDetails: MangoPay\PayInExecutionDetailsDirect {#515 ▼
    +SecureMode: "DEFAULT"
    +SecureModeReturnURL: "http://www.my-site.com/returnURL"
    +SecureModeRedirectURL: null
    +SecureModeNeeded: null
    +Billing: null
    +SecurityInfo: null
    +Culture: null
    +Requested3DSVersion: null
    +Applied3DSVersion: null
  }
  +RecurringPayinRegistrationId: null
}

I don't really know where I'm going wrong because I do the same thing like the payment.php but on Symfony and controller/service. And finally in my controller i'm just doing

$service->createPayin($user , $cardId);

Can someone help us ?