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

Update into v4.2.1 #169

Merged
merged 138 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
74f9ce6
Update countries to retrieve their names from the database based on t…
vegimcarkaxhija Mar 27, 2024
e09f74d
Merge pull request #158 from buckaroo-it/BP-3520-PrestaShop-language-…
vegimcarkaxhija Mar 28, 2024
a6d6a42
BP-3512 Remove logo selection for In3 & iDEAL In3 (#157)
harli91 Mar 28, 2024
bff573d
BP-3503 Remove payment method: Tinka
Mar 29, 2024
6962d62
BP-3295-Add-the-option-to-display-giftcards-inline
AlbinaBaraliu Apr 8, 2024
1087121
BP-3295-Add-the-option-to-display-giftcards-inline
AlbinaBaraliu Apr 11, 2024
771a4b9
only display buckaroo refund table when its buckaroo order
vegimcarkaxhija Apr 12, 2024
c15c22f
remove tinka tpl
vegimcarkaxhija Apr 12, 2024
431e623
change Buckaroo fee to Payment fee
vegimcarkaxhija Apr 12, 2024
db4d531
Merge pull request #160 from buckaroo-it/BP-3503-remove-payment-metho…
vegimcarkaxhija Apr 12, 2024
d82518a
change Buckaroo fee to Payment fee
vegimcarkaxhija Apr 12, 2024
877124a
Merge branch 'develop' into BP-3295-Add-the-option-to-display-giftcar…
AlbinaBaraliu Apr 15, 2024
710d9fb
BP-3295-Add-the-option-to-display-giftcards-inline
AlbinaBaraliu Apr 15, 2024
5885020
Merge pull request #159 from buckaroo-it/BP-3295-Add-the-option-to-di…
AlbinaBaraliu Apr 15, 2024
31f19b4
update
vegimcarkaxhija Apr 22, 2024
7601ef4
fix isOrderBackOrder function
vegimcarkaxhija May 16, 2024
d133577
Merge pull request #162 from buckaroo-it/BP-3509-Status-changed-from-…
vegimcarkaxhija May 16, 2024
eb8cb74
Merge branch 'refs/heads/develop' into BP-3482-Fix-Payment-fee-not-vi…
vegimcarkaxhija May 16, 2024
a635e5d
fix
vegimcarkaxhija May 16, 2024
797c4e1
Merge branch 'refs/heads/develop' into BP-3482-Fix-Payment-fee-not-vi…
vegimcarkaxhija May 16, 2024
4b43018
update fee table, add fee settings
vegimcarkaxhija May 21, 2024
073316d
update
vegimcarkaxhija May 21, 2024
0195a64
update use getfee function
vegimcarkaxhija May 21, 2024
bc1e9e2
fix
vegimcarkaxhija May 21, 2024
de51e9d
fix
vegimcarkaxhija May 21, 2024
8e4b209
fix
vegimcarkaxhija May 21, 2024
872cb6e
fix
vegimcarkaxhija May 22, 2024
cfc3239
fix
vegimcarkaxhija May 22, 2024
192fc39
fix
vegimcarkaxhija May 22, 2024
4ad9765
fix
vegimcarkaxhija May 22, 2024
a6d4519
fix
vegimcarkaxhija May 22, 2024
9ea697f
fix
vegimcarkaxhija May 22, 2024
2216b0b
refactor all parts where fee is used
vegimcarkaxhija May 24, 2024
63daaef
refactor all parts where fee is used
vegimcarkaxhija May 24, 2024
6359684
add payment fee table
vegimcarkaxhija May 24, 2024
058854d
add payment fee table
vegimcarkaxhija May 24, 2024
36031c5
fix
vegimcarkaxhija May 24, 2024
76dcbe5
switch back to 4.2.0
vegimcarkaxhija May 24, 2024
893d9b5
add payment fee description
vegimcarkaxhija May 24, 2024
ea8e6fa
remove tab space
vegimcarkaxhija May 27, 2024
5f31b8d
remove tab space
vegimcarkaxhija May 27, 2024
a461497
Merge pull request #163 from buckaroo-it/BP-3482-Fix-Payment-fee-not-…
vegimcarkaxhija Jun 11, 2024
8293c9f
update version
vegimcarkaxhija Jun 12, 2024
ed41b2f
fix upgrade file
vegimcarkaxhija Jun 12, 2024
d3c8ed5
fix upgrade file
vegimcarkaxhija Jun 12, 2024
2472cbd
change round function into toPrecision
vegimcarkaxhija Jun 18, 2024
ce5f8e6
fix float to Decimal
vegimcarkaxhija Jun 18, 2024
09d31c1
fix float to Decimal
vegimcarkaxhija Jun 18, 2024
109fdf1
Merge pull request #164 from buckaroo-it/BP-3618-Billink-displays-an-…
vegimcarkaxhija Jun 18, 2024
a1034a5
Ensure that $buckarooFeeData is an array
vegimcarkaxhija Jun 18, 2024
66d7037
Merge pull request #165 from buckaroo-it/BP-3621-Refund-not-working-w…
vegimcarkaxhija Jun 18, 2024
10892e0
Merge branch 'refs/heads/develop' into BP-3481-Update-test-release-v4…
vegimcarkaxhija Jun 18, 2024
a7a6385
update
vegimcarkaxhija Jun 18, 2024
348eab7
update
vegimcarkaxhija Jun 18, 2024
62abf81
update
vegimcarkaxhija Jun 18, 2024
837032a
update
vegimcarkaxhija Jun 18, 2024
1e34b28
update
vegimcarkaxhija Jun 18, 2024
53a0b1f
update
vegimcarkaxhija Jun 18, 2024
7d79cef
update
vegimcarkaxhija Jun 18, 2024
0db62cd
update
vegimcarkaxhija Jun 18, 2024
d167d7b
update
vegimcarkaxhija Jun 18, 2024
f396a51
update
vegimcarkaxhija Jun 18, 2024
2ae3eed
update
vegimcarkaxhija Jun 18, 2024
2817c65
update
vegimcarkaxhija Jun 18, 2024
3a84e80
update
vegimcarkaxhija Jun 18, 2024
8854b0b
update
vegimcarkaxhija Jun 18, 2024
0ad62b3
update
vegimcarkaxhija Jun 18, 2024
ed03b52
update
vegimcarkaxhija Jun 18, 2024
91eb362
Merge pull request #166 from buckaroo-it/BP-3295-Add-the-option-to-di…
vegimcarkaxhija Jun 18, 2024
c872bcc
update
vegimcarkaxhija Jun 18, 2024
ecdec50
update
vegimcarkaxhija Jun 18, 2024
8c193ac
update
vegimcarkaxhija Jun 18, 2024
eeb451a
update
vegimcarkaxhija Jun 18, 2024
9d1803f
update
vegimcarkaxhija Jun 18, 2024
005cbe3
update
vegimcarkaxhija Jun 18, 2024
509a048
update
vegimcarkaxhija Jun 18, 2024
c342c03
update
vegimcarkaxhija Jun 18, 2024
3d62033
update
vegimcarkaxhija Jun 18, 2024
15c022a
update
vegimcarkaxhija Jun 18, 2024
5f1a4ae
update
vegimcarkaxhija Jun 18, 2024
818082b
update request.php
vegimcarkaxhija Jun 19, 2024
b5efa6d
update request.php
vegimcarkaxhija Jun 19, 2024
9a1f605
update
vegimcarkaxhija Jun 19, 2024
8b2e66b
update
vegimcarkaxhija Jun 19, 2024
af813d1
update
vegimcarkaxhija Jun 19, 2024
c019a72
update
vegimcarkaxhija Jun 19, 2024
f3932a8
update
vegimcarkaxhija Jun 19, 2024
f92b028
update
vegimcarkaxhija Jun 19, 2024
e748b31
update
vegimcarkaxhija Jun 19, 2024
bc203ff
update
vegimcarkaxhija Jun 19, 2024
13047e5
update
vegimcarkaxhija Jun 19, 2024
7447e40
update
vegimcarkaxhija Jun 19, 2024
c5af476
update
vegimcarkaxhija Jun 19, 2024
ffe3297
update
vegimcarkaxhija Jun 19, 2024
234f43b
update
vegimcarkaxhija Jun 19, 2024
3a06695
update
vegimcarkaxhija Jun 19, 2024
02182f9
update
vegimcarkaxhija Jun 19, 2024
f5f25de
update
vegimcarkaxhija Jun 19, 2024
d8bac8a
update
vegimcarkaxhija Jun 19, 2024
e6aa9f5
update
vegimcarkaxhija Jun 19, 2024
b816d97
update
vegimcarkaxhija Jun 19, 2024
4f3a418
update
vegimcarkaxhija Jun 19, 2024
07bcce3
update
vegimcarkaxhija Jun 19, 2024
2b7e0ad
update
vegimcarkaxhija Jun 19, 2024
74c7946
update
vegimcarkaxhija Jun 19, 2024
12d151a
update
vegimcarkaxhija Jun 19, 2024
5b98bf2
update
vegimcarkaxhija Jun 19, 2024
53692f1
update
vegimcarkaxhija Jun 19, 2024
d4357a2
update
vegimcarkaxhija Jun 19, 2024
0f59ca1
update
vegimcarkaxhija Jun 19, 2024
59e7860
update
vegimcarkaxhija Jun 19, 2024
4ba0aa9
update
vegimcarkaxhija Jun 19, 2024
137b327
update
vegimcarkaxhija Jun 19, 2024
81b48b8
update
vegimcarkaxhija Jun 19, 2024
6ade3f1
update
vegimcarkaxhija Jun 19, 2024
6946901
update
vegimcarkaxhija Jun 19, 2024
1563a9a
update
vegimcarkaxhija Jun 19, 2024
d0aec96
update
vegimcarkaxhija Jun 19, 2024
212ccc2
update
vegimcarkaxhija Jun 20, 2024
b5cb912
update
vegimcarkaxhija Jun 20, 2024
5e1881a
update
vegimcarkaxhija Jun 20, 2024
7ce7d01
update
vegimcarkaxhija Jun 20, 2024
2d7f597
update
vegimcarkaxhija Jun 20, 2024
9dc5c8e
update
vegimcarkaxhija Jun 20, 2024
488e5a2
update
vegimcarkaxhija Jun 20, 2024
687ddfb
update
vegimcarkaxhija Jun 20, 2024
c6fc448
update
vegimcarkaxhija Jun 20, 2024
50364c6
update
vegimcarkaxhija Jun 20, 2024
5992028
update
vegimcarkaxhija Jun 20, 2024
e7f6661
update
vegimcarkaxhija Jun 20, 2024
1a2945f
update
vegimcarkaxhija Jun 20, 2024
9dd779b
Merge pull request #167 from buckaroo-it/BP-3295-Add-the-option-to-di…
vegimcarkaxhija Jun 20, 2024
33a2027
fix
vegimcarkaxhija Jun 20, 2024
daaf84c
Merge branch 'refs/heads/develop' into BP-3481-Update-test-release-v4…
vegimcarkaxhija Jun 20, 2024
8f9fc7d
fix
vegimcarkaxhija Jun 20, 2024
31a5a62
fix
vegimcarkaxhija Jun 20, 2024
a0f9fea
fix
vegimcarkaxhija Jun 20, 2024
f895bfd
Merge pull request #168 from buckaroo-it/BP-3481-Update-test-release-…
vegimcarkaxhija Jun 20, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ composer.lock
var
tools
dev/node_modules
dev/package-lock.json
.idea
2 changes: 0 additions & 2 deletions api/paymentmethods/paymentrequestfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class PaymentRequestFactory
public const REQUEST_TYPE_PAYCONIQ = 'payconiq';
public const REQUEST_TYPE_PAYPEREMAIL = 'payperemail';
public const REQUEST_TYPE_PRZELEWY24 = 'przelewy24';
public const REQUEST_TYPE_TINKA = 'tinka';
public const REQUEST_TYPE_TRUSTLY = 'trustly';
public const REQUEST_TYPE_WECHATPAY = 'wechatpay';
public const REQUEST_TYPE_ALIPAY = 'alipay';
Expand Down Expand Up @@ -77,7 +76,6 @@ class PaymentRequestFactory
PaymentRequestFactory::REQUEST_TYPE_PAYCONIQ => 'Payconiq',
PaymentRequestFactory::REQUEST_TYPE_PAYPEREMAIL => 'PayPerEmail',
PaymentRequestFactory::REQUEST_TYPE_PRZELEWY24 => 'Przelewy24',
PaymentRequestFactory::REQUEST_TYPE_TINKA => 'Tinka',
PaymentRequestFactory::REQUEST_TYPE_TRUSTLY => 'Trustly',
PaymentRequestFactory::REQUEST_TYPE_WECHATPAY => 'Wechatpay',
PaymentRequestFactory::REQUEST_TYPE_ALIPAY => 'Alipay',
Expand Down
165 changes: 91 additions & 74 deletions api/paymentmethods/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require_once dirname(__FILE__) . '/../../library/logger.php';
require_once dirname(__FILE__) . '/../abstract.php';
require_once _PS_ROOT_DIR_ . '/modules/buckaroo3/vendor/autoload.php';

use Buckaroo\BuckarooClient;
use Buckaroo\Handlers\Reply\ReplyHandler;
use Buckaroo\Transaction\Response\TransactionResponse;
Expand All @@ -27,15 +28,11 @@

abstract class Response extends BuckarooAbstract
{
// false if not received response
private $received = false;
// true if validated and securety checked
private $validated = false;
// request is test?
private $test = true;
private $signature;
private $isPush;
// payment key
public $payment;
public $payment_method;
public $statuscode;
Expand All @@ -53,43 +50,36 @@ abstract class Response extends BuckarooAbstract
public $brq_transaction_type;
public $brq_relatedtransaction_partialpayment;
public $brq_relatedtransaction_refund;
// transaction key
public $transactions;
// if is errors, othervise = null
public $parameterError;

protected ?TransactionResponse $response = null;
protected $logger;

public function __construct(TransactionResponse $response = null)
{
$this->logger = new Logger(Logger::INFO, 'response');
$this->logger->logInfo("\n\n\n\n***************** Response start ***********************");

if ($response) {
$this->response = $response;
$this->logger->logInfo('Response object provided directly');
} else {
$this->isPush = $this->isPushRequest();
$this->received = true;
$this->logger->logInfo('Response determined to be a push request');
$this->parsePushRequest();
}
}

/**
* Get code required for payment
*
* @param string $configCode
*
* @return string
*/
protected function getPaymentCode(string $configCode): string
{
if ($configCode === 'Capayable') {
return 'in3';
}

return $configCode;
return $configCode === 'Capayable' ? 'in3' : $configCode;
}

private function parsePushRequest()
{
if (!$this->isPushRequest()) {
$this->logger->logInfo('Not a push request');
return false;
}

Expand All @@ -99,7 +89,6 @@ private function parsePushRequest()
} elseif (Tools::getValue('brq_transaction_method')) {
$this->payment_method = $this->getPaymentCode(Tools::getValue('brq_transaction_method'));
}

$this->statuscode = $this->setPostVariable('brq_statuscode');
$this->statusmessage = $this->setPostVariable('brq_statusmessage');
$this->statuscode_detail = $this->setPostVariable('brq_statuscode_detail');
Expand All @@ -109,95 +98,94 @@ private function parsePushRequest()
$this->invoice = $this->setPostVariable('brq_invoicenumber');
$this->invoicenumber = $this->setPostVariable('brq_invoicenumber');
$this->amount = $this->setPostVariable('brq_amount');
if (Tools::getValue('brq_amount_credit')) {
$this->amount_credit = Tools::getValue('brq_amount_credit');
}

$this->amount_credit = $this->setPostVariable('brq_amount_credit');
$this->currency = $this->setPostVariable('brq_currency');
$this->test = $this->setPostVariable('brq_test');
$this->timestamp = $this->setPostVariable('brq_timestamp');
$this->transactions = $this->setPostVariable('brq_transactions');
$this->signature = $this->setPostVariable('brq_signature');

$this->logger->logInfo('Parsed push request', [
'statuscode' => $this->statuscode,
'statusmessage' => $this->statusmessage,
'amount' => $this->amount,
'currency' => $this->currency,
'timestamp' => $this->timestamp
]);

if (!empty($this->statuscode)) {
$responseArray = $this->responseCodes[(int) $this->statuscode];
$responseArray = $this->responseCodes[(int)$this->statuscode];
$this->status = $responseArray['status'];
$this->message = $responseArray['message'];
}
}

/**
* @return bool
*/
public function isSuccess(): bool
{
return $this->response->isSuccess();
}

/**
* @return bool
*/
public function isFailed(): bool
{
return $this->response->isFailed();
}

/**
* @return bool
*/
public function isCanceled(): bool
{
return $this->response->isCanceled();
}

/**
* @return bool
*/
public function isAwaitingConsumer(): bool
{
return $this->response->isAwaitingConsumer();
}

/**
* @return bool
*/
public function isPendingProcessing(): bool
{
return $this->response->isPendingProcessing();
}

/**
* @return bool
*/
public function isWaitingOnUserInput(): bool
{
return $this->response->isWaitingOnUserInput();
}

/**
* @return bool
*/
public function isRejected(): bool
{
return $this->response->isRejected();
}

// Determine if is buckaroo response or push
private function isPushRequest()
private function isPushRequest(): bool
{
if (Tools::getValue('brq_statuscode')) {
return true;
}

return false;
return (bool)Tools::getValue('brq_statuscode');
}

public function getServiceParameters()
{
return $this->response->getServiceParameters();
}

public function hasSomeError()
public function getStatuscode()
{
return $this->response->statuscode;
}

public function getStatusmessage()
{
return $this->response->statusmessage;
}

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

public function getBrqRelatedtransactionPartialpayment()
{
return $this->brq_relatedtransaction_partialpayment;
}

public function hasSomeError(): bool
{
return $this->response->hasSomeError();
}
Expand All @@ -207,71 +195,73 @@ public function getSomeError()
return $this->response->getSomeError();
}

