Mangopay / mangopay2-php-sdk

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

Help with recurring payments setting #534

Closed alfredobp closed 2 years ago

alfredobp commented 2 years ago

Hello, I need help with the integration. I have to implement a recurring payment, so I register the user's card, make the first payment and manage the first payment. However I get this error:

MangoPay\Libraries\ResponseException Bad request. Requires an active 3DSV2 configuration

My code integration is:

  try {
    $CardRegistration = new \MangoPay\CardRegistration();

    $CardRegistration->Id = session('Id');

    $CardRegistration->RegistrationData = 'data=' . $_GET['data'];

    $updatedCardRegister2 = $this->mangopay->CardRegistrations->Update($CardRegistration);

    $CardRegistrationId = session('Id');
    $CardRegistration =  $this->mangopay->CardRegistrations->Get($CardRegistrationId);
    $PayIn = new \MangoPay\PayIn();
    $PayIn->CreditedWalletId = '117549975';
    $PayIn->AuthorId = Auth::User()->mangopay_id;
    $PayIn->PaymentType = \MangoPay\PayInPaymentType::Card;
    $PayIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsCard();
    $PayIn->DebitedFunds = new \MangoPay\Money();
    $PayIn->DebitedFunds->Currency = "EUR";
    $PayIn->DebitedFunds->Amount =  session('amount') * 100;
    $PayIn->Fees = new \MangoPay\Money();
    $PayIn->Fees->Currency = "EUR";

    $PayIn->Fees->Amount = 0;
    $PayIn->ExecutionType = \MangoPay\PayInExecutionType::Direct;
    $PayIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsWeb();
    $PayIn->ExecutionDetails->SecureMode="FORCE";
    $PayIn->ExecutionDetails->SecureModeReturnURL = "http" . (isset($_SERVER['HTTPS']) ? "s" : null) . "://" . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?stepId=" . (1);
    $PayIn->ExecutionDetails->CardType="CB_VISA_MASTERCARD";
    $PayIn->ExecutionDetails->CardId =   $CardRegistration->CardId;
    $PayIn->ExecutionDetails->Culture =  "ES";
    $result = $this->mangopay->PayIns->Create($PayIn);

    $PayRecurrent = new \MangoPay\PayInRecurringRegistration();
    $PayRecurrent->AuthorId = Auth::user()->mangopay_id;
    $PayRecurrent->CardId = $CardRegistration->CardId;
    $PayRecurrent->CreditedWalletId = '117049975';
    $PayRecurrent->FirstTransactionDebitedFunds = new \MangoPay\Money();
    $PayRecurrent->FirstTransactionDebitedFunds->Amount = session('amount') * 100;
    $PayRecurrent->FirstTransactionDebitedFunds->Currency = 'EUR';
    $PayRecurrent->FirstTransactionFees = new \MangoPay\Money();

    $PayRecurrent->FirstTransactionFees->Amount = 0;
    $PayRecurrent->FirstTransactionFees->Currency = 'EUR';
    $PayRecurrent->secureMode = ' DEFAULT';
    $billing = new \MangoPay\Billing();
    $billing->FirstName = 'John';
    $billing->LastName = 'Doe';
    $billing->Address = new \MangoPay\Address;
    $billing->Address->AddressLine1 = 'Doe';
    $billing->Address->Country = 'ES';
    $billing->Address->City = 'Doe';
    $billing->Address->PostalCode = '1111';
    $shipping = new \MangoPay\Shipping();
    $shipping->FirstName = 'John';
    $shipping->LastName = 'Doe';
    $shipping->Address = new \MangoPay\Address;
    $shipping->Address->AddressLine1 = 'Doe';
    $shipping->Address->City = 'Doe';
    $shipping->Address->Country = 'ES';
    $shipping->Address->PostalCode = '1111';

    $PayRecurrent->Shipping = $shipping;
    $PayRecurrent->Billing = $billing;
        $result = $this->mangopay->PayIns->CreateRecurringRegistration($PayRecurrent);
  }
Previously I have the user fill in their card details using a form whit this data in the view:

$CardRegistration = new \MangoPay\CardRegistration(); $CardRegistration->UserId = auth()->user()->mangopay_id; // card registrarion $CardRegistration->Currency = "EUR"; // $CardRegistration->Securre // $CardRegistration->CardType = "CB_VISA_MASTERCARD"; $Result = $this->mangopay->CardRegistrations->Create($CardRegistration); session(['Id' => $Result->Id]); $returnUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST']; $returnUrl .= substr($_SERVER['REQUEST_URI'], 0, strripos($_SERVER['REQUESTURI'], '/') + 1); $returnUrl .= 'resultCard'; $cardRegistrationUrl = $Result->CardRegistrationURL; $preregistrationData = $Result->PreregistrationData; $accessKey = $Result->AccessKey;

I think that the problem is in Secure Mode, but I need a example of this showcase.

Thanks.
SoloJr commented 2 years ago

hi @alfredobp

Please follow all the test examples from here and here. This can also help.

They should help. You will see how we test RecurringPayments :)

fredericdelordm commented 2 years ago

Hello @alfredobp, please contact the mangopay support team. They will activate the feature for you.