@@ -386,8 +386,8 @@ protected function assignDataCommon(array $data)
386
386
if (isset ($ data ['additional_data ' ]['customer_gender ' ])) {
387
387
$ this ->getInfoInstance ()->setAdditionalInformation ('customer_gender ' , $ additionalData ['customer_gender ' ]);
388
388
}
389
-
390
- if (isset ($ data ['additional_data ' ]['termsCondition ' ])) {
389
+
390
+ if (isset ($ data ['additional_data ' ]['termsCondition ' ])) {
391
391
$ this ->getInfoInstance ()->setAdditionalInformation ('termsCondition ' , $ additionalData ['termsCondition ' ]);
392
392
$ this ->getInfoInstance ()->setAdditionalInformation ('customer_billingName ' , $ additionalData ['customer_billingName ' ]);
393
393
$ this ->getInfoInstance ()->setAdditionalInformation ('customer_identificationNumber ' , $ additionalData ['customer_identificationNumber ' ]);
@@ -715,7 +715,7 @@ public function order(InfoInterface $payment, $amount)
715
715
if (!(isset ($ response ->RequiredAction ->Type ) && $ response ->RequiredAction ->Type === 'Redirect ' )) {
716
716
$ this ->setPaymentInTransit ($ payment , false );
717
717
}
718
-
718
+
719
719
$ order = $ payment ->getOrder ();
720
720
$ this ->helper ->setRestoreQuoteLastOrder ($ order ->getId ());
721
721
@@ -789,6 +789,10 @@ protected function getFailureMessage($response)
789
789
$ responseCode = $ transactionResponse ->Status ->Code ->Code ;
790
790
$ billingCountry = $ this ->payment ->getOrder ()->getBillingAddress ()->getCountryId ();
791
791
792
+ if ($ responseCode == 491 ) {
793
+ return $ this ->getFirstError ($ transactionResponse );
794
+ }
795
+
792
796
$ method = null ;
793
797
if ($ this ->payment ->getMethodInstance () && !empty ($ this ->payment ->getMethodInstance ()->buckarooPaymentMethodCode )) {
794
798
$ method = $ this ->payment ->getMethodInstance ()->buckarooPaymentMethodCode ;
@@ -818,6 +822,34 @@ protected function getFailureMessage($response)
818
822
return $ message ;
819
823
}
820
824
825
+ /**
826
+ * @param $transactionResponse
827
+ * @param $errorType
828
+ * @return bool
829
+ */
830
+ public function hasError ($ transactionResponse , $ errorType ): bool
831
+ {
832
+ return !empty ($ transactionResponse ->RequestErrors ) && !empty ($ transactionResponse ->RequestErrors ->$ errorType );
833
+ }
834
+
835
+ /**
836
+ * @param $transactionResponse
837
+ * @return string
838
+ */
839
+ public function getFirstError ($ transactionResponse ): string
840
+ {
841
+ $ errorTypes = ['ChannelError ' , 'ServiceError ' , 'ActionError ' , 'ParameterError ' , 'CustomParameterError ' ];
842
+
843
+ foreach ($ errorTypes as $ errorType ) {
844
+ if ($ this ->hasError ($ transactionResponse , $ errorType )) {
845
+ return $ transactionResponse ->RequestErrors ->$ errorType ->_ ;
846
+
847
+ }
848
+ }
849
+
850
+ return '' ;
851
+ }
852
+
821
853
public function getFailureMessageOnFraud ($ transactionResponse )
822
854
{
823
855
if (
@@ -904,7 +936,7 @@ public function authorize(InfoInterface $payment, $amount)
904
936
if (!(isset ($ response ->RequiredAction ->Type ) && $ response ->RequiredAction ->Type === 'Redirect ' )) {
905
937
$ this ->setPaymentInTransit ($ payment , false );
906
938
}
907
-
939
+
908
940
$ order = $ payment ->getOrder ();
909
941
$ this ->helper ->setRestoreQuoteLastOrder ($ order ->getId ());
910
942
@@ -1167,7 +1199,7 @@ public function refundTransaction(\Buckaroo\Magento2\Gateway\Http\Transaction $t
1167
1199
$ payment ->getOrder ()->addStatusHistoryComment (
1168
1200
__ ("The refund has been initiated but it is waiting for a approval. Login to the Buckaroo Plaza to finalize the refund by approving it. " )
1169
1201
)->setIsCustomerNotified (false )->save ();
1170
-
1202
+
1171
1203
$ messageManager = $ this ->objectManager ->get ('Magento\Framework\Message\ManagerInterface ' );
1172
1204
$ messageManager ->addError (
1173
1205
__ ("Refund has been initiated, but it needs to be approved, so you need to wait for an approval " )
@@ -1818,7 +1850,7 @@ public function refundGroupTransactions(InfoInterface $payment, $amount)
1818
1850
1819
1851
$ this ->saveTransactionData ($ response [0 ], $ payment , $ this ->closeRefundTransaction , false );
1820
1852
1821
-
1853
+
1822
1854
foreach ($ groupTransaction as $ item ) {
1823
1855
$ prevRefundAmount = $ item ->getData ('refunded_amount ' );
1824
1856
$ newRefundAmount = $ amount_value ;
@@ -2489,14 +2521,14 @@ public function getPaymentRequestParameters($payment)
2489
2521
// First data to set is the billing address data.
2490
2522
$ requestData = $ this ->getRequestBillingData ($ payment );
2491
2523
2492
-
2524
+
2493
2525
// If the shipping address is not the same as the billing it will be merged inside the data array.
2494
2526
if (
2495
2527
$ this ->isAddressDataDifferent ($ payment ) ||
2496
2528
is_null ($ payment ->getOrder ()->getShippingAddress ()) ||
2497
2529
$ payment ->getMethod () === Klarna::KLARNA_METHOD_NAME ||
2498
2530
$ payment ->getMethod () === Klarnain::PAYMENT_METHOD_CODE ||
2499
- $ payment ->getMethod () === Afterpay20::PAYMENT_METHOD_CODE
2531
+ $ payment ->getMethod () === Afterpay20::PAYMENT_METHOD_CODE
2500
2532
) {
2501
2533
$ requestData = array_merge ($ requestData , $ this ->getRequestShippingData ($ payment ));
2502
2534
}
@@ -2581,14 +2613,14 @@ public function checkTotalGrossAmount($requestData, $payment)
2581
2613
}
2582
2614
public function canUseForCountry ($ country )
2583
2615
{
2584
-
2585
-
2616
+
2617
+
2586
2618
if ($ this ->getConfigData ('allowspecific ' ) != 1 ) {
2587
2619
return true ;
2588
2620
}
2589
2621
2590
2622
$ specificCountries = $ this ->getConfigData ('specificcountry ' );
2591
-
2623
+
2592
2624
//if the country config is null in the store get the config value from the global('default') settings
2593
2625
if ($ specificCountries === null ) {
2594
2626
$ specificCountries = $ this ->_scopeConfig ->getValue (
@@ -2598,6 +2630,6 @@ public function canUseForCountry($country)
2598
2630
2599
2631
$ availableCountries = explode (', ' , $ specificCountries );
2600
2632
return in_array ($ country , $ availableCountries );
2601
-
2633
+
2602
2634
}
2603
2635
}
0 commit comments