Skip to content

Commit

Permalink
V2.0.2 (#146)
Browse files Browse the repository at this point in the history
* BP-2904 Pay the remaining group transaction amount with iDEAL, Bancon… (#143)

* BP-2904 Pay the remaining group transaction amount with iDEAL, Bancontact etc

* correctly set version in composer.json

* remove methods

* fix phpcs

* fix in3 logo selector visibility

---------

Co-authored-by: Ivascu Madalin <madalin.ivascu@arnia.ro>

* added assets

* change version in composer json

* BP-2944 Shopware 6 - Cannot partially refund group transactions

* fix validation messages

---------

Co-authored-by: Ivascu Madalin <madalin.ivascu@arnia.ro>
  • Loading branch information
harli91 and Ivascu Madalin committed Sep 21, 2023
1 parent 5158694 commit 9e947f7
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 55 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "buckaroo/shopware6",
"description": "Buckaroo payment provider plugin for Shopware 6",
"type": "shopware-platform-plugin",
"version": "2.0.0",
"version": "2.0.2",
"license": "proprietary",
"minimum-stability": "stable",
"require": {
Expand All @@ -11,6 +11,7 @@
"ext-json": "*",
"ext-pcre": "*",
"ext-fileinfo": "*",
"shopware/core": "~6.5.0",
"buckaroo/sdk": "^1.6"
},
"authors": [{
Expand Down
37 changes: 32 additions & 5 deletions src/Handlers/GiftcardsPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,42 @@ protected function getMethodAction(

protected function getAllowedGiftcards(string $salesChannelId): string
{
$allowedgiftcards = $this->asyncPaymentService
$allowedGiftcards = $this->asyncPaymentService
->settingsService
->getSetting('allowedgiftcards', $salesChannelId);

if (is_array($allowedgiftcards) &&
count($allowedgiftcards)
$allowedServices = [];

if (
is_array($allowedGiftcards) &&
count($allowedGiftcards)
) {
return implode(",", $allowedgiftcards).",ideal,bancontactmrcash";
$allowedServices = $allowedGiftcards;
}

$allowedMethods = $this->getAllowedMethods($salesChannelId);

if (count($allowedMethods) === 0) {
$allowedMethods = ['ideal']; //defaults to ideal payment method
}
return 'ideal';
$allowedServices = array_merge($allowedServices, $allowedMethods);

return implode(",", $allowedServices);
}

protected function getAllowedMethods(string $salesChannelId): array
{
$allowedMethods = $this->asyncPaymentService
->settingsService
->getSetting('giftcardsPaymentmethods', $salesChannelId);

if (
!is_array($allowedMethods) ||
count($allowedMethods) == 0
) {
return [];
}

return $allowedMethods;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ Component.register('buckaroo-settings', {
id = id.join("");

if (config["BuckarooPayments.config." + id + "Enabled"] != undefined && config["BuckarooPayments.config." + id + "Enabled"]) {
if (fid === "capayableLogo") {
if (
config["BuckarooPayments.config.capayableVersion"] === undefined ||
config["BuckarooPayments.config.capayableVersion"] ==='v3') {
return true;
}
return false;
}
return true;
}

Expand Down
93 changes: 93 additions & 0 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,99 @@
</option>
</options>
</input-field>
<input-field type="multi-select">
<name>giftcardsPaymentmethods</name>
<label lang="en-GB">Allowed payment methods:</label>
<label lang="de-DE">Allowed payment methods:</label>
<label lang="nl-NL">Allowed payment methods:</label>
<label lang="fr-FR">Allowed payment methods:</label>
<options>
<option>
<id>applepay</id>
<name>Apple Pay</name>
</option>
<option>
<id>bancontactmrcash</id>
<name>Bancontact</name>
</option>
<option>
<id>belfius</id>
<name>Belfius</name>
</option>
<option>
<id>eps</id>
<name>EPS</name>
</option>
<option>
<id>postepay</id>
<name>PostePay</name>
</option>
<option>
<id>ideal</id>
<name>iDEAL</name>
</option>
<option>
<id>kbcpaymentbutton</id>
<name>KBC</name>
</option>
<option>
<id>paypal</id>
<name>PayPal</name>
</option>
<option>
<id>sofortueberweisung</id>
<name>SOFORT</name>
</option>
<option>
<id>Przelewy24</id>
<name>Przelewy24</name>
</option>
<option>
<id>mastercard</id>
<name>MasterCard</name>
</option>
<option>
<id>visa</id>
<name>Visa</name>
</option>
<option>
<id>amex</id>
<name>American Express</name>
</option>
<option>
<id>vpay</id>
<name>VPay</name>
</option>
<option>
<id>maestro</id>
<name>Maestro</name>
</option>
<option>
<id>visaelectron</id>
<name>Visa Electron</name>
</option>
<option>
<id>cartebleuevisa</id>
<name>Carte Bleue</name>
</option>
<option>
<id>cartebancaire</id>
<name>Carte Bancaire</name>
</option>
<option>
<id>dankort</id>
<name>Dankort</name>
</option>
<option>
<id>nexi</id>
<name>Nexi</name>
</option>
<option>
<id>postepay</id>
<name>PostePay</name>
</option>
</options>
</input-field>
</card>
<card>
<title>In3</title>
Expand Down

Large diffs are not rendered by default.

116 changes: 82 additions & 34 deletions src/Service/RefundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,12 @@ public function __construct(
$this->clientService = $clientService;
}

/**
* Do a buckaroo refund request
*
* @param Request $request
* @param OrderEntity $order
* @param Context $context
* @param array<mixed> $transaction
*
* @return array<mixed>|null
*/
public function refund(
public function refundAll(
Request $request,
OrderEntity $order,
Context $context,
array $transaction
): ?array {
array $transactionsToRefund
) {
if (!$this->transactionService->isBuckarooPaymentMethod($order)) {
return null;
}
Expand All @@ -84,16 +74,71 @@ public function refund(
$validationErrors = $this->validate($order, $customFields);

if ($validationErrors !== null) {
return $validationErrors;
return [$validationErrors];
}

$amount = $this->determineAmount(
$amountRemaining = $this->getMaxAmount(
$orderItems,
$request->get('customRefundAmount'),
$transaction['amount'],
$configCode
);

$responses = [];
foreach ($transactionsToRefund as $item) {

if ($amountRemaining <= 0) {
break;
}

if (is_array($item) && isset($item['amount']) && is_scalar($item['amount'])) {
$amount = $item['amount'];

$diff = $amountRemaining - $amount;

if ($diff < 0) {
$amount = $amountRemaining;
$amountRemaining = 0;
} else {
$amountRemaining = round($diff, 2);
}

$responses[] = $this->refund(
$request,
$order,
$context,
$item,
$amount,
$configCode,
$orderItems
);
}
}

return $responses;
}

/**
* Do a buckaroo refund request
*
* @param Request $request
* @param OrderEntity $order
* @param Context $context
* @param array<mixed> $transaction
*
* @return array<mixed>|null
*/
public function refund(
Request $request,
OrderEntity $order,
Context $context,
array $transaction,
float $amount,
string $configCode,
array $orderItems
): ?array {



if ($amount <= 0) {
return [];
}
Expand Down Expand Up @@ -423,27 +468,21 @@ private function getIp(Request $request): array
];
}

/**
*
/* *
* @param array<mixed> $orderItems
* @param mixed $customRefundAmount
* @param mixed $transactionAmount
* @param string $paymentCode
*
* @return float
*/
public function determineAmount(
public function getMaxAmount(
array $orderItems,
$customRefundAmount,
$transactionAmount,
string $paymentCode
): float {
$amount = 0;
if (
is_scalar($customRefundAmount) &&
(float)$customRefundAmount > 0 &&
!in_array($paymentCode, ['afterpay', 'Billink', 'klarnakp'])
) {

if ($this->isCustomRefundAmount($customRefundAmount, $paymentCode)) {
$amount = (float)$customRefundAmount;
} else {
if (!empty($orderItems) && is_array($orderItems)) {
Expand All @@ -453,18 +492,27 @@ public function determineAmount(
}
}
}

if (is_scalar($transactionAmount) && $amount > (float)$transactionAmount) {
$amount = (float)$transactionAmount;
}
}

if ($amount <= 0 && is_scalar($transactionAmount)) {
$amount = (float)$transactionAmount; //backward compatibility only or in case no $orderItems was passed
}
return $amount;
}



/**
* Is custom refund amount
*
* @param mixed $customRefundAmount
* @param string $paymentCode
*
* @return boolean
*/
private function isCustomRefundAmount($customRefundAmount, string $paymentCode)
{
return is_scalar($customRefundAmount) &&
(float)$customRefundAmount > 0 &&
!in_array($paymentCode, ['afterpay', 'Billink', 'klarnakp']);
}

/**
* @param array<mixed> $customFields
*
Expand Down
16 changes: 6 additions & 10 deletions src/Storefront/Controller/RefundController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@ public function refundBuckaroo(Request $request, Context $context): JsonResponse
$responses = [];

if (is_array($transactionsToRefund)) {
foreach ($transactionsToRefund as $item) {
if (is_array($item)) {
$responses[] = $this->refundService->refund(
$request,
$order,
$context,
$item,
);
}
}
$responses = $this->refundService->refundAll(
$request,
$order,
$context,
$transactionsToRefund,
);
}
return new JsonResponse($responses);
} catch (\Exception $exception) {
Expand Down
4 changes: 0 additions & 4 deletions src/Subscribers/CheckoutConfirmTemplateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ public function hideNotEnabledPaymentMethods($event): void
if ($buckarooKey === 'afterpay' && !$this->canShowAfterpay($event)) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, $paymentMethod->getId());
}

if ($buckarooKey === 'afterpay' && !$this->canShowAfterpay($event)) {
$paymentMethods = $this->removePaymentMethod($paymentMethods, $paymentMethod->getId());
}
}
}
$event->getPage()->setPaymentMethods($paymentMethods);
Expand Down

0 comments on commit 9e947f7

Please sign in to comment.