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

1.2.0 Aplicação de normativas wordpress e correção de renderização #10

Merged
merged 15 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
9765df5
feat: Inclusão das variáveis globais
CaioAndersonMM Aug 12, 2024
8b478f5
fix: Correção na renderização e criação do input com o idUnique
CaioAndersonMM Aug 12, 2024
9167fa2
die: Apagando variáveis não mais utilizadas e deleção do input com id…
CaioAndersonMM Aug 12, 2024
339b9f2
feat: Se o método de pagamento for alterado, voltar para o Mercado Pa…
CaioAndersonMM Aug 13, 2024
6406e86
update: Mudança do nome do fieldset
CaioAndersonMM Aug 13, 2024
aa19890
feat: Adicionado noticia que informa que o plugin não está habilitado…
CaioAndersonMM Aug 13, 2024
89112ae
fix: Fix URL with double https
emanuellopess Aug 14, 2024
266478e
Merge branch 'dev' of https://github.com/LinkNacional/lkn-mercadopago…
emanuellopess Aug 14, 2024
53939ec
feat: Remoção da noticia no formulário legado (quando inicializa o pl…
CaioAndersonMM Aug 15, 2024
4f54eb5
feat: Adicionada tradução para a mensagem do Mercado Pago não habilit…
CaioAndersonMM Aug 15, 2024
a685b30
Merge branch 'dev' of https://github.com/LinkNacional/lkn-mercadopago…
CaioAndersonMM Aug 15, 2024
fa10750
fix: Escape de mensagem e limpeza de código
CaioAndersonMM Aug 15, 2024
16f7189
chore: Atualização da versão, do changelog e do readme
CaioAndersonMM Aug 15, 2024
baa9107
update: Mensagens no console só aparecem conforme ativação do debug a…
CaioAndersonMM Aug 15, 2024
cd58999
update: Modificação na mensagem do Mercado Pago não habilitado para o…
CaioAndersonMM Aug 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: '1.0.1' # // TODO caso necessário definir a tag da release manualmente
custom_tag: '1.2.0' # // TODO caso necessário definir a tag da release manualmente

# Generate new release
- name: Generate new Release
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.2.0 - 15/08/2024
* Renderização do plugin corrigida
* Correção de alteração de método de pagamento
* Normativas WordPress aplicadas
* Notícia de inabilidade do plugin no formulário clássico e multistep

# 1.0.1 - 05/08/2024
* Mensagem adicionada ao inserir o token do Mercado Pago;
* Namespace do plugin atualizado;
Expand Down
2 changes: 1 addition & 1 deletion Includes/LknmpMercadoPagoForGiveWPHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final public static function dependency_notice(): void {
esc_html('para o plugin Mercado Pago para GiveWP ativar')
);

echo $message;
echo wp_kses_post($message);
}

