Problem/Motivation

Several customers have reported that payment fails using Mobile Pay.

We received the following info from Paytrail's support:

The payments have returned the following error:
“status”:403,“text”:“Stamp validation failed.“},” Which means that request body's stamp has not been unique.

https://docs.paytrail.com/#/?id=payloads

stamp string x Merchant unique identifier for the order

Steps to reproduce

Unknown, since Mobile Pay is not available using test credentials.

Comments

iamfredrik created an issue. See original summary.

iamfredrik’s picture

Some additional info. The payments have been registered as paid in Paytrail's control panel despite the error. However, the orders have not been registered as completed in the Drupal Commerce shop.

tuutti’s picture

Do you have any idea what is giving that 403 error? The error message looks like something what Paytrail::onNotify() would return.

Nevermind, I didn't see your previous comment. It's definitely the Paytrail::onNotify() or Paytrail::onReturn() that fails then.

tuutti’s picture

StatusFileSize
new19.22 KB

Can you check if the failed orders have commerce_paytrail_stamp in order's data field, like:

Example query

iamfredrik’s picture

It returns this:

{s:21:"paid_event_dispatched";b:0;s:20:"terms_and_conditions";i:1;s:32:"commerce_paytrail_transaction_id";s:36:"974adf96-b5db-11ec-8f0f-03abd6bbce33";s:23:"commerce_paytrail_stamp";s:36:"d27563f8-29e4-4afd-8488-4d86c1e289c3";}

iamfredrik’s picture

More info from Paytrail support:

I double checked this with our technology and it turns out that we have tried to make a callback on the payments but the online store gives us this response: "status": 403, "text": "Stamp validation failed."}, ".

In normal cases, the payment goes through normally, but in some cases, your online store has given us the error code "status": 403, "text": "Stamp validation failed."}, ". when we have sent a callback. This then means that there is some type of error in the online store itself.

This does not explain why the payment has gone through. Why is the payment registered if stamp validation fails?

tuutti’s picture

The stamp is generated and saved to commerce order when the payment form is rendered and is then validated when user returns from the payment gateway (Paytrail::onReturn()) or when Paytrail calls the notification callback (Paytrail::onNotify()).

I'm not sure why stamp wouldn't match tho. Can you ask/check if the checkout-stamp query parameter matches with the stamp saved in commerce order?

This is where it's validated: https://git.drupalcode.org/project/commerce_paytrail/-/blob/3.x/src/Plug...

iamfredrik’s picture

Okay, so it seems the shop returns the stamp validation error after Paytrail has returned that the payment is approved.

Will see if I can find the query parameter.

iamfredrik’s picture

There are two queries for the same order and none of the checkout-stamps matches the one I posted in comment #5 for the same order.

/checkout/373/payment/return?checkout-account=977532&checkout-algorithm=sha512&checkout-amount=335&checkout-provider=mobilepay&checkout-reference=373&checkout-stamp=e8f96f74-6344-4e1c-97a1-2508bf49f0e3&checkout-status=ok&checkout-transaction-id=964bc006-b5db-11ec-8f0e-0b9ffd411762&signature=7d7cb9f2c4b33cd05bef956c05a5a9e82d5495b3a520a8aa4d1b55c5223441ee53f29a37750149de72bad7bb6b41c37d97abf438f86e1c9f46890860241c5d2a

/checkout/373/payment/return?checkout-account=977532&checkout-algorithm=sha512&checkout-amount=335&checkout-provider=mobilepay&checkout-reference=373&checkout-stamp=6e591138-3f8a-4710-b308-a45238a02ec5&checkout-status=ok&checkout-transaction-id=6f70550a-b5db-11ec-bfa2-3f4d9fc7f2cc&signature=427a575574db2338702b545cd310fb98195da495269f0d15d1cf17d967c80bfd31e0024d07e156d3bbc23a7fca283c9eb83b94e819512edc603221866481d8ee

simohell’s picture

