7
7
8
8
use Magento \Framework \DataObject ;
9
9
use Magento \Framework \Exception \LocalizedException ;
10
+ use Magento \Payment \Helper \Formatter ;
10
11
use Magento \Payment \Model \InfoInterface ;
11
12
use Magento \Payment \Model \Method \ConfigInterface ;
12
13
use Magento \Payment \Model \Method \ConfigInterfaceFactory ;
27
28
*/
28
29
class Payflowpro extends \Magento \Payment \Model \Method \Cc implements GatewayInterface
29
30
{
31
+ use Formatter;
32
+
30
33
/**
31
34
* Transaction action codes
32
35
*/
@@ -83,8 +86,6 @@ class Payflowpro extends \Magento\Payment\Model\Method\Cc implements GatewayInte
83
86
84
87
const PNREF = 'pnref ' ;
85
88
86
- /**#@-*/
87
-
88
89
/**#@-*/
89
90
protected $ _responseParamsMappings = [
90
91
'firstname ' => 'billtofirstname ' ,
@@ -391,14 +392,14 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
391
392
* Get capture amount
392
393
*
393
394
* @param float $amount
394
- * @return float
395
+ * @return float|int
395
396
*/
396
397
protected function _getCaptureAmount ($ amount )
397
398
{
398
399
$ infoInstance = $ this ->getInfoInstance ();
399
- $ amountToPay = round ( $ amount, 2 ) ;
400
- $ authorizedAmount = round ( $ infoInstance ->getAmountAuthorized (), 2 );
401
- return $ amountToPay != $ authorizedAmount ? $ amountToPay : 0 ;
400
+ $ amountToPay = $ amount ;
401
+ $ authorizedAmount = $ infoInstance ->getAmountAuthorized ();
402
+ return abs ( $ amountToPay - $ authorizedAmount) < 0.00001 ? 0 : $ amountToPay ;
402
403
}
403
404
404
405
/**
@@ -414,7 +415,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
414
415
{
415
416
if ($ payment ->getAdditionalInformation (self ::PNREF )) {
416
417
$ request = $ this ->buildBasicRequest ();
417
- $ request ->setAmt (round ($ amount, 2 ));
418
+ $ request ->setAmt ($ this -> formatPrice ($ amount ));
418
419
$ request ->setTrxtype (self ::TRXTYPE_SALE );
419
420
$ request ->setOrigid ($ payment ->getAdditionalInformation (self ::PNREF ));
420
421
$ payment ->unsAdditionalInformation (self ::PNREF );
@@ -423,7 +424,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
423
424
$ request ->setOrigid ($ payment ->getParentTransactionId ());
424
425
$ captureAmount = $ this ->_getCaptureAmount ($ amount );
425
426
if ($ captureAmount ) {
426
- $ request ->setAmt ($ captureAmount );
427
+ $ request ->setAmt ($ this -> formatPrice ( $ captureAmount) );
427
428
}
428
429
$ trxType = $ this ->getInfoInstance ()->hasAmountPaid () ? self ::TRXTYPE_SALE : self ::TRXTYPE_DELAYED_CAPTURE ;
429
430
$ request ->setTrxtype ($ trxType );
@@ -511,7 +512,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
511
512
$ request = $ this ->buildBasicRequest ();
512
513
$ request ->setTrxtype (self ::TRXTYPE_CREDIT );
513
514
$ request ->setOrigid ($ payment ->getParentTransactionId ());
514
- $ request ->setAmt (round ($ amount, 2 ));
515
+ $ request ->setAmt ($ this -> formatPrice ($ amount ));
515
516
$ response = $ this ->postRequest ($ request , $ this ->getConfig ());
516
517
$ this ->processErrors ($ response );
517
518
@@ -606,7 +607,7 @@ public function postRequest(DataObject $request, ConfigInterface $config)
606
607
protected function _buildPlaceRequest (DataObject $ payment , $ amount )
607
608
{
608
609
$ request = $ this ->buildBasicRequest ();
609
- $ request ->setAmt (round ($ amount, 2 ));
610
+ $ request ->setAmt ($ this -> formatPrice ($ amount ));
610
611
$ request ->setAcct ($ payment ->getCcNumber ());
611
612
$ request ->setExpdate (sprintf ('%02d ' , $ payment ->getCcExpMonth ()) . substr ($ payment ->getCcExpYear (), -2 , 2 ));
612
613
$ request ->setCvv2 ($ payment ->getCcCid ());
0 commit comments