Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bp 3310 refund not working for some payment methods #118

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

require_once dirname(__FILE__) . '/../paymentmethod.php';

class Kbc extends PaymentMethod
class Kbcpaymentbutton extends PaymentMethod
{
public function __construct()
{
$this->type = 'kbc';
$this->type = 'kbcpaymentbutton';
$this->version = 1;
}
}
4 changes: 2 additions & 2 deletions api/paymentmethods/paymentrequestfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PaymentRequestFactory
public const REQUEST_TYPE_IDEAL = 'ideal';
public const REQUEST_TYPE_PAYBYBANK = 'paybybank';
public const REQUEST_TYPE_GIROPAY = 'giropay';
public const REQUEST_TYPE_KBC = 'kbc';
public const REQUEST_TYPE_KBCPAYMENTBUTTON = 'kbcpaymentbutton';
public const REQUEST_TYPE_SEPADIRECTDEBIT = 'sepadirectdebit';
public const REQUEST_TYPE_BANCONTACTMRCASH = 'bancontactmrcash';
public const REQUEST_TYPE_SOFORTBANKING = 'sofortueberweisung';
Expand Down Expand Up @@ -58,7 +58,7 @@ class PaymentRequestFactory
PaymentRequestFactory::REQUEST_TYPE_PAYBYBANK => 'PayByBank',
PaymentRequestFactory::REQUEST_TYPE_SEPADIRECTDEBIT => 'SepaDirectDebit',
PaymentRequestFactory::REQUEST_TYPE_GIROPAY => 'Giropay',
PaymentRequestFactory::REQUEST_TYPE_KBC => 'Kbc',
PaymentRequestFactory::REQUEST_TYPE_KBCPAYMENTBUTTON => 'Kbcpaymentbutton',
PaymentRequestFactory::REQUEST_TYPE_BANCONTACTMRCASH => 'Bancontactmrcash',
PaymentRequestFactory::REQUEST_TYPE_SOFORTBANKING => 'Sofortbanking',
PaymentRequestFactory::REQUEST_TYPE_GIFTCARD => 'GiftCard',
Expand Down
2 changes: 1 addition & 1 deletion dev/lang/php_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
"payment_methods.ideal": "Ideal",
"payment_methods.idin": "iDIN",
"payment_methods.in3": "In3",
"payment_methods.kbc": "KBC",
"payment_methods.kbcpaymentbutton": "KBC",
"payment_methods.klarna": "Klarna",
"payment_methods.mbway": "MB WEG",
"payment_methods.multibanco": "Multibanco",
Expand Down
2 changes: 1 addition & 1 deletion dev/lang/php_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
"payment_methods.ideal": "iDEAL",
"payment_methods.idin": "iDIN",
"payment_methods.in3": "In3",
"payment_methods.kbc": "KBC",
"payment_methods.kbcpaymentbutton": "KBC",
"payment_methods.klarna": "Klarna",
"payment_methods.mbway": "MB WAY",
"payment_methods.multibanco": "Multibanco",
Expand Down
2 changes: 1 addition & 1 deletion dev/lang/php_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
"payment_methods.ideal": "idéal",
"payment_methods.idin": "IDIN",
"payment_methods.in3": "Dans3",
"payment_methods.kbc": "KBC",
"payment_methods.kbcpaymentbutton": "KBC",
"payment_methods.klarna": "Klarna",
"payment_methods.mbway": "VOIE MB",
"payment_methods.multibanco": "Multibanco",
Expand Down
2 changes: 1 addition & 1 deletion dev/lang/php_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
"payment_methods.ideal": "iDEAL",
"payment_methods.idin": "iDIN",
"payment_methods.in3": "In3",
"payment_methods.kbc": "KBC",
"payment_methods.kbcpaymentbutton": "KBC",
"payment_methods.klarna": "Klarna",
"payment_methods.mbway": "MB WAY",
"payment_methods.multibanco": "Multibanco",
Expand Down
4 changes: 2 additions & 2 deletions library/checkout/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class Checkout
public const CHECKOUT_TYPE_PAYBYBANK = 'paybybank';
public const CHECKOUT_TYPE_SEPADIRECTDEBIT = 'sepadirectdebit';
public const CHECKOUT_TYPE_GIROPAY = 'giropay';
public const CHECKOUT_TYPE_KBC = 'kbc';
public const CHECKOUT_TYPE_KBCPAYMENTBUTTON = 'kbcpaymentbutton';
public const CHECKOUT_TYPE_BANCONTACTMRCASH = 'bancontactmrcash';
public const CHECKOUT_TYPE_GIFTCARD = 'giftcard';
public const CHECKOUT_TYPE_CREDITCARD = 'creditcard';
Expand Down Expand Up @@ -66,7 +66,7 @@ abstract class Checkout
Checkout::CHECKOUT_TYPE_PAYBYBANK => 'PayByBank',
Checkout::CHECKOUT_TYPE_SEPADIRECTDEBIT => 'SepaDirectdebit',
Checkout::CHECKOUT_TYPE_GIROPAY => 'Giropay',
Checkout::CHECKOUT_TYPE_KBC => 'Kbc',
Checkout::CHECKOUT_TYPE_KBCPAYMENTBUTTON => 'Kbcpaymentbutton',
Checkout::CHECKOUT_TYPE_BANCONTACTMRCASH => 'Bancontactmrcash',
Checkout::CHECKOUT_TYPE_GIFTCARD => 'GiftCard',
Checkout::CHECKOUT_TYPE_CREDITCARD => 'CreditCard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
exit;
}