/**
Expand Down
348 changes: 176 additions & 172 deletions Public/LknmpMercadoPagoForGiveWPGateway.php
Original file line number Diff line number Diff line change
@@ -1,173 +1,177 @@
<?php

namespace Lknmp\MercadoPagoForGiveWp\PublicView;

use Give\Donations\Models\Donation;
use Give\Donations\Models\DonationNote;
use Give\Donations\ValueObjects\DonationStatus;
use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\PaymentGateways\Commands\GatewayCommand;
use Give\Framework\PaymentGateways\Commands\PaymentPending;
use Give\Framework\PaymentGateways\Commands\PaymentRefunded;
use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException;
use Give\Framework\PaymentGateways\PaymentGateway;
use Lknmp\MercadoPagoForGiveWp\Includes\LknmpMercadoPagoForGiveWPHelper;

/**
* @inheritDoc
*/
final class LknmpMercadoPagoForGiveWPGateway extends PaymentGateway {
public $idUnique;

public function __construct() {
$this->idUnique = uniqid();
}

/**
* @inheritDoc
*/
public static function id(): string {
return 'lnk-mercadopago-forgivewp';
}

/**
* @inheritDoc
*/
public function getId(): string {
return self::id();
}

/**
* @inheritDoc
*/
public function getName(): string {
return 'Mercado Pago';
}

/**
* @inheritDoc
*/
public function getPaymentMethodLabel(): string {
return 'Mercado Pago';
}

/**
* @inheritDoc
*/
public function getLegacyFormFieldMarkup(int $formId, array $args): string {
// Step 1: add any gateway fields to the form using html. In order to retrieve this data later the name of the input must be inside the key gatewayData (name='gatewayData[input_name]').
// Step 2: you can alternatively send this data to the $gatewayData param using the filter `givewp_create_payment_gateway_data_{gatewayId}`.

$url_pagina = site_url();
$configs = LknmpMercadoPagoForGiveWPHelper::get_configs();
$MenssageErrorNameEmpty = __('The Name field is empty. Please fill in this field before proceeding.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorName = __('The Name field must be at least 3 letters.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorEmailEmpty = __('The Email field is empty. Please fill in this field before proceeding.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorEmailInvalid = __('The Email field is invalid. Please enter a valid email address.', 'lknmp-mercadopago-for-givewp');

if (empty($configs['token']) && strlen($configs['token']) <= 5) {
Give()->notices->print_frontend_notice(
sprintf(
'%1$s %2$s',
esc_html__('Erro:', 'give'),
esc_html__('Mercado Pago Token was not provided or is invalid!', 'give')
)
);
} elseif (empty($configs['key']) && strlen($configs['token']) <= 5) {
Give()->notices->print_frontend_notice(
sprintf(
'%1$s %2$s',
esc_html__('Erro:', 'give'),
esc_html__('Mercado Pago Public Key was not provided or is invalid!', 'give')
)
);
}

$html = "
<fieldset class=\"no-fields\">
<h3 id=\"warning-text\"></h3>
<div id=\"wallet_container\"></div>
<input type=\"hidden\" name=\"gatewayData[gatewayId]\" value=\"$this->idUnique\"></input>
</fieldset>";

return $html;
}

/**
* @inheritDoc
*/
public function createPayment(Donation $donation, $gatewayData): GatewayCommand {
try {
$idTeste = $gatewayData['gatewayId'];
add_option("lkn_mercadopago_" . $idTeste, $donation->id);

return new PaymentPending();
} catch (Exception $e) {
$errorMessage = $e->getMessage();

$donation->status = DonationStatus::FAILED();
$donation->save();

DonationNote::create(array(
'donationId' => $donation->id,
'content' => esc_html('Falha na doação. Razão: ' . $errorMessage) // Translators: %s é um espaço reservado para a mensagem de erro
));

throw new PaymentGatewayException(esc_html($errorMessage));
}
}

/**
* @inerhitDoc
*/
public function refundDonation(Donation $donation): PaymentRefunded {
// Step 1: refund the donation with your gateway.
// Step 2: return a command to complete the refund.
return new PaymentRefunded();
}

/**
* // TO DO needs this function to appear in v3 forms
* @since 3.0.0
*/
public function enqueueScript(int $formId): void {
$configs = LknmpMercadoPagoForGiveWPHelper::get_configs();
$url_pagina = site_url();

$MenssageErrorNameEmpty = __('The Name field is empty. Please fill in this field before proceeding.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorName = __('The Name field must be at least 3 letters.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorEmailEmpty = __('The Email field is empty. Please fill in this field before proceeding.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorEmailInvalid = __('The Email field is invalid. Please enter a valid email address.', 'lknmp-mercadopago-for-givewp');
$MenssageDonation = __('Donation of ', 'lknmp-mercadopago-for-givewp');
$MenssageErrorToken = __('Mercado Pago Token was not provided or is invalid!');
$MenssageErrorPublicKey = __('Mercado Pago Public Key was not provided or is invalid!');

$hastoken = ! empty($configs['token']) && strlen($configs['token']) > 10 ? 'true' : 'false';
$haspublicKey = ! empty($configs['key']) && strlen($configs['key']) > 10 ? 'true' : 'false';

wp_enqueue_script( self::id(), plugin_dir_url( __FILE__ ) . 'js/plugin-script.js', array('jquery', self::id() . 'MercadoPago'), LKNMP_MERCADOPAGO_FOR_GIVEWP_VERSION, true );
wp_enqueue_script( self::id() . 'MercadoPago', plugin_dir_url( __FILE__ ) . 'js/MercadoPago.js', array(), LKNMP_MERCADOPAGO_FOR_GIVEWP_VERSION, false);

wp_localize_script(self::id(), 'urlPag', $url_pagina);
wp_localize_script(self::id(), 'idUnique', uniqid());
wp_localize_script(self::id(), 'configData', array(
'advDebug' => $configs['advDebug'],
'key' => $configs['key'],
'tittle' => $configs['tittle'],
'description' => $configs['description'],
'token' => $configs['token']
));

wp_localize_script(self::id(), 'lknMercadoPagoGlobals', array(
'MenssageErrorNameEmpty' => $MenssageErrorNameEmpty,
'MenssageErrorName' => $MenssageErrorName,
'MenssageErrorEmailEmpty' => $MenssageErrorEmailEmpty,
'MenssageErrorEmailInvalid' => $MenssageErrorEmailInvalid,
'MenssageDonation' => $MenssageDonation,
'MenssageErrorToken' => $MenssageErrorToken,
'MenssageErrorPublicKey' => $MenssageErrorPublicKey,
'token' => $hastoken,
'publicKey' => $haspublicKey
));
}
<?php

namespace Lknmp\MercadoPagoForGiveWp\PublicView;

use Give\Donations\Models\Donation;
use Give\Donations\Models\DonationNote;
use Give\Donations\ValueObjects\DonationStatus;
use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\PaymentGateways\Commands\GatewayCommand;
use Give\Framework\PaymentGateways\Commands\PaymentPending;
use Give\Framework\PaymentGateways\Commands\PaymentRefunded;
use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException;
use Give\Framework\PaymentGateways\PaymentGateway;
use Give_DB_Form_Meta;
use Lknmp\MercadoPagoForGiveWp\Includes\LknmpMercadoPagoForGiveWPHelper;

/**
* @inheritDoc
*/
final class LknmpMercadoPagoForGiveWPGateway extends PaymentGateway {
/**
* @inheritDoc
*/
public static function id(): string {
return 'lnk-mercadopago-forgivewp';
}

/**
* @inheritDoc
*/
public function getId(): string {
return self::id();
}

/**
* @inheritDoc
*/
public function getName(): string {
return 'Mercado Pago';
}

/**
* @inheritDoc
*/
public function getPaymentMethodLabel(): string {
return 'Mercado Pago';
}

/**
* @inheritDoc
*/
public function getLegacyFormFieldMarkup(int $formId, array $args): string {
// Step 1: add any gateway fields to the form using html. In order to retrieve this data later the name of the input must be inside the key gatewayData (name='gatewayData[input_name]').
// Step 2: you can alternatively send this data to the $gatewayData param using the filter `givewp_create_payment_gateway_data_{gatewayId}`.
$formTb = new Give_DB_Form_Meta();
$formTb->table_name = "wp_give_formmeta";
$resultForm = $formTb->get_results_by(array('form_id' => $formId, 'meta_key' => '_give_form_template'));

if ('legacy' != $resultForm[0]->meta_value) {
$html = '
<div class="donation-errors">
<div class="give-notice give-notice-error" id="give_error_warning">
<p class="give_notice give_warning">
<strong>' . esc_html__('Notice:', 'give') . '</strong>
' . esc_html__('Mercado Pago is not enabled for the classic and multistep form!', 'give') . '</p>
</div>
</div>';
return $html;
}

$configs = LknmpMercadoPagoForGiveWPHelper::get_configs();

if (empty($configs['token']) && strlen($configs['token']) <= 5) {
Give()->notices->print_frontend_notice(
sprintf(
'%1$s %2$s',
esc_html__('Erro:', 'give'),
esc_html__('Mercado Pago Token was not provided or is invalid!', 'give')
)
);
} elseif (empty($configs['key']) && strlen($configs['token']) <= 5) {
Give()->notices->print_frontend_notice(
sprintf(
'%1$s %2$s',
esc_html__('Erro:', 'give'),
esc_html__('Mercado Pago Public Key was not provided or is invalid!', 'give')
)
);
}

$html = "
<fieldset class=\"no-fields-lknmp\">
<h3 id=\"warning-text\"></h3>
<div id=\"wallet_container\"></div>
</fieldset>";

return $html;
}

/**
* @inheritDoc
*/
public function createPayment(Donation $donation, $gatewayData): GatewayCommand {
try {
$idTeste = $gatewayData['gatewayId'];
add_option("lkn_mercadopago_" . $idTeste, $donation->id);

return new PaymentPending();
} catch (Exception $e) {
$errorMessage = $e->getMessage();

$donation->status = DonationStatus::FAILED();
$donation->save();

DonationNote::create(array(
'donationId' => $donation->id,
'content' => esc_html('Falha na doação. Razão: ' . $errorMessage) // Translators: %s é um espaço reservado para a mensagem de erro
));

throw new PaymentGatewayException(esc_html($errorMessage));
}
}

/**
* @inerhitDoc
*/
public function refundDonation(Donation $donation): PaymentRefunded {
// Step 1: refund the donation with your gateway.
// Step 2: return a command to complete the refund.
return new PaymentRefunded();
}

/**
* // TO DO needs this function to appear in v3 forms
* @since 3.0.0
*/
public function enqueueScript(int $formId): void {
$configs = LknmpMercadoPagoForGiveWPHelper::get_configs();
$url_pagina = site_url();

$MenssageErrorNameEmpty = __('The Name field is empty. Please fill in this field before proceeding.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorName = __('The Name field must be at least 3 letters.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorEmailEmpty = __('The Email field is empty. Please fill in this field before proceeding.', 'lknmp-mercadopago-for-givewp');
$MenssageErrorEmailInvalid = __('The Email field is invalid. Please enter a valid email address.', 'lknmp-mercadopago-for-givewp');
$MenssageDonation = __('Donation of ', 'lknmp-mercadopago-for-givewp');
$MenssageErrorToken = __('Mercado Pago Token was not provided or is invalid!');
$MenssageErrorPublicKey = __('Mercado Pago Public Key was not provided or is invalid!');

$hastoken = ! empty($configs['token']) && strlen($configs['token']) > 10 ? 'true' : 'false';
$haspublicKey = ! empty($configs['key']) && strlen($configs['key']) > 10 ? 'true' : 'false';

wp_enqueue_script( self::id(), plugin_dir_url( __FILE__ ) . 'js/plugin-script.js', array('jquery', self::id() . 'MercadoPago'), LKNMP_MERCADOPAGO_FOR_GIVEWP_VERSION, true );
wp_enqueue_script( self::id() . 'MercadoPago', plugin_dir_url( __FILE__ ) . 'js/MercadoPago.js', array(), LKNMP_MERCADOPAGO_FOR_GIVEWP_VERSION, false);

wp_localize_script(self::id(), 'urlPag', $url_pagina);
wp_localize_script(self::id(), 'idUnique', uniqid());
wp_localize_script(self::id(), 'configData', array(
'advDebug' => $configs['advDebug'],
'key' => $configs['key'],
'tittle' => $configs['tittle'],
'description' => $configs['description'],
'token' => $configs['token']
));

wp_localize_script(self::id(), 'lknMercadoPagoGlobals', array(
'MenssageErrorNameEmpty' => $MenssageErrorNameEmpty,
'MenssageErrorName' => $MenssageErrorName,
'MenssageErrorEmailEmpty' => $MenssageErrorEmailEmpty,
'MenssageErrorEmailInvalid' => $MenssageErrorEmailInvalid,
'MenssageDonation' => $MenssageDonation,
'MenssageErrorToken' => $MenssageErrorToken,
'MenssageErrorPublicKey' => $MenssageErrorPublicKey,
'token' => $hastoken,
'publicKey' => $haspublicKey
));
}
}
Loading
Loading