Skip to content

Commit

Permalink
Merge pull request #20 from LinkNacional/dev
Browse files Browse the repository at this point in the history
1.2.4 Correção em url de redirecionamento
  • Loading branch information
emanuellopess authored Nov 26, 2024
2 parents 100de33 + 7f0e73a commit 2173ad8
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 93 deletions.
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.2.3' # // TODO caso necessário definir a tag da release manualmente
custom_tag: '1.2.4' # // TODO caso necessário definir a tag da release manualmente

# Generate new release
- name: Generate new Release
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.devcontainer/devcontainer.json
.vscode/settings.json
vendor
.devcontainer/devcontainer.json
node_modules
Includes/logs/*.log
.vscode/functions
17 changes: 17 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"recommendations": [
"natizyskunk.sftp",
"wakatime.vscode-wakatime",
"mehedidracula.php-namespace-resolver",
"eamodio.gitlens",
"vivaxy.vscode-conventional-commits",
"ms-vscode-remote.remote-containers",
"yzhang.markdown-all-in-one",
"junstyle.php-cs-fixer",
"bmewburn.vscode-intelephense-client",
"neilbrayfield.php-docblocker",
"dbaeumer.vscode-eslint",
"aswinkumar863.smarty-template-support",
"ms-vscode-remote.remote-containers"
]
}
23 changes: 15 additions & 8 deletions Admin/LknmpGatewayGiveWPAdmin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Lknmp\Gateway\Admin;

/**
Expand All @@ -21,7 +22,8 @@
* @subpackage Lknmp_Gateway_Givewp/admin
* @author Link Nacional <contato@linknacional>
*/
final class LknmpGatewayGiveWPAdmin {
final class LknmpGatewayGiveWPAdmin
{
/**
* The ID of this plugin.
*
Expand All @@ -47,7 +49,8 @@ final class LknmpGatewayGiveWPAdmin {
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
public function __construct($plugin_name, $version)
{
$this->plugin_name = $plugin_name;
$this->version = $version;
}
Expand All @@ -57,7 +60,8 @@ public function __construct( $plugin_name, $version ) {
*
* @since 1.0.0
*/
public function enqueue_styles(): void {
public function enqueue_styles(): void
{
/**
* This function is provided for demonstration purposes only.
*
Expand All @@ -69,15 +73,16 @@ public function enqueue_styles(): void {
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/lknmp-gateway-givewp-admin.css', array(), $this->version, 'all' );
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/lknmp-gateway-givewp-admin.css', array(), $this->version, 'all');
}

/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts($hook): void {
public function enqueue_scripts($hook): void
{
/**
* This function is provided for demonstration purposes only.
*
Expand All @@ -89,14 +94,15 @@ public function enqueue_scripts($hook): void {
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script("lkn-mercadopago-givewp-show-message.js", plugin_dir_url(__FILE__) . 'js/lknmp-gateway-givewp-show-message.js', null, $this->version, false );
wp_enqueue_script("lkn-mercadopago-givewp-show-message.js", plugin_dir_url(__FILE__) . 'js/lknmp-gateway-givewp-show-message.js', null, $this->version, false);

wp_localize_script("lkn-mercadopago-givewp-show-message.js", "varsPhp", array(
"admin_url" => admin_url("edit.php?post_type=give_forms&page=give-settings&tab=gateways&section=mercado_pago")
));
}

public function add_setting_into_new_section($settings) {
public function add_setting_into_new_section($settings)
{
switch (give_get_current_setting_section()) {
case 'mercado_pago':

Expand Down Expand Up @@ -163,7 +169,8 @@ public function add_setting_into_new_section($settings) {
*
* @return array
*/
public function new_setting_section($sections) {
public function new_setting_section($sections)
{
$sections['mercado_pago'] = 'Mercado Pago';
return $sections;
}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.4 - 26/11/2024
* Correção em url de redirecionamento.
* Melhoria no fluxo de pagamento.

# 1.2.3 - 27/09/2024
* Correção de problema no script do SDK do Mercado Pago.

Expand Down
84 changes: 50 additions & 34 deletions Includes/LknmpGatewayGiveWP.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
* @subpackage Lknmp_Gateway_Givewp/includes
* @author Link Nacional <contato@linknacional>
*/
final class LknmpGatewayGiveWP {
final class LknmpGatewayGiveWP
{
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
Expand Down Expand Up @@ -76,7 +77,8 @@ final class LknmpGatewayGiveWP {
*
* @since 1.0.0
*/
public function __construct() {
public function __construct()
{
if (defined('LKNMP_GATEWAY_GIVEWP_VERSION')) {
$this->version = LKNMP_GATEWAY_GIVEWP_VERSION;
} else {
Expand Down Expand Up @@ -107,7 +109,8 @@ public function __construct() {
* @since 1.0.0
* @access private
*/
private function load_dependencies(): void {
private function load_dependencies(): void
{
$this->loader = new LknmpGatewayGiveWPLoader();
}

Expand All @@ -120,7 +123,8 @@ private function load_dependencies(): void {
* @since 1.0.0
* @access private
*/
private function set_locale(): void {
private function set_locale(): void
{
$plugin_i18n = new LknmpGatewayGiveWPi18n();

$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
Expand All @@ -133,7 +137,8 @@ private function set_locale(): void {
* @since 1.0.0
* @access private
*/
private function define_admin_hooks(): void {
private function define_admin_hooks(): void
{
$plugin_admin = new LknmpGatewayGiveWPAdmin($this->get_plugin_name(), $this->get_version());
$this->loader->add_filter('plugin_action_links_' . LKNMP_GATEWAY_GIVEWP_BASENAME, 'Lknmp\Gateway\Includes\LknmpGatewayGiveWPHelper', 'plugin_row_meta', 10, 2);
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
Expand All @@ -152,7 +157,8 @@ private function define_admin_hooks(): void {
* @since 1.0.0
* @access private
*/
private function define_public_hooks(): void {
private function define_public_hooks(): void
{
$plugin_public = new LknmpGatewayGiveWPPublic($this->get_plugin_name(), $this->get_version());

$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
Expand All @@ -165,7 +171,8 @@ private function define_public_hooks(): void {
*
* @since 1.0.0
*/
public function run(): void {
public function run(): void
{
$this->loader->run();
}

Expand All @@ -176,7 +183,8 @@ public function run(): void {
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
public function get_plugin_name()
{
return $this->plugin_name;
}

Expand All @@ -186,7 +194,8 @@ public function get_plugin_name() {
* @since 1.0.0
* @return LknmpGatewayGiveWPLoader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
public function get_loader()
{
return $this->loader;
}

Expand All @@ -196,7 +205,8 @@ public function get_loader() {
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
public function get_version()
{
return $this->version;
}

Expand All @@ -209,35 +219,40 @@ public function get_version() {
*
* @return void
*/
public function new_gateway_register($paymentGatewayRegister) :void {
public function new_gateway_register($paymentGatewayRegister): void
{
$paymentGatewayRegister->registerGateway('Lknmp\Gateway\PublicView\LknmpGatewayGiveWPGateway');
}

final public function mercadopago_get_endpoint_payments() {
final public function mercadopago_get_endpoint_payments()
{
// rest_ensure_response() wraps the data we want to return into a WP_REST_Response, and ensures it will be properly returned.
return rest_ensure_response( 'Hello World, this is the WordPress REST API' );
return rest_ensure_response('Hello World, this is the WordPress REST API');
}

/**
* This function is where we register our routes for our example endpoint.
*/
final public function register_payment_routes(): void {
final public function register_payment_routes(): void
{
// register_rest_route() handles more arguments but we are going to stick to the basics for now.
register_rest_route('lknmp/v1', '/payments', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array($this, 'mercadopago_get_endpoint_payments'),
) );
));
}

public function register_rest_route(): void {
register_rest_route( 'lknmp/v1', '/payments/checkpayment', array(
public function register_rest_route(): void
{
register_rest_route('lknmp/v1', '/payments/checkpayment', array(
'methods' => 'GET',
'callback' => array($this, 'get_handle_custom_payment_route'),
'permission_callback' => '__return_true',
) );
));
}

public function get_handle_custom_payment_route($request) {
public function get_handle_custom_payment_route($request)
{
$id = $request->get_param('id');
$statusFront = $request->get_param('statusFront');
if (empty($id)) {
Expand All @@ -247,59 +262,60 @@ public function get_handle_custom_payment_route($request) {
switch ($statusFront) {
case '1':
$donation_id = get_option("lknmp_gateway_" . $id);
if ( ! $donation_id) {
if (! $donation_id) {
return new WP_Error('no_donation_id', 'No donation ID found', array('status' => 404));
}

$donation = Donation::find($donation_id);
if ( ! $donation) {
if (! $donation) {
return new WP_Error('donation_not_found', 'Donation not found', array('status' => 404));
}

$donation->status = DonationStatus::COMPLETE();
$donation->save();
if ( ! $donation) {
if (! $donation) {
return new WP_Error('save_failed', 'Failed to update donation status', array('status' => 500));
}

$url_pagina = give_get_success_page_uri();
$receipt_id = give_get_payment_meta($donation_id, '_give_payment_purchase_key');
$redirect_url = home_url('/?givewp-route=donation-confirmation-receipt-view&receipt-id=' . sanitize_text_field($receipt_id));

header("Location: $url_pagina", true, 302);
header("Location: $redirect_url", true, 302);
exit;
break;
case '2':
$donation_id = get_option("lknmp_gateway_" . $id);
if ( ! $donation_id) {
if (! $donation_id) {
return new WP_Error('no_donation_id', 'No donation ID found', array('status' => 404));
}
$donation = Donation::find($donation_id);
if ( ! $donation) {
if (! $donation) {
return new WP_Error('donation_not_found', 'Donation not found', array('status' => 404));
}
$donation->status = DonationStatus::PENDING();
$donation->save();
if ( ! $donation) {
if (! $donation) {
return new WP_Error('save_failed', 'Failed to update donation status', array('status' => 500));
}
$receipt_id = give_get_payment_meta($donation_id, '_give_payment_purchase_key');
$redirect_url = home_url('/?givewp-route=donation-confirmation-receipt-view&receipt-id=' . sanitize_text_field($receipt_id));

$url_pagina = give_get_success_page_uri();

header("Location: $url_pagina", true, 302);
header("Location: $redirect_url", true, 302);
exit;
break;
case '3':
$donation_id = get_option("lknmp_gateway_" . $id);
if ( ! $donation_id) {
if (! $donation_id) {
return new WP_Error('no_donation_id', 'No donation ID found', array('status' => 404));
}
$donation = Donation::find($donation_id);
if ( ! $donation) {
if (! $donation) {
return new WP_Error('donation_not_found', 'Donation not found', array('status' => 404));
}

$donation->status = DonationStatus::FAILED();
$donation->save();
if ( ! $donation) {
if (! $donation) {
return new WP_Error('save_failed', 'Failed to update donation status', array('status' => 500));
}

Expand All @@ -318,4 +334,4 @@ public function get_handle_custom_payment_route($request) {
break;
}
}
}
}
7 changes: 5 additions & 2 deletions Includes/LknmpGatewayGiveWPi18n.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Lknmp\Gateway\Includes;

/**
* Define the internationalization functionality
*
Expand All @@ -25,13 +26,15 @@
* @subpackage Lknmp_Gateway_Givewp/includes
* @author Link Nacional <contato@linknacional>
*/
final class LknmpGatewayGiveWPi18n {
final class LknmpGatewayGiveWPi18n
{
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain(): void {
public function load_plugin_textdomain(): void
{
load_plugin_textdomain(
'lknmp-gateway-givewp',
false,
Expand Down
Loading

0 comments on commit 2173ad8

Please sign in to comment.