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 3295 add the option to display giftcards inline #167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
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
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
171 changes: 92 additions & 79 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,53 +50,41 @@ 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;
}

$this->payment = $this->setPostVariable('brq_payment');
if (Tools::getValue('brq_payment_method')) {
$this->payment_method = $this->getPaymentCode(Tools::getValue('brq_payment_method'));
} elseif (Tools::getValue('brq_transaction_method')) {
$this->payment_method = $this->getPaymentCode(Tools::getValue('brq_transaction_method'));
}

$this->payment_method = $this->getPaymentCode($this->setPostVariable('brq_payment_method') ?? $this->setPostVariable('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 +94,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 +191,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 +269,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 +281,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'];
}

}
1 change: 1 addition & 0 deletions buckaroo3.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public function hookPaymentOptions($params)
'methodsWithFinancialWarning' => $buckarooPaymentService->paymentMethodsWithFinancialWarning(),
'creditcardIssuers' => $buckarooConfigService->getActiveCreditCards(),
'creditCardDisplayMode' => $buckarooConfigService->getConfigValue('creditcard', 'display_type'),
'giftCardDisplayMode' => $buckarooConfigService->getConfigValue('giftcard', 'display_in_checkout'),
'in3Method' => $this->get('buckaroo.classes.issuers.capayableIn3')->getMethod(),
'showIdealIssuers' => $buckarooConfigService->getConfigValue('ideal', 'show_issuers') ?? true,
'buckaroo_idin_test' => $buckarooConfigService->getConfigValue('idin', 'mode'),
Expand Down
12 changes: 12 additions & 0 deletions controllers/front/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

class BuckarooCommonController extends ModuleFrontController
{
public function __construct()
{
parent::__construct();
}
private $id_order;

protected function displayConfirmationTransfer($response)
Expand Down Expand Up @@ -86,4 +90,12 @@ protected function displayError($invoicenumber = null, $error_message = null)

$this->setTemplate('module:buckaroo3/views/templates/front/error.tpl');
}

/**
* Method to initialize content, should be overridden in child classes
*/
public function initContent()
{
parent::initContent();
}
}
Loading
Loading