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 2358 support for new rma module available from shopware v 6 5 #140

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ parameters:
- ./src
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: false
checkGenericClassInNonGenericObjectType: false
excludePaths:
- ./src/Subscribers/OrderReturnCreatedSubscriber.php
- ./custom/plugins/BuckarooPayments/src/Service/RefundService.php
1 change: 0 additions & 1 deletion src/Buckaroo/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Buckaroo\Shopware6\Buckaroo;

use Buckaroo\BuckarooClient;
use Buckaroo\Shopware6\Buckaroo\PayloadFragmentInterface;

class Client
{
Expand Down
61 changes: 61 additions & 0 deletions src/Buckaroo/Refund/Order/PaymentRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Buckaroo\Shopware6\Buckaroo\Refund\Order;

use Buckaroo\Shopware6\Buckaroo\Refund\Order\PaymentRecordInterface;

class PaymentRecord implements PaymentRecordInterface
{
private array $transactionData;

public function __construct(array $transactionData)
{
$this->transactionData = $transactionData;
}

public function getId(): string
{
if (
!isset($this->transactionData['id']) ||
!is_scalar($this->transactionData['id'])
) {
throw new \InvalidArgumentException('Transaction id must be a string');
}
return (string)$this->transactionData['id'];
}

public function getAmount(): float
{
if (
!isset($this->transactionData['amount']) ||
!is_scalar($this->transactionData['amount'])
) {
return 0;
}
return (float)$this->transactionData['amount'];
}

public function getOriginalTransactionId(): ?string
{
if (
!isset($this->transactionData['transactions']) ||
!is_string($this->transactionData['transactions'])
) {
return null;
}
return $this->transactionData['transactions'];
}

public function getPaymentCode(): ?string
{
if (
!isset($this->transactionData['transaction_method']) &&
!is_string($this->transactionData['transaction_method'])
) {
return null;
}
return $this->transactionData['transaction_method'];
}
}
16 changes: 16 additions & 0 deletions src/Buckaroo/Refund/Order/PaymentRecordInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Buckaroo\Shopware6\Buckaroo\Refund\Order;

interface PaymentRecordInterface
{
public function getId(): string;

public function getAmount(): float;

public function getOriginalTransactionId(): ?string;

public function getPaymentCode(): ?string;
}
67 changes: 67 additions & 0 deletions src/Buckaroo/Refund/Order/ReturnPaymentRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Buckaroo\Shopware6\Buckaroo\Refund\Order;

use Buckaroo\Shopware6\Buckaroo\Refund\Order\PaymentRecordInterface;
use Buckaroo\Shopware6\Entity\Transaction\BuckarooTransactionEntity;

class ReturnPaymentRecord implements PaymentRecordInterface
{
private BuckarooTransactionEntity $transactionData;

private float $amount;

public function __construct(BuckarooTransactionEntity $transactionData, float $amount)
{
$this->transactionData = $transactionData;
$this->amount = $amount;
}

public function getId(): string
{
if (!is_scalar($this->transactionData->get('id'))) {
return '';
}
return (string)$this->transactionData->get('id');
}

public function getAmount(): float
{

if (
!is_scalar($this->transactionData->get('amount')) ||
!is_scalar($this->transactionData->get('amount_credit'))
) {
return 0.0;
}
return (float)$this->transactionData->get('amount') - (float)$this->transactionData->get('amount_credit');
}

public function getOriginalTransactionId(): ?string
{
if (
!is_string($this->transactionData->get('transactions'))
) {
return null;
}
return $this->transactionData->get('transactions');
}

public function getPaymentCode(): ?string
{
if (
!is_string($this->transactionData->get('transaction_method'))
) {
return null;
}
return $this->transactionData->get('transaction_method');
}

public function addAmount(float $amount): self
{
$this->amount += $amount;
return $this;
}
}
96 changes: 96 additions & 0 deletions src/Buckaroo/Refund/OrderRefundData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Buckaroo\Shopware6\Buckaroo\Refund;

use Buckaroo\Shopware6\Buckaroo\Refund\Order\PaymentRecordInterface;
use Shopware\Core\Checkout\Order\OrderEntity;
use Buckaroo\Shopware6\Buckaroo\Refund\RefundDataInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;

class OrderRefundData implements RefundDataInterface
{
/**
* @var OrderEntity
*/
private OrderEntity $order;

private float $amount;

private PaymentRecordInterface $paymentRecord;

public function __construct(
OrderEntity $order,
PaymentRecordInterface $paymentRecord,
float $amount
) {
$this->order = $order;
$this->amount = $amount;
$this->paymentRecord = $paymentRecord;
}
public function getInvoiceNumber(): string
{
if ($this->order->getOrderNumber() === null) {
return '';
}
return $this->order->getOrderNumber();
}

public function getOrderNumber(): string
{
return $this->getInvoiceNumber();
}

public function getAmount(): float
{
return $this->amount;
}

public function getCurrency(): string
{
$currency = $this->order->getCurrency();
if ($currency === null) {
throw new \InvalidArgumentException('Cannot find currency on order');
}
return $currency->getIsoCode();
}

public function getTransactionId(): string
{
return $this->getLastTransaction()->getId();
}

public function getOrderId(): string
{
return $this->order->getId();
}

public function getLastTransaction(): OrderTransactionEntity
{
$transactions = $this->order->getTransactions();

if ($transactions === null) {
throw new \InvalidArgumentException('Cannot find last transaction on order');
}

/** @var \Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity|null */
$transaction = $transactions->last();

if ($transaction === null) {
throw new \InvalidArgumentException('Cannot find last transaction on order');
}

return $transaction;
}

public function getOrder(): OrderEntity
{
return $this->order;
}

public function getPaymentRecord(): PaymentRecordInterface
{
return $this->paymentRecord;
}
}
30 changes: 30 additions & 0 deletions src/Buckaroo/Refund/RefundDataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Buckaroo\Shopware6\Buckaroo\Refund;

use Shopware\Core\Checkout\Order\OrderEntity;
use Buckaroo\Shopware6\Buckaroo\Refund\Order\PaymentRecordInterface;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;

interface RefundDataInterface
{
public function getInvoiceNumber(): string;

public function getOrderNumber(): string;

public function getAmount(): float;

public function getCurrency(): string;

public function getTransactionId(): string;

public function getOrderId(): string;

public function getOrder(): OrderEntity;

public function getPaymentRecord(): PaymentRecordInterface;

public function getLastTransaction(): OrderTransactionEntity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ Component.register('buckaroo-payment-detail', {
if (response[key].status) {
this.createNotificationSuccess({
title: that.$tc('buckaroo-payment.settingsForm.titleSuccess'),
message: that.$tc(response[key].message) + response[key].amount
message: response[key].message
});
} else {
this.createNotificationError({
title: that.$tc('buckaroo-payment.settingsForm.titleError'),
message: that.$tc(response[key].message)
message: response[key].message
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@
"labelTestApi": "Testverbindung"
},
"paymentInTestMode": "The payment for this order was made in test mode",
"refund": {
"not_supported": "Refund is not supported",
"already_refunded": "This order is already refunded",
"refunded_amount": "Buckaroo success refunded"
},
"capture": {
"invalid_amount": "Amount is not valid",
"capture_not_supported": "Capture is not supported",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@
"noTaxes": "No VAT tax"
},
"paymentInTestMode": "The payment for this order was made in test mode",
"refund": {
"not_supported": "Refund is not supported",
"already_refunded": "This order is already refunded",
"refunded_amount": "Buckaroo success refunded"
},
"capture": {
"invalid_amount": "Amount is not valid",
"capture_not_supported": "Capture is not supported",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@
"labelTestApi": "Test verbinding"
},
"paymentInTestMode": "The payment for this order was made in test mode",
"refund": {
"not_supported": "Refund is not supported",
"already_refunded": "This order is already refunded",
"refunded_amount": "Buckaroo success refunded"
},
"capture": {
"invalid_amount": "Amount is not valid",
"capture_not_supported": "Capture is not supported",
Expand Down
Loading
Loading