class KbcCheckout extends Checkout
class KbcpaymentbuttonCheckout extends Checkout
{
final public function setCheckout()
{
Expand All @@ -44,6 +44,6 @@ public function isVerifyRequired()

protected function initialize()
{
$this->payment_request = PaymentRequestFactory::create(PaymentRequestFactory::REQUEST_TYPE_KBC);
$this->payment_request = PaymentRequestFactory::create(PaymentRequestFactory::REQUEST_TYPE_KBCPAYMENTBUTTON);
}
}
14 changes: 11 additions & 3 deletions src/Refund/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ private function refund(\Order $order, \OrderPayment $payment, OrderRefundSummar
*/
private function getBuckarooPayments(\Order $order): array
{
return array_filter($order->getOrderPayments(), function ($orderPayment) {
return strpos($orderPayment->payment_method, 'Buckaroo Payments') !== false;
});
$buckarooPayments = [];
$allPayments = $order->getOrderPayments();

// Check if the order's module is 'buckaroo3'
if ($order->module === 'buckaroo3') {
foreach ($allPayments as $payment) {
$buckarooPayments[] = $payment;
}
}

return $buckarooPayments;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Refund/Request/AbstractBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,7 @@ private function getPushUrl(): string
*/
protected function buildIssuers(\OrderPayment $payment): array
{
if (in_array($payment->payment_method, [
'creditcard', 'mastercard', 'visa',
'amex', 'vpay', 'maestro',
'visaelectron', 'cartebleuevisa',
'cartebancaire', 'dankort', 'nexi',
'postepay',
])) {
if (PaymentMethodHelper::isCreditCardMethod($payment->payment_method)) {
return [
'name' => $payment->payment_method,
'version' => 2,
Expand Down
5 changes: 5 additions & 0 deletions src/Refund/Request/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ public function refund(array $body, string $method): TransactionResponse
* @param string $method
*
* @return BuckarooClient
* @throws \Exception
*/
private function getClient(string $method): BuckarooClient
{
if (PaymentMethodHelper::isCreditCardMethod($method)) {
$method = 'creditcard';
}

return new BuckarooClient(
\Configuration::get('BUCKAROO_MERCHANT_KEY'),
\Configuration::get('BUCKAROO_SECRET_KEY'),
Expand Down
39 changes: 39 additions & 0 deletions src/Refund/Request/PaymentMethodHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* It is available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this file
*
* @author Buckaroo.nl <[email protected]>
* @copyright Copyright (c) Buckaroo B.V.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

namespace Buckaroo\PrestaShop\Src\Refund\Request;

class PaymentMethodHelper
{
/**
* Check if the payment method is a type of credit card.
*
* @param string $method The payment method to check.
* @return bool Returns true if the method is a type of credit card, false otherwise.
*/
public static function isCreditCardMethod(string $method): bool {
$creditCardMethods = [
'creditcard', 'mastercard', 'visa',
'amex', 'vpay', 'maestro',
'visaelectron', 'cartebleuevisa', 'cartebleue',
'cartebancaire', 'dankort', 'nexi',
'postepay',
];

return in_array($method, $creditCardMethods);
}
}
2 changes: 1 addition & 1 deletion src/Repository/RawPaymentMethodRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function getPaymentMethodsData()
['name' => 'paypal', 'label' => 'PayPal', 'icon' => 'PayPal.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'sepadirectdebit', 'label' => 'SEPA Direct Debit', 'icon' => 'SEPA-directdebit.svg', 'template' => 'payment_sepadirectdebit.tpl', 'is_payment_method' => '1'],
['name' => 'giropay', 'label' => 'GiroPay', 'icon' => 'Giropay.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'kbc', 'label' => 'KBC', 'icon' => 'KBC.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'kbcpaymentbutton', 'label' => 'KBC', 'icon' => 'KBC.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'bancontactmrcash', 'label' => 'Bancontact / Mister Cash', 'icon' => 'Bancontact.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'giftcard', 'label' => 'Giftcards', 'icon' => 'Giftcards.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'creditcard', 'label' => 'Cards', 'icon' => 'Creditcards.svg', 'template' => 'payment_creditcard.tpl', 'is_payment_method' => '1'],
Expand Down
1 change: 1 addition & 0 deletions upgrade/upgrade-4.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ function upgrade_module_4_1($object)

Db::getInstance()->execute('DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'bk_countries');

Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'bk_payment_methods SET name = "kbcpaymentbutton" WHERE name = "kbc"');
return true;
}
60 changes: 30 additions & 30 deletions views/js/buckaroo.vue.js

Large diffs are not rendered by default.