Magento 2.1.9 PayFlow pro - Transaction Declined issues
-
07-01-2021 - |
Question
I configured PayFlow Pro on Magento 2.1.9 and I tried Test mode which seems to work fine, however when switching to Live mode, I'm getting the following Result from the debug log.
'RESULT' => '12',
'RESPMSG' => 'Declined',
'HOSTCODE' => '58', (or) '57'
I've gone through with the following link from PayPal to go through with the issue but I feel everything fine (IDK if I need to check with Card Issuer (I also tried using Different Cards))
UPDATED:
This issue is only related to Australian based PayFlow Pro setup. which uses the processor PayPal Australia in your Payflow account.
Cause:
- Payment Processor: PayPal Australia didn't accept $0 Authorization which is sent by Magento 2 as default.
How to Resolve This?
I have answered it. please review and put your comment if you have a better idea
La solution
Override the Model Magento\Paypal\Model\Payflow\Service\Request\SecureToken
from PayPal using di.xml
as below in your custom module (Hope you know to do that).
Create: Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Paypal\Model\Payflow\Service\Request\SecureToken" type="Vendor\Module\Model\Rewrite\Payflow\Service\Request\SecureToken" />
</config>
Now create a Model Rewrite for SecureToken,
Create: Vendor\Module\Model\Rewrite\Payflow\Service\Request\SecureToken
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\Module\Model\Rewrite\Payflow\Service\Request;
use Magento\Framework\Math\Random;
use Magento\Framework\DataObject;
use Magento\Framework\UrlInterface;
use Magento\Paypal\Model\Payflow\Transparent;
use Magento\Paypal\Model\Payflowpro;
use Magento\Quote\Model\Quote;
/**
* Class SecureToken
*/
class SecureToken extends \Magento\Paypal\Model\Payflow\Service\Request\SecureToken
{
/**
* @var UrlInterface
*/
private $url;
/**
* @var Random
*/
private $mathRandom;
/**
* @var Transparent
*/
private $transparent;
/**
* @param UrlInterface $url
* @param Random $mathRandom
* @param Transparent $transparent
*/
public function __construct(
UrlInterface $url,
Random $mathRandom,
Transparent $transparent
) {
$this->url = $url;
$this->mathRandom = $mathRandom;
$this->transparent = $transparent;
}
/**
* Get the Secure Token from Paypal for TR
*
* @param Quote $quote
*
* @return DataObject
* @throws \Exception
*/
public function requestToken(Quote $quote)
{
$request = $this->transparent->buildBasicRequest();
$request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
$request->setVerbosity('HIGH');
$request->setAmt(1); // Set authorization amount as 1 by default its 0
$request->setCurrency($quote->getBaseCurrencyCode());
$request->setCreatesecuretoken('Y');
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
$request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
$request->setCancelurl($this->url->getUrl('paypal/transparent/cancel'));
$request->setDisablereceipt('TRUE');
$request->setSilenttran('TRUE');
$this->transparent->fillCustomerContacts($quote, $request);
$result = $this->transparent->postRequest($request, $this->transparent->getConfig());
return $result;
}
}
Changes Made in the above file is $request->setAmt(0);
to $request->setAmt(1);
.
This resolved the transaction declined issue from the PayPal Australia Processor.