public function isTest()
public function isTest(): bool
{
return $this->response->get('IsTest') === true;
}

public function isValid()
public function isValid(): bool
{
if (!$this->validated) {
if ($this->isPush) {
$buckaroo = new BuckarooClient(Configuration::get('BUCKAROO_MERCHANT_KEY'), Configuration::get('BUCKAROO_SECRET_KEY'));
try {
$reply_handler = new ReplyHandler($buckaroo->client()->config(), $_POST);
$reply_handler->validate();

return $this->validated = $reply_handler->isValid();
$this->validated = $reply_handler->isValid();
$this->logger->logInfo('Push request validated successfully');
} catch (Exception $e) {
$this->logger->logError('Push request validation failed', ['exception' => $e->getMessage()]);
}
} elseif ($this->response) {
$this->validated = (!$this->response->isValidationFailure());
$this->validated = !$this->response->isValidationFailure();
$this->logger->logInfo('Response validation status', ['validated' => $this->validated]);
}
}

return $this->validated;
}

public function hasSucceeded()
public function hasSucceeded(): bool
{
if (isset($this->response)) {
try {
if ($this->isValid()) {
if ($this->isPendingProcessing() || $this->isAwaitingConsumer() || $this->isWaitingOnUserInput() || $this->isSuccess()) {
$this->logger->logInfo('Response has succeeded');
return true;
}
}
} catch (Exception $e) {
$this->logger->logError('Exception while checking success', ['exception' => $e->getMessage()]);
}
} elseif (in_array($this->status, [self::BUCKAROO_PENDING_PAYMENT, self::BUCKAROO_SUCCESS])) {
$this->logger->logInfo('Response status indicates success');
return true;
}

$this->logger->logInfo('Response has not succeeded');
return false;
}

