Magento2: magento from 2.0.4 to 2.0.7 custom payment error with valid input data "message":"Please enter a valid credit card expiration date."

Created on 27 May 2016  Â·  18Comments  Â·  Source: magento/magento2

I made custom payment similar to this https://github.com/Inchoo/magento2-Inchoo_Stripe (but not Stripe - Onpex payment, if it is important)
After "composer update" my core changes from 2.0.4 to 2.0.7.
Testing payment at newer version showed me error. I entered test credit card, valid expiration date and cvv and got payment error "Please enter a valid credit card expiration date."
REST query sended to http://XXX.XXX.XXX.XXX/rest/default/V1/guest-carts/54fce3777572e7f79df94bb4a25da69f/payment-information gave response with that message and stack trace.

{"message":"Please enter a valid credit card expiration date.",
"trace":"#0 \/srv\/xxx\/web\/vendor\/magento\/module-quote\/Model\/Quote\/Payment.php(176): Magento\Payment\Model\Method\Cc->validate()\n#1 \/srv\/xxx\/web\/vendor\/magento\/module-quote\/Model\/PaymentMethodManagement.php(64): Magento\Quote\Model\Quote\Payment->importData(Object(Magento\Framework\DataObject))\n#2 \/srv\/xxx\/web\/vendor\/magento\/module-quote\/Model\/GuestCart\/GuestPaymentMethodManagement.php(49): Magento\Quote\Model\PaymentMethodManagement->set('3', Object(Magento\Quote\Model\Quote\Payment))\n#3 \/srv\/xxx\/web\/vendor\/magento\/module-checkout\/Model\/GuestPaymentInformationManagement.php(99): Magento\Quote\Model\GuestCart\GuestPaymentMethodManagement->set('54fce3777572e7f...', Object(Magento\Quote\Model\Quote\Payment))\n#4 \/srv\/xxx\/web\/vendor\/magento\/module-checkout\/Model\/GuestPaymentInformationManagement.php(78): Magento\Checkout\Model\GuestPaymentInformationManagement->savePaymentInformation('54fce3777572e7f...', '[email protected]...', Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))\n#5 [internal function]: Magento\Checkout\Model\GuestPaymentInformationManagement->savePaymentInformationAndPlaceOrder('54fce3777572e7f...', '[email protected]...', Object(Magento\Quote\Model\Quote\Payment), Object(Magento\Quote\Model\Quote\Address))\n#6 \/srv\/xxx\/web\/vendor\/magento\/module-webapi\/Controller\/Rest.php(265): call_user_func_array(Array, Array)\n#7 \/srv\/xxx\/web\/vendor\/magento\/module-webapi\/Controller\/Rest.php(160): Magento\Webapi\Controller\Rest->processApiRequest()\n#8 \/srv\/xxx\/web\/var\/generation\/Magento\/Webapi\/Controller\/Rest\/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))\n#9 \/srv\/xxx\/web\/vendor\/magento\/framework\/App\/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))\n#10 \/srv\/xxx\/web\/vendor\/magento\/framework\/App\/Bootstrap.php(258): Magento\Framework\App\Http->launch()\n#11 \/srv\/xxx\/web\/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))\n#12 {main}"}

I checked this twice and twice (one time windows, second time linux) updates made from 2.0.4 to 2.0.7

Magento\Payment\Model\Method\Cc.php has method validate() containiing following code
if ($ccType != 'SS' && !$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth()))
where $info->getCcExpYear() and $info->getCcExpMonth() == NULL.

How is that possible?
What changes should I do to fix that and pass my payment method?

UPD: site is on http

Payment bug report

All 18 comments

@schogini, I tried to change code according to your commit and now I get new error from rest http://XXX.XXX.XXX.XXX/rest/default/V1/guest-carts/54fce3777572e7f79df94bb4a25da69f/payment-information
{"message":"The payment method you requested is not available."}
Don't know if you already finished, but check it, please.
Magento\Payment\Model\Info.php line 102 gives this error.

