Skip to content

Commit

Permalink
Fix: Adição do botao gerar link de pagamento, alteração no texto de l…
Browse files Browse the repository at this point in the history
…ink de pagamento para ver link de pagamento, botão na coluna link de pagamento agora é edit pedido, css no padding do botao link de pagamento
  • Loading branch information
lucastgama committed Aug 15, 2024
1 parent ec2a989 commit ea18edc
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/assets/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,16 @@ jQuery(document).ready(function ($) {
}
});

const url = new URLSearchParams(location.href);
if (url.has("vindi-payment-link")) {
const addresses = document.querySelectorAll(".edit_address");

addresses.forEach((address) => {
address.style.display = "block";
});

if (url.has("gateway")) {
this.updateLinkGateway(url.get("gateway"));
}
}
});
25 changes: 12 additions & 13 deletions src/assets/js/editpost.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
jQuery(document).ready(function ($) {
const copyLinkPostEditButtons = document.querySelectorAll('.btnCopyPostLink');
copyLinkPostEditButtons.forEach(button => {
button.addEventListener('click', function (e) {
e.preventDefault();
const link = e.currentTarget.href;
const tempInput = document.createElement('input');
tempInput.value = link;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
});
});
let url = window.location.href;
let side = document.querySelector(".page-title-action");
if (side && (url.includes("post_type=shop_order") || url.includes("action=edit"))) {
let button = document.createElement('a');
button.className = 'button button-primary';
button.style.marginLeft = '10px';
button.style.marginTop = '10px';
button.setAttribute("target", "_blank");
button.innerText = "Gerar Link de Pagamento";
button.setAttribute("href", `${location.origin}/wp-admin/post-new.php?post_type=shop_order&vindi-payment-link=true`);
side.after(button);
}
})
1 change: 1 addition & 0 deletions src/assets/js/notification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jQuery(document).ready(function ($) {
'use strict';

if (orderData.hasSubscription) {
const newTextOrder = document.querySelector('.wc-order-data-row');
newTextOrder.append('O valor final pode variar com base nas condições da assinatura.');
Expand Down
6 changes: 2 additions & 4 deletions src/includes/admin/WcVindiColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ private function include_template_with_variables($template_path, $variables)
*/
public function build_payment_link($order, $gateway)
{
$url = wc_get_checkout_url();
$url = get_site_url();
$gateway = $gateway ? "&vindi-gateway={$gateway}" : '';
$orderId = $order->get_id();
$orderKey = $order->get_order_key();

return "{$url}order-pay/{$orderId}/?pay_for_order=true&key={$orderKey}&vindi-payment-link=true{$gateway}";
return "{$url}/wp-admin/post.php?post={$orderId}&action=edit&vindi-payment-link=true";
}

public function has_subscription($order)
Expand Down
22 changes: 22 additions & 0 deletions src/includes/checkout/WCSOrderSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class OrderSetup
public function __construct()
{
add_action('template_redirect', [$this, 'set_payment_gateway']);
add_filter('woocommerce_payment_gateways', [$this, 'restrict_payment_gateways_for_vindi_payment_link']);

}
public function set_payment_gateway()
{
Expand All @@ -21,4 +23,24 @@ public function set_payment_gateway()
WC()->session->set('vindi-gateway', $gateway);
}
}

public function restrict_payment_gateways_for_vindi_payment_link($available_gateways)
{
if (is_admin() && isset($_GET['vindi-payment-link'])) {
$allowed_gateways = [
'vindi-bank-slip',
'vindi-bolepix',
'vindi-credit-card',
'vindi-pix',
];

foreach ($available_gateways as $gateway_id => $gateway) {
if (!in_array($gateway_id, $allowed_gateways)) {
unset($available_gateways[$gateway_id]);
}
}
}

return $available_gateways;
}
}
6 changes: 3 additions & 3 deletions src/templates/admin-payment-button.html.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php if (in_array($status, ['pending', 'auto-draft'])) : ?>
<?php if ($type == 'shop_order') : ?>
<div style="display: flex;gap: 6px; width: 100%;margin-top: 6px;">
<div style="display:flex;gap:6px;width:100%;margin-top:6px;padding-top:10px;">
<?php
$is_disabled = ($disable) ? 'disabled' : 'enable';
?>
Expand All @@ -10,7 +10,7 @@
<img style="width: 15px;"
src="<?php echo plugin_dir_url(dirname(__FILE__)) . 'assets/images/logo-white.svg'; ?>"
alt="Logo Vindi">
<span><?php echo esc_html__('Link de pagamento', 'vindi-payment-gateway'); ?></span>
<span><?php echo esc_html__('Ver link de pagamento', 'vindi-payment-gateway'); ?></span>
</a>
<a class="buttonCopy" id="buttonCopyPost">
<img style="width: 15px;"
Expand Down Expand Up @@ -51,7 +51,7 @@
<img style="width: 15px;"
src="<?php echo plugin_dir_url(dirname(__FILE__)) . 'assets/images/logo-white.svg'; ?>"
alt="Logo Vindi">
<span><?php echo esc_html__('Link de pagamento', 'vindi-payment-gateway'); ?></span>
<span><?php echo esc_html__('Ver link de pagamento', 'vindi-payment-gateway'); ?></span>
</a>
<a class="buttonCopy" id="buttonCopyPost">
<img style="width: 15px;"
Expand Down
4 changes: 2 additions & 2 deletions src/templates/admin-payment-link-button-column.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
target="_blank">
<img style="width: 15px;"
src="<?php echo plugin_dir_url(dirname(__FILE__)) . 'assets/images/logo-white.svg'; ?>"
alt="Copy icon">
<span><?php echo esc_html__('Copiar Link', 'vindi-payment-gateway'); ?></span>
alt="Logo Vindi">
<span><?php echo esc_html__('Link de Pagamento', 'vindi-payment-gateway'); ?></span>
</a>
<?php endif; ?>
<?php endif; ?>

0 comments on commit ea18edc

Please sign in to comment.