Mangopay / mangopay2-php-sdk

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

Access CreatedPayIn Object #405

Closed janooosh closed 4 years ago

janooosh commented 4 years ago

Hi all,

i am trying to extract the SecureModeRedirectURL from the createdPayIn object to redirect the user to complete the 3DS challenge.

How can i access the redirect url?

Here's my code (which btw works perfectly fine for non-3DS payments, it returns the "Payment success" message):

           $test_amount = 10000;
            // create pay-in CARD DIRECT
            $payIn = new \MangoPay\PayIn();
            $payIn->CreditedWalletId = $wallet_id;
            $payIn->AuthorId = $user_id;
            $payIn->DebitedFunds = new \MangoPay\Money();
            $payIn->DebitedFunds->Amount = $test_amount;
            $payIn->DebitedFunds->Currency = $order->get_currency();
            $payIn->Fees = new \MangoPay\Money();
            $payIn->Fees->Amount = 0;
            $payIn->Fees->Currency = $order->get_currency();

            // payment type as CARD
            $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsCard();
            $payIn->PaymentDetails->CardType = $card_type;
            $payIn->PaymentDetails->CardId = $card_id;

            // execution type as DIRECT
            $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect();
            $payIn->ExecutionDetails->SecureModeReturnURL = $return_url;
            $payIn->ExecutionDetails->SecureMode = 'FORCE';
            // create Pay-In
            $createdPayIn = $api->PayIns->Create($payIn);

            // if created Pay-in object has status SUCCEEDED it's mean that all is fine
            if ($createdPayIn->Status == \MangoPay\PayInStatus::Succeeded) {
                return "Payment success";
            }
            else {
                // if created Pay-in object has status different than SUCCEEDED 
                // that occurred error and display error message
                $message = $createdPayIn->Status . ' (result code: '. $createdPayIn->ResultCode . '), SecureModeRedirectURL ist '.$createdPayIn->SecureModeRedirectURL.' und SecureMode ist '.$createdPayIn->SecureMode;
                return $message;
            }

When attempting to pay, i receive the following error message, indicating that SecureModeRedirectURL is empty: "CREATED (result code: ), SecureModeRedirectURL ist und SecureMode ist"

Thank you! Kind regards Jan

mangomaxoasis commented 4 years ago

Hi @janooosh I'm looking into it, I'll keep you updated Max

janooosh commented 4 years ago

Hi Max, thanks for your response! It was a quick fix, i was able to find it out myself. It's located in $createdPayIn->ExecutionDetails->SecureModeRedirectURL.

Overall the sdk is a great help, thank you so much for it!! As a minor suggestion, it would however be great to get an overview of all objects and their return values.

Cheers Jan

mangomaxoasis commented 4 years ago

Thanks @janooosh ! Feel free to contact us if you have any other questions Max