Skip to content

Commit

Permalink
Merge pull request #180 from paynl/feature/PLUG-3379
Browse files Browse the repository at this point in the history
PLUG-3379 - Add chargeback functionality
  • Loading branch information
woutse authored May 6, 2024
2 parents df5e94e + 95d619e commit 6b77262
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Controller/Checkout/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public function execute()
}
}

if ($transaction->isChargeBack() && substr($action, 0, 10) == 'chargeback') {
try {
$response = $this->payPayment->chargebackOrder($orderEntityId);
} catch (Exception $e) {
$response = $e->getMessage();
}
return $this->result->setContents($response === true ? 'TRUE|Chargeback success' : 'FALSE|' . $response);
}

if ($order->getTotalDue() <= 0) {
$this->payHelper->logDebug($action . '. Ignoring - already paid: ' . $orderEntityId);
if (!$this->config->registerPartialPayments()) {
Expand Down
8 changes: 8 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ public function refundFromPay()
return $this->store->getConfig('payment/paynl/allow_refund_from_pay');
}

/**
* @return string|null
*/
public function chargebackFromPayEnabled()
{
return $this->store->getConfig('payment/paynl/allow_chargeback_from_pay');
}

/**
* @param string $paymentProfileId
* @return mixed|void
Expand Down
22 changes: 22 additions & 0 deletions Model/PayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ public function uncancelOrder(Order $order)
$this->eventManager->dispatch('order_uncancel_after', ['order' => $order]);
}

/**
* @param integer $orderEntityId
* @return true
* @throws \Exception
*/
public function chargebackOrder($orderEntityId)
{
$order = $this->orderRepository->get($orderEntityId);
if (!$this->config->chargebackFromPayEnabled() || $order->getTotalDue() != 0 || $order->getBaseTotalRefunded() == $order->getBaseGrandTotal()) {
throw new \Exception("Ignoring chargeback");
}
try {
$creditmemo = $this->cmFac->createByOrder($order);
$this->cmService->refund($creditmemo);
$order->addStatusHistoryComment(__('PAY. - Chargeback initiated by customer'))->save();
} catch (\Exception $e) {
$this->payHelper->logDebug('Chargeback failed:', ['error' => $e->getMessage(), 'orderEntityId' => $orderEntityId]);
throw new \Exception('Could not chargeback');
}
return true;
}

/**
* @param integer $orderEntityId
* @return true
Expand Down
9 changes: 9 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ On - via Sherpa - Capture automatically via Sherpa.</tooltip>
<source_model>Paynl\Payment\Model\Config\Source\OffOn</source_model>
<config_path>payment/paynl/allow_refund_from_pay</config_path>
</field>
<field id="allow_chargeback_from_pay" translate="label" type="select" sortOrder="107" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Chargebacks</label>
<comment>
<![CDATA[Set to `on` to accept chargebacks initiated from Pay.]]>
</comment>
<tooltip>When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.</tooltip>
<source_model>Paynl\Payment\Model\Config\Source\OffOn</source_model>
<config_path>payment/paynl/allow_chargeback_from_pay</config_path>
</field>
<field id="never_cancel" translate="label,comment" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Never cancel order</label>
<comment>
Expand Down
3 changes: 2 additions & 1 deletion i18n/de_AT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,5 @@ On - via Sherpa - Capture automatically via Sherpa.","Aus – Keine automatische
Ein – Zahlungen mit dem Status AUTORISIEREN automatisch erfassen, wenn eine Sendung in Magento erstellt wird (Picqer wird dabei auch unterstützt).
Ein – über Wuunder – Automatische Erfassung über Wuunder.
Ein – über Sherpa – Automatische Erfassung über Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.",""
5 changes: 4 additions & 1 deletion i18n/de_CH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Aus – Keine automatische
Ein – Zahlungen mit dem Status AUTORISIEREN automatisch erfassen, wenn eine Sendung in Magento erstellt wird (Picqer wird dabei auch unterstützt).
Ein – über Wuunder – Automatische Erfassung über Wuunder.
Ein – über Sherpa – Automatische Erfassung über Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wenn die Shopwährung von der Basiswährungseinstellung in Magento abweicht, sorgt diese Einstellung dafür, dass die Zahlung in der Basiswährung und nicht in der Shopwährung beginnt."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wenn die Shopwährung von der Basiswährungseinstellung in Magento abweicht, sorgt diese Einstellung dafür, dass die Zahlung in der Basiswährung und nicht in der Shopwährung beginnt."
"Chargebacks","Rückbuchungen"
"Set to `on` to accept chargebacks initiated from Pay.","Setzen Sie diese Option auf "Ein", um von Pay initiierte Rückbuchungen zu akzeptieren."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Wenn diese Einstellung aktiviert ist, werden Rückbuchungen, die von Kunden initiiert wurden, in Magento erstattet."
5 changes: 4 additions & 1 deletion i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Aus – Keine automatische
Ein – Zahlungen mit dem Status AUTORISIEREN automatisch erfassen, wenn eine Sendung in Magento erstellt wird (Picqer wird dabei auch unterstützt).
Ein – über Wuunder – Automatische Erfassung über Wuunder.
Ein – über Sherpa – Automatische Erfassung über Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wenn die Shopwährung von der Basiswährungseinstellung in Magento abweicht, sorgt diese Einstellung dafür, dass die Zahlung in der Basiswährung und nicht in der Shopwährung beginnt."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wenn die Shopwährung von der Basiswährungseinstellung in Magento abweicht, sorgt diese Einstellung dafür, dass die Zahlung in der Basiswährung und nicht in der Shopwährung beginnt."
"Chargebacks","Rückbuchungen"
"Set to `on` to accept chargebacks initiated from Pay.","Setzen Sie diese Option auf "Ein", um von Pay initiierte Rückbuchungen zu akzeptieren."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Wenn diese Einstellung aktiviert ist, werden Rückbuchungen, die von Kunden initiiert wurden, in Magento erstattet."
5 changes: 4 additions & 1 deletion i18n/de_LU.csv
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Aus – Keine automatische
Ein – Zahlungen mit dem Status AUTORISIEREN automatisch erfassen, wenn eine Sendung in Magento erstellt wird (Picqer wird dabei auch unterstützt).
Ein – über Wuunder – Automatische Erfassung über Wuunder.
Ein – über Sherpa – Automatische Erfassung über Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wenn die Shopwährung von der Basiswährungseinstellung in Magento abweicht, sorgt diese Einstellung dafür, dass die Zahlung in der Basiswährung und nicht in der Shopwährung beginnt."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wenn die Shopwährung von der Basiswährungseinstellung in Magento abweicht, sorgt diese Einstellung dafür, dass die Zahlung in der Basiswährung und nicht in der Shopwährung beginnt."
"Chargebacks","Rückbuchungen"
"Set to `on` to accept chargebacks initiated from Pay.","Setzen Sie diese Option auf "Ein", um von Pay initiierte Rückbuchungen zu akzeptieren."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Wenn diese Einstellung aktiviert ist, werden Rückbuchungen, die von Kunden initiiert wurden, in Magento erstattet."
5 changes: 4 additions & 1 deletion i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Off - No autocapture.
On - Automatically capture payments with the status AUTHORIZE when a shipment is created in Magento (Picqer is also supported in this).
On - via Wuunder - Capture automatically via Wuunder.
On - via Sherpa - Capture automatically via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency."
"Chargebacks","Chargebacks"
"Set to `on` to accept chargebacks initiated from Pay.","Set to `on` to accept chargebacks initiated from Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","When this settings is enabled, chargebacks initiated by customers will refund the order in Magento."
5 changes: 4 additions & 1 deletion i18n/fr_BE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Désactivé - Pas de captu
Activé - Capturer automatiquement les paiements avec le statut AUTORISER lorsqu'un envoi est créé dans Magento (Picqer est également pris en charge dans ce domaine).
Activé - via Wuunder - Capture automatique via Wuunder.
Activé - via Sherpa - Capture automatique via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"Chargebacks","Refacturation"
"Set to `on` to accept chargebacks initiated from Pay.","Réglez ce paramètre sur "on" pour accepter les rétrofacturations initiées par Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Lorsque ce paramètre est activé, les rétrocessions initiées par les clients rembourseront la commande dans Magento."
5 changes: 4 additions & 1 deletion i18n/fr_CA.csv
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Désactivé - Pas de captu
Activé - Capturer automatiquement les paiements avec le statut AUTORISER lorsqu'un envoi est créé dans Magento (Picqer est également pris en charge dans ce domaine).
Activé - via Wuunder - Capture automatique via Wuunder.
Activé - via Sherpa - Capture automatique via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"Chargebacks","Refacturation"
"Set to `on` to accept chargebacks initiated from Pay.","Réglez ce paramètre sur "on" pour accepter les rétrofacturations initiées par Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Lorsque ce paramètre est activé, les rétrocessions initiées par les clients rembourseront la commande dans Magento."
5 changes: 4 additions & 1 deletion i18n/fr_CH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Désactivé - Pas de captu
Activé - Capturer automatiquement les paiements avec le statut AUTORISER lorsqu'un envoi est créé dans Magento (Picqer est également pris en charge dans ce domaine).
Activé - via Wuunder - Capture automatique via Wuunder.
Activé - via Sherpa - Capture automatique via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"Chargebacks","Refacturation"
"Set to `on` to accept chargebacks initiated from Pay.","Réglez ce paramètre sur "on" pour accepter les rétrofacturations initiées par Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Lorsque ce paramètre est activé, les rétrocessions initiées par les clients rembourseront la commande dans Magento."
5 changes: 4 additions & 1 deletion i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Désactivé - Pas de captu
Activé - Capturer automatiquement les paiements avec le statut AUTORISER lorsqu'un envoi est créé dans Magento (Picqer est également pris en charge dans ce domaine).
Activé - via Wuunder - Capture automatique via Wuunder.
Activé - via Sherpa - Capture automatique via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"Chargebacks","Refacturation"
"Set to `on` to accept chargebacks initiated from Pay.","Réglez ce paramètre sur "on" pour accepter les rétrofacturations initiées par Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Lorsque ce paramètre est activé, les rétrocessions initiées par les clients rembourseront la commande dans Magento."
5 changes: 4 additions & 1 deletion i18n/fr_LU.csv
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Désactivé - Pas de captu
Activé - Capturer automatiquement les paiements avec le statut AUTORISER lorsqu'un envoi est créé dans Magento (Picqer est également pris en charge dans ce domaine).
Activé - via Wuunder - Capture automatique via Wuunder.
Activé - via Sherpa - Capture automatique via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Lorsque la devise du magasin diffère de la devise de base dans Magento, ce paramètre garantit que le paiement commence dans la devise de base au lieu de la devise du magasin."
"Chargebacks","Refacturation"
"Set to `on` to accept chargebacks initiated from Pay.","Réglez ce paramètre sur "on" pour accepter les rétrofacturations initiées par Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Lorsque ce paramètre est activé, les rétrocessions initiées par les clients rembourseront la commande dans Magento."
5 changes: 4 additions & 1 deletion i18n/nl_BE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,7 @@ On - via Sherpa - Capture automatically via Sherpa.","Uit - Geen autocapture.
Aan - Capture automatisch betalingen met de status AUTHORIZE wanneer een shipment in Magento wordt aangemaakt (Picqer wordt hierin ook ondersteund).
Aan - via Wuunder - Capture automatisch via Wuunder.
Aan - via Sherpa - Capture automatisch via Sherpa."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wanneer de winkelvaluta afwijkt van de basisvaluta-instelling in Magento, zorgt deze instelling ervoor dat de betalingen worden gestart in de basisvaluta in plaats van de winkelvaluta."
"When the store currency deviates from the base currency setting in Magento, this setting will ensure the payment starts in the base currency instead of the store currency.","Wanneer de winkelvaluta afwijkt van de basisvaluta-instelling in Magento, zorgt deze instelling ervoor dat de betalingen worden gestart in de basisvaluta in plaats van de winkelvaluta."
"Chargebacks","Terugboekingen"
"Set to `on` to accept chargebacks initiated from Pay.","Stel in op `aan` om chargebacks te accepteren die zijn geïnitieerd vanuit Pay."
"When this settings is enabled, chargebacks initiated by customers will refund the order in Magento.","Als deze instelling is ingeschakeld, zullen chargebacks die door klanten worden geïnitieerd de bestelling refunden in Magento."
Loading

0 comments on commit 6b77262

Please sign in to comment.