Note: Similar issue with MobilePay+Paytrail has persisted for years already on Commerce 1.x and other old Paytrail payment modules and E1 (https://www.drupal.org/project/commerce_suomenverkkomaksut) as well as recently increased number of issues with Commerce 2.x and commerce_paytrail 2.x. The consistent factor seems to be combination of MobilePay+Paytrail+any version of Drupal Commerce.

This may be specific to MobilePay who is know for issues including double charging client purchases (national level news in 2021 https://www.iltalehti.fi/kotimaa/a/fd3087c2-2cf7-482a-bc67-45652eddc715). It is not impossible that MobilePay's fix for preventing double charges is somewhat incompatible with the other APIs. The fact that we seem to be getting doulbe responses indicates in this direction.

MobilePay is a popular payment method so it might make sense for to accommodate this by additional checks on wether a payment was already accepted. This is "wrong" as it should be fixed where the issue starts but fixing it in any possible way would benefit Durpal Commerce shop owners.

simohell’s picture

#10 would apply to a case where the feedback

In normal cases, the payment goes through normally, but in some cases, your online store has given us the error code "status": 403, "text": "Stamp validation failed."}, ". when we have sent a callback. This then means that there is some type of error in the online store itself.

refers to case that some MobilePay payments are successful, if all fail then it's something different...
I'll start testing this with live credentials.

simohell’s picture

After live testing on an early stage development site (Ubuntu + Lando + Drupal 9 + Commerce 2 + Commerce Paytrail 3.0-alpha3 ) I cannot reproduce the error. The payment is recorded in Paytrail merchant's panel as to be expected and Commerce updates the order from Draft status to Completed status.

The issue might be related to payment method provider, some server side stuff, caching or some other site components or conditions but live payment by MobilePay using commerce_paytrail 3.0-alpha3 is tested working in the above setup.

iamfredrik’s picture

We're still having problems with Mobile Pay payments. The orders do not register as completed, but remain as draft although the payment is shown as completed. What could be the reason why only Mobile Pay payments have this problem?

draft
payment

  • tuutti committed ddcd1ed on 3.x
    Issue #3274707 by tuutti: Payment using Mobile Pay fails
    Issue #3314321...
tuutti’s picture

Can you test if 3.0.0-alpha4 release fixes this? I've completely refactored how the return/notify callback validation works: https://git.drupalcode.org/project/commerce_paytrail/-/commit/5e892e3327...

I think this had something to do with PaytrailOffsiteForm being refreshed/re-rendered after user was redirected to Paytrail / MobilePay app, which caused transaction ID and stamp key to be regenerated.

iamfredrik’s picture

With our limited testing, MobilePay seems to work, but we now have an other problem. When selecting shipping methods that changes the order total, we get the following error:

Paytrail\Payment\ApiException: [400] Client error: `POST https://services.paytrail.com/payments` resulted in a `400 Bad Request` response: {"status":"error","message":"Sum of purchase item amounts does not match total amount."} in Paytrail\Payment\Api\PaymentsApi->createPaymentWithHttpInfo() (line 580 of /backend/vendor/tuutti/php-paytrail-payment-api/src/Api/PaymentsApi.php).

tuutti’s picture

Did that happen with previous version?

iamfredrik’s picture

Hmmm, I'm not sure. No one has reported the error. I just discovered it myself when testing the new version. I tried downgrading to the previous version, but the error still occurs.

iamfredrik’s picture

Additionally, the following error occurs upon clicking a bank payment button after updating Commece from 2.30.0 => 2.32.0. This error applies to both current and previous version of Commerce Paytrail.

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getState() on null in Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowBase->getStepId() (line 211 of modules/contrib/commerce/modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php).

tuutti’s picture

Looks like I forgot to add shipping support. Here's a separate issues for it: #3316739: Support commerce shipping

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getState() on null in Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowBase->getStepId() (line 211 of modules/contrib/commerce/modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php).

I wasn't able to reproduce this, does this only happen with Paytrail?

tuutti’s picture

Status: Active » Fixed

I'll close this for now. Please open a new issue if that 2.32 commerce issue persists.

iamfredrik’s picture

I will have to conduct some more testing on the Commerce 2.32 issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.