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.