Mangopay / mangopay2-php-sdk

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

Recurring Payment with saved 3D card #367

Closed Azim-pix closed 4 years ago

Azim-pix commented 4 years ago

Hi mick

We are currently using your service in order to get the payments from our client. We have succeeded in getting the payment from the client successfully.

Currently, we are trying to develop a system where the money is deducted from the client's 3D secured card. We don't have any issue with the 1st cycle of the payment.

For the subsequent cycles, we have the issue recurring payment with 3D payment card,the payment status in MANGOPAY is pending.

here is my code

public function setCardRegistration($naturalUserId){

    $cardRegister = new MangoPay\CardRegistration();
    $cardRegister->UserId = $naturalUserId;
    $cardRegister->Currency = 'EUR';
    $cardRegister->CardType = 'CB_VISA_MASTERCARD';
    $createdCardRegister = $this->mangoPayApi->CardRegistrations->Create($cardRegister);

    return $createdCardRegister;
}

public function finishCardRegistration($card_id,$data){

    try{

        $cardRegisterPut = $this->mangoPayApi->CardRegistrations->Get($card_id);
        $cardRegisterPut->RegistrationData = 'data='.$data;
        $updatedCardRegister = $this->mangoPayApi->CardRegistrations->Update($cardRegisterPut);

        if($updatedCardRegister->Status != MangoPay\CardRegistrationStatus::Validated || !isset($updatedCardRegister->CardId)){
            return false;
        }

        $card = $this->mangoPayApi->Cards->Get($updatedCardRegister->CardId);

        return $card;

    }catch (MangoPay\Libraries\ResponseException $e){

        return false;

    }

}

$payIn = new MangoPay\PayIn(); $payIn->CreditedWalletId = $wallet->Id; $payIn->AuthorId = $mangoUser->Id; $payIn->Tag = $tag; $payIn->DebitedFunds = new MangoPay\Money(); $payIn->DebitedFunds->Amount = $amount; $payIn->DebitedFunds->Currency = 'EUR'; $payIn->Fees = new MangoPay\Money(); $payIn->Fees->Amount = $fee; $payIn->Fees->Currency = 'EUR';

    // payment type as CARD

    $payIn->PaymentDetails = new MangoPay\PayInPaymentDetailsCard();
    $payIn->PaymentDetails->CardType = $card_array['card_type'];
    $payIn->PaymentDetails->CardId = $card_array['card_id'];

    // execution type as DIRECT
    $payIn->ExecutionDetails = new MangoPay\PayInExecutionDetailsDirect();
    if($cycle == 1)
    {
        $payIn->ExecutionDetails->SecureModeNeeded = "FORCE";
    }else{
        $payIn->ExecutionDetails->SecureModeNeeded = "DEFAULT";
    }

    $payIn->ExecutionDetails->SecureModeReturnURL = "http".(isset($_SERVER['HTTPS']) ? "s" : null)."://".$_SERVER["HTTP_HOST"]."/client/mission/mission-accept-process/".$transaction;

    // create Pay-In
    $createdPayIn = $this->mangoPayApi->PayIns->Create($payIn);
mickaelpois commented 4 years ago

@Azim-pix