Skip to content

Commit 2d3cb8f

Browse files
authored
Merge pull request #609 from buckaroo-it/develop
version 1.43.1
2 parents 9dfe22f + e2cd8fe commit 2d3cb8f

File tree

6 files changed

+84
-17
lines changed

6 files changed

+84
-17
lines changed

Controller/Redirect/Process.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ protected function handleFailed($statusCode)
427427

428428
$this->eventManager->dispatch('buckaroo_process_handle_failed_before');
429429

430+
$this->removeAmastyGiftcardOnFailed();
431+
430432
if (!$this->getSkipHandleFailedRecreate()) {
431433
if (!$this->quoteRecreate->recreate($this->quote)) {
432434
$this->logging->addError('Could not recreate the quote.');
@@ -711,11 +713,42 @@ private function setCustomerIDIN()
711713

712714
public function getSkipHandleFailedRecreate()
713715
{
714-
return false;
716+
return false;
715717
}
716718

717719
public function setSkipHandleFailedRecreate($value)
718720
{
719721
return true;
720722
}
723+
724+
/**
725+
* Remove amasty giftcard from failed order
726+
*
727+
* @return void
728+
*/
729+
protected function removeAmastyGiftcardOnFailed()
730+
{
731+
$class = \Amasty\GiftCardAccount\Model\GiftCardAccount\Repository::class;
732+
if (class_exists($class)) {
733+
734+
$giftcardAccountRepository = $this->_objectManager->get($class);
735+
$giftcardOrderRepository = $this->_objectManager->get(\Amasty\GiftCardAccount\Model\GiftCardExtension\Order\Repository::class);
736+
737+
try {
738+
$giftcardOrder = $giftcardOrderRepository->getByOrderId($this->order->getId());
739+
740+
foreach ($giftcardOrder->getGiftCards() as $giftcardObj) {
741+
/** @var \Amasty\GiftCardAccount\Api\Data\GiftCardAccountInterface */
742+
$giftcard = $giftcardAccountRepository->getByCode($giftcardObj['code']);
743+
$giftcard->setStatus(1);
744+
745+
$giftcard->setCurrentValue($giftcard->getCurrentValue() + (float)$giftcardObj['amount']);
746+
$giftcardAccountRepository->save($giftcard);
747+
}
748+
} catch (\Throwable $th) {
749+
$this->logger->addDebug($th->getMessage());
750+
return;
751+
}
752+
}
753+
}
721754
}

Model/Method/AbstractMethod.php

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ protected function assignDataCommon(array $data)
386386
if (isset($data['additional_data']['customer_gender'])) {
387387
$this->getInfoInstance()->setAdditionalInformation('customer_gender', $additionalData['customer_gender']);
388388
}
389-
390-
if (isset($data['additional_data']['termsCondition'])) {
389+
390+
if (isset($data['additional_data']['termsCondition'])) {
391391
$this->getInfoInstance()->setAdditionalInformation('termsCondition', $additionalData['termsCondition']);
392392
$this->getInfoInstance()->setAdditionalInformation('customer_billingName', $additionalData['customer_billingName']);
393393
$this->getInfoInstance()->setAdditionalInformation('customer_identificationNumber', $additionalData['customer_identificationNumber']);
@@ -715,7 +715,7 @@ public function order(InfoInterface $payment, $amount)
715715
if (!(isset($response->RequiredAction->Type) && $response->RequiredAction->Type === 'Redirect')) {
716716
$this->setPaymentInTransit($payment, false);
717717
}
718-
718+
719719
$order = $payment->getOrder();
720720
$this->helper->setRestoreQuoteLastOrder($order->getId());
721721

@@ -789,6 +789,10 @@ protected function getFailureMessage($response)
789789
$responseCode = $transactionResponse->Status->Code->Code;
790790
$billingCountry = $this->payment->getOrder()->getBillingAddress()->getCountryId();
791791

792+
if($responseCode == 491) {
793+
return $this->getFirstError($transactionResponse);
794+
}
795+
792796
$method = null;
793797
if ($this->payment->getMethodInstance() && !empty($this->payment->getMethodInstance()->buckarooPaymentMethodCode)) {
794798
$method = $this->payment->getMethodInstance()->buckarooPaymentMethodCode;
@@ -818,6 +822,34 @@ protected function getFailureMessage($response)
818822
return $message;
819823
}
820824

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+
821853
public function getFailureMessageOnFraud($transactionResponse)
822854
{
823855
if (
@@ -904,7 +936,7 @@ public function authorize(InfoInterface $payment, $amount)
904936
if (!(isset($response->RequiredAction->Type) && $response->RequiredAction->Type === 'Redirect')) {
905937
$this->setPaymentInTransit($payment, false);
906938
}
907-
939+
908940
$order = $payment->getOrder();
909941
$this->helper->setRestoreQuoteLastOrder($order->getId());
910942

@@ -1167,7 +1199,7 @@ public function refundTransaction(\Buckaroo\Magento2\Gateway\Http\Transaction $t
11671199
$payment->getOrder()->addStatusHistoryComment(
11681200
__("The refund has been initiated but it is waiting for a approval. Login to the Buckaroo Plaza to finalize the refund by approving it.")
11691201
)->setIsCustomerNotified(false)->save();
1170-
1202+
11711203
$messageManager = $this->objectManager->get('Magento\Framework\Message\ManagerInterface');
11721204
$messageManager->addError(
11731205
__("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)
18181850

18191851
$this->saveTransactionData($response[0], $payment, $this->closeRefundTransaction, false);
18201852

1821-
1853+
18221854
foreach ($groupTransaction as $item) {
18231855
$prevRefundAmount = $item->getData('refunded_amount');
18241856
$newRefundAmount = $amount_value;
@@ -2489,14 +2521,14 @@ public function getPaymentRequestParameters($payment)
24892521
// First data to set is the billing address data.
24902522
$requestData = $this->getRequestBillingData($payment);
24912523

2492-
2524+
24932525
// If the shipping address is not the same as the billing it will be merged inside the data array.
24942526
if (
24952527
$this->isAddressDataDifferent($payment) ||
24962528
is_null($payment->getOrder()->getShippingAddress()) ||
24972529
$payment->getMethod() === Klarna::KLARNA_METHOD_NAME ||
24982530
$payment->getMethod() === Klarnain::PAYMENT_METHOD_CODE ||
2499-
$payment->getMethod() === Afterpay20::PAYMENT_METHOD_CODE
2531+
$payment->getMethod() === Afterpay20::PAYMENT_METHOD_CODE
25002532
) {
25012533
$requestData = array_merge($requestData, $this->getRequestShippingData($payment));
25022534
}
@@ -2581,14 +2613,14 @@ public function checkTotalGrossAmount($requestData, $payment)
25812613
}
25822614
public function canUseForCountry($country)
25832615
{
2584-
2585-
2616+
2617+
25862618
if ($this->getConfigData('allowspecific') != 1) {
25872619
return true;
25882620
}
25892621

25902622
$specificCountries = $this->getConfigData('specificcountry');
2591-
2623+
25922624
//if the country config is null in the store get the config value from the global('default') settings
25932625
if ($specificCountries === null) {
25942626
$specificCountries = $this->_scopeConfig->getValue(
@@ -2598,6 +2630,6 @@ public function canUseForCountry($country)
25982630

25992631
$availableCountries = explode(',', $specificCountries);
26002632
return in_array($country, $availableCountries);
2601-
2633+
26022634
}
26032635
}

Model/Push.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ public function receivePush()
367367
if (isset($this->postData['brq_statusmessage'])) {
368368
if (
369369
$this->order->getState() === Order::STATE_NEW &&
370-
!isset($this->postData['add_frompayperemail'])
370+
!isset($this->postData['add_frompayperemail']) &&
371+
(isset($this->postData['brq_statuscode']) && $this->postData['brq_statuscode'] == 190)
372+
371373
) {
372374
$this->order->setState(Order::STATE_PROCESSING);
373375
$this->order->addStatusHistoryComment(

Service/Software/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Data
3535
const MODULE_CODE = 'Buckaroo_Magento2';
3636

3737
/** Version of Module */
38-
const BUCKAROO_VERSION = '1.43.0';
38+
const BUCKAROO_VERSION = '1.43.1';
3939

4040
/** @var ProductMetadataInterface */
4141
private $productMetadata;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"docs": "https://support.buckaroo.nl"
2323
},
2424
"homepage": "https://www.buckaroo.nl",
25-
"version" : "v1.43.0",
25+
"version" : "v1.43.1",
2626
"minimum-stability": "stable",
2727
"autoload": {
2828
"files": [

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
-->
2222
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Buckaroo_Magento2:etc/buckaroo_module.xsd">
23-
<module name="Buckaroo_Magento2" setup_version="1.43.0" build_number="1769" stability="stable">
23+
<module name="Buckaroo_Magento2" setup_version="1.43.1" build_number="1769" stability="stable">
2424
<sequence>
2525
<module name="Magento_Payment"/>
2626
<module name="Magento_ReleaseNotification"/>

0 commit comments

Comments
 (0)