public function isRedirectRequired()
public function isRedirectRequired(): bool
{
return $this->response->hasRedirect();
}

public function getRedirectUrl()
public function getRedirectUrl(): string
{
return $this->response->getRedirectUrl();
}

public function getResponse()
public function getResponse(): ?TransactionResponse
{
return $this->response;
}

private function setPostVariable($key)
{
if (Tools::getValue($key)) {
return Tools::getValue($key);
} else {
return null;
}
return Tools::getValue($key) ?? null;
}

public function getCartIdAndReferenceId($show = false)
Expand All @@ -283,14 +273,10 @@ public function getCartIdAndReferenceId($show = false)
$cartId = 0;
$reference = $this->invoicenumber;
}
if ($show == 'cartId') {
return (int) $cartId;
}

return $reference;
return $show == 'cartId' ? (int)$cartId : $reference;
}

public function getCartId()
public function getCartId(): int
{
return $this->getCartIdAndReferenceId('cartId');
}
Expand All @@ -299,4 +285,35 @@ public function getReferenceId()
{
return $this->getCartIdAndReferenceId('reference');
}

public function isPartialPayment(): bool
{
return !empty($this->getGroupTransaction());
}

public function getRemainingAmount(): float
{
return $this->response->remaining_amount ?? 0;
}

public function getGroupTransaction()
{
$data = $this->response->data();
if (isset($data['RequiredAction']['PayRemainderDetails']['GroupTransaction'])) {
return $data['RequiredAction']['PayRemainderDetails']['GroupTransaction'];
}
return null;
}

public function getRemainderAmount()
{
$data = $this->response->data();
if (!isset($data['RequiredAction']['PayRemainderDetails']['RemainderAmount']) ||
!is_scalar($data['RequiredAction']['PayRemainderDetails']['RemainderAmount'])
) {
return 0;
}
return (float) $data['RequiredAction']['PayRemainderDetails']['RemainderAmount'];
}

}
Loading
Loading