Skip to content

Commit

Permalink
Merge pull request #110 from buckaroo-it/BP-3038-Tinka-displays-an-er…
Browse files Browse the repository at this point in the history
…ror-on-frontend

Transaction description replace order tags
  • Loading branch information
Rinor12010 authored Dec 13, 2023
2 parents 45355ce + 7441540 commit 4917e93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
29 changes: 26 additions & 3 deletions api/paymentmethods/paymentmethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public function payGlobal($customPayAction = null)
{
(!$customPayAction) ? $payAction = 'pay' : $payAction = $customPayAction;

$this->payload = array_merge($this->payload,
[
$this->payload = array_merge([
'currency' => $this->currency,
'amountDebit' => $this->amountDebit,
'invoice' => $this->invoiceId,
'description' => $this->description,
'order' => $this->orderId,
'returnURL' => $this->returnUrl,
'pushURL' => $this->pushUrl,
Expand All @@ -92,7 +92,7 @@ public function payGlobal($customPayAction = null)
'moduleVersion' => $this->moduleVersion,
'moduleSupplier' => $this->moduleSupplier,
'moduleName' => $this->moduleName,
]);
],$this->payload);

$buckaroo = $this->getBuckarooClient(Config::getMode($this->type));
// Pay
Expand Down Expand Up @@ -164,4 +164,27 @@ public function verify($customVars = [])

return ResponseFactory::getResponse($response);
}
public function setDescription(\Order $order){
$description = (string) Configuration::get('BUCKAROO_TRANSACTION_LABEL');
$patterns = ['/{order_number}/','/{shop_name}/'];
$replacement = [$order->reference,\Context::getContext()->shop->name];

$description = preg_replace($patterns, $replacement, $description);
preg_match_all('/{\w+}/',$description,$matches);

if (!empty($matches[0])) {
$patterns = [];
$replacement = [];
foreach ($matches[0] as $match){
$property = trim($match, '{}');
if (isset($order->$property)) {
$replacement[] = $order->$property;
$patterns[] = "/$match/";
}
}
$patterns[] = '/{\w+}/';
$description = preg_replace($patterns, $replacement, $description);
}
$this->description = $description;
}
}
2 changes: 0 additions & 2 deletions controllers/admin/PaymentMethodConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ public function initContent()
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
return $this->handleGet();
break;
case 'POST':
return $this->handlePost();
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/checkout/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ protected function setCheckout()
if ($buckarooFee > 0) {
$this->updateOrderFee($buckarooFee);
}

$order = Order::getByCartId($this->cart->id);
$this->payment_request->setDescription($order);
$this->payment_request->currency = $currency->iso_code;
$this->payment_request->description = Configuration::get('BUCKAROO_TRANSACTION_LABEL');
$reference = $this->reference . '_' . $this->cart->id;
$this->payment_request->invoiceId = $reference;
$this->payment_request->orderId = $reference;
Expand Down
3 changes: 1 addition & 2 deletions library/checkout/tinkacheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ final public function setCheckout()
{
parent::setCheckout();
$this->customVars = [
'description' => 'This is a test order',
'paymentMethod' => 'Credit',
'deliveryMethod' => 'Locker',
'deliveryMethod' => $this->cart->id_carrier === 1 ? 'CompanyStore' : 'ShippingPartner',
'deliveryDate' => date('Y-m-d'),
'articles' => $this->getArticles(),
'customer' => $this->getCustomer(),
Expand Down

0 comments on commit 4917e93

Please sign in to comment.