@schogini, @alena-marchenko have a look:
Magento\Quote\Model\Quote\Payment.php
inside method convertPaymentData code should be following:

    foreach (array_keys($rawData) as $requestKey) {
        if (!array_key_exists($requestKey, $paymentData)) {
            $paymentData[PaymentInterface::KEY_ADDITIONAL_DATA][$requestKey] = $rawData[$requestKey];
        } elseif ($requestKey === PaymentInterface::KEY_ADDITIONAL_DATA) {
            $paymentData = array_merge($paymentData, (array) $rawData[$requestKey]);
        } else {
             $paymentData[$requestKey] = $rawData[$requestKey];
        }
    }

And in that way everything works fine.
So this commit is unneeded https://github.com/schogini/magento2-1/commit/1cd6b28c53730012ea1dba621af047ad7d8668e3

That was a mistake in our local repo. This code has been corrected. Thanks!
The correct code was pushed to another branch in our repo (branch2.0.7) We have corrected the develop branch too now.

Can confirm this also effects 2.0.6. The fix @antonlazarchenko posted works.

Hello , I had the same issue , I've corrected my Payment.php page as you said , and now I'm getting payment capturing error

@antonlazarchenko, @schogini
This is a bug in general CC model (created internal ticket to fix in next patch), as it depends on wrong DataObject structure (raw request, security vulnerable), instead of \Magento\Quote\Api\Data\PaymentInterface which gets passed to Checkout service.

All Payment Integrations which have own payload on checkout, should pass it in additional_data field and read this data from additional_data field of DataObject.

The internal ticket number is MAGETWO-53865. We will try to slot it into one of the upcoming patch releases.

Hi @elenleonova ,
We are in a trouble that the Usaepay payment method is not working, when we upgraded the website to Magento 2.0.7 version. We need to make the website live as early as possible.
Could you please confirm the date of the patch release which solves this bug.

Hi,

Please let us know this issue fixed on any other branches in your
development repo. so that we can catch the fix before your patch release.

https://www.magentocommerce.com/certification/directory/dev/1865255/

SHINE , Software Developer
shine.[email protected]

M: +91 9447117468

On Fri, Jun 17, 2016 at 11:21 AM, vipin-eglobeits [email protected]
wrote:

Hi @elenleonova https://github.com/elenleonova ,
We are in a trouble that the Usaepay payment method is not working, when
we upgraded the website to Magento 2.0.7 version. We need to make the
website live as early as possible.
Could you please confirm the date of the patch release which solves this
bug.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/4741#issuecomment-226686157,
or mute the thread
https://github.com/notifications/unsubscribe/AGgpM7C3vUIG-UHnqABCrGOfIe3aGLbHks5qMjX5gaJpZM4IoaW9
.

Hello @antonlazarchenko, this issue has been fixed in the 2.1.0 Release, that's why I'm closing it. If you any questions or additional information regarding the issue feel free to reopen it or create a new one.

Hello, @KrystynaKabannyk! Good news. Thanx)

@dkvashninbay, I've updated to 2.1.0.
Now I got error "Unable to place order. Please try again later." but payment system says that transaction passed successfully.
So I assume that something in my code is wrong and I need to pass credit card data correct to complete payment inside magento.
Would you look at this module https://github.com/Inchoo/magento2-Inchoo_Stripe (I made my module similar to this) and tell me how to pass and read data through additional_data right, please?

Hi, @antonlazarchenko I am getting the same error after updated to magento 2.1.0. I made my module based on the same example from Inchoo.

If you found the solution, please reply here :+1:

@antonlazarchenko Finally, after a lot of debugging and comparing magento versions, I found the error.

Look at https://github.com/magento/magento2/issues/5324

Hi, @mauromm ! Thanx!

HI @mauromm,

Thanks! Your code work. Save me a lot of times.
I'm made my module base on the same example from Inchoo.

It seem we need to decrypt config data like api key and api password/secret in 2.1.0
https://github.com/magento/magento2/issues/2984

hi @antonlazarchenko @mauromm
Is this issue happen with you?

Hi, @hungpvdev . Yes, but didn't fix this yet.

Was this page helpful?
0 / 5 - 0 ratings