Skip to content

Commit

Permalink
Merge pull request #142 from culqi/release-3.0.1
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
JoseHCalderon authored Nov 18, 2022
2 parents 0763bad + ad09983 commit 396093e
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 21 deletions.
5 changes: 4 additions & 1 deletion admin/assets/js/fullculqi_login.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ jQuery(document).ready(function () {
"merchant": jQuery('#fullculqi_pubkey').val(),
"eventId": "order.status.changed",
"url": jQuery('#fullculqi_notpay').val(),
"version": 2
"version": 2,
"loginActive": true,
"username": jQuery('#fullculqi_username').val(),
"password": jQuery('#fullculqi_password').val()
}),
};
jQuery.ajax(settings).done(function (response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ window.addEventListener("message", async function (event) {
}
}, false );
Culqi3DS.publicKey = fullculqi_vars.public_key;
var device = await Culqi3DS.generateDevice();
//var device = await Culqi3DS.generateDevice();
async function generateDevice(){
const device = await Culqi3DS.generateDevice();
return device;
}
var device = generateDevice();

(function ($) {

Expand Down
64 changes: 59 additions & 5 deletions includes/admin/class-fullculqi-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ class FullCulqi_Settings {
* Construct
*/
public function __construct() {
$settings = fullculqi_get_settings();
error_log(print_r($settings,true));
$username_bd = $settings['username'];
if($username_bd == '' || $username_bd == null){
$GLOBALS['username'] = bin2hex(random_bytes(5));
}
else{
$GLOBALS['username'] = $username_bd;
}

$settings = fullculqi_get_settings();
$password_bd = $settings['password'];
if($password_bd == '' || $password_bd == null){
$GLOBALS['password'] = bin2hex(random_bytes(10));
}
else
{
$GLOBALS['password'] = $password_bd;
}

// Script JS & CSS
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
Expand All @@ -19,14 +38,14 @@ public function __construct() {

// Register Form
add_action( 'admin_init', [ $this, 'register_settings' ] );
}


}
/**
* CSS & JS
* @return mixed
*/
public function enqueue_scripts() {

$screen = get_current_screen();

if( isset( $screen->base ) && (
Expand Down Expand Up @@ -205,16 +224,13 @@ public function webhooks_page() {
'resources/layouts/admin/webhooks-page.php', $args
);
}


/**
* Register Settings
* @return mixed
*/
public function register_settings() {
//OLANDA INGRESO INPUTS FORM SETTINGS
do_action( 'fullculqi/settings/before_fields' );

register_setting(
'fullculqi_group', // Option group
'fullculqi_options', // Option name
Expand Down Expand Up @@ -296,6 +312,24 @@ public function register_settings() {
'fullculqi_section' // Section
);

add_settings_field(
'fullculqi_username', // ID
esc_html__( '', 'fullculqi' ) , // Username
[ $this, 'input_username' ], // Callback
'fullculqi_page', // Page
'fullculqi_section', // Section
array( 'class' => 'fullculqi_username' )
);

add_settings_field(
'fullculqi_password', // ID
esc_html__( '', 'fullculqi' ) , // Username
[ $this, 'input_password' ], // Callback
'fullculqi_page', // Page
'fullculqi_section',
array( 'class' => 'fullculqi_password' )
);

add_settings_field(
'fullculqi_buttoncustom', // ID
esc_html__( 'Personalizar formulario de checkout', 'fullculqi' ), // Logo
Expand Down Expand Up @@ -420,6 +454,26 @@ public function input_notpay() {
fullculqi_get_template( 'resources/layouts/admin/settings/input_notpay.php', $settings );
}

/**
* Input URL notify payment
* @return html
*/
public function input_username() {
$settings = fullculqi_get_settings();

fullculqi_get_template( 'resources/layouts/admin/settings/input_username.php', $settings );
}

/**
* Input URL notify payment
* @return html
*/
public function input_password() {
$settings = fullculqi_get_settings();

fullculqi_get_template( 'resources/layouts/admin/settings/input_password.php', $settings );
}

/**
* Input URL logo
* @return html
Expand Down
21 changes: 20 additions & 1 deletion includes/class-fullculqi-webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,30 @@ public function __construct() {
public function to_receive() {

$inputJSON = file_get_contents('php://input');

$headers = getallheaders();
$headers = $headers['Authorization'];
if(!isset($headers)){
exit("Error: Cabecera Authorization no presente");
}
$authorization = substr($headers,6);
$credenciales = base64_decode($authorization);
$credenciales = explode( ':', $credenciales );
$username = $credenciales[0];
$password = $credenciales[1];
if(!isset($username) or !isset($password)){
exit("Error: No Autorizado");
}
if( empty( $inputJSON ) )
return;

$input = json_decode( $inputJSON );
$settings = fullculqi_get_settings();
$username_bd = $settings['username'];
$password_bd = $settings['password'];

if( $username != $username_bd || $password != $password_bd ){
exit("Error: Crendenciales Incorrectas");
}

if( $input->object != 'event' )
return;
Expand Down
2 changes: 2 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function fullculqi_get_default() {
],
'time_expiration' => '',
'notify_pay' => '',
'username' => '',
'password' => '',
'color_palette' => ''
];

Expand Down
5 changes: 5 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function fullculqi_activate() {
fullculqi_Activator::activate();
}

// plugin uninstallation
register_uninstall_hook( __FILE__, 'my_fn_uninstall' );
function my_fn_uninstall() {
delete_option( 'fullculqi_options' );
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-fullculqi-deactivator.php
Expand Down
32 changes: 20 additions & 12 deletions resources/layouts/admin/settings/input_methods.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
<?php
$tarjeta = $methods['tarjeta'] ?? '';
$yape = $methods['yape'] ?? '';
$billetera = $methods['billetera'] ?? '';
$bancaMovil = $methods['bancaMovil'] ?? '';
$agente = $methods['agente'] ?? '';
$cuetealo = $methods['cuetealo'] ?? '';
?>
<label for="fullculqi_logo">
<div>
<input id="fullculqi_methods_tarjeta" name="fullculqi_options[methods][tarjeta]" <?php echo ($methods['tarjeta'] == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Tarjetas débito/credito
<input id="fullculqi_methods_tarjeta" name="fullculqi_options[methods][tarjeta]" <?php echo ($tarjeta == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Tarjetas débito/credito
</div>
<div>
<input id="fullculqi_methods_yape" name="fullculqi_options[methods][yape]" <?php echo ($methods['yape'] == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Yape
<input id="fullculqi_methods_yape" name="fullculqi_options[methods][yape]" <?php echo ($yape == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Yape
</div>
<div>
<input id="fullculqi_methods_wallets" name="fullculqi_options[methods][billetera]" <?php echo ($methods['billetera'] == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Billeteras móviles
<input id="fullculqi_methods_wallets" name="fullculqi_options[methods][billetera]" <?php echo ($billetera == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Billeteras móviles
<span class="tool" data-tip="Tus clientes pueden pagar con Yape, Plin y las principales billeteras móviles del país." tabindex="2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.496 6.033h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286a.237.237 0 0 0 .241.247zm2.325 6.443c.61 0 1.029-.394 1.029-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94 0 .533.425.927 1.01.927z"/></svg>
</span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.496 6.033h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286a.237.237 0 0 0 .241.247zm2.325 6.443c.61 0 1.029-.394 1.029-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94 0 .533.425.927 1.01.927z"/></svg>
</span>
</div>
<div>
<input id="fullculqi_methods_bancaMovil" name="fullculqi_options[methods][bancaMovil]" <?php echo ($methods['bancaMovil'] == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Banca móvil o internet
<input id="fullculqi_methods_bancaMovil" name="fullculqi_options[methods][bancaMovil]" <?php echo ($bancaMovil == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Banca móvil o internet
</div>
<div>
<input id="fullculqi_methods_agents" name="fullculqi_options[methods][agente]" <?php echo ($methods['agente'] == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Agentes y bodegas
<input id="fullculqi_methods_agents" name="fullculqi_options[methods][agente]" <?php echo ($agente == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Agentes y bodegas
</div>
<div>
<input id="fullculqi_methods_quotedbcp" name="fullculqi_options[methods][cuetealo]" <?php echo ($methods['cuetealo'] == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Cuotéalo BCP
<input id="fullculqi_methods_quotedbcp" name="fullculqi_options[methods][cuetealo]" <?php echo ($cuetealo == 'yes') ? 'checked' : '' ; ?> type="checkbox" value="yes"> Cuotéalo BCP
<span class="tool" data-tip="Paga en cuotas y sin tarjetas de crédito con Cuotéalo" tabindex="2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.496 6.033h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286a.237.237 0 0 0 .241.247zm2.325 6.443c.61 0 1.029-.394 1.029-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94 0 .533.425.927 1.01.927z"/></svg>
</span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-question-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.496 6.033h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286a.237.237 0 0 0 .241.247zm2.325 6.443c.61 0 1.029-.394 1.029-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94 0 .533.425.927 1.01.927z"/></svg>
</span>
</div>
</label>
<span id="errorpaymentmethods" class="form-text text-muted" style="display: block; color: red"></span>
4 changes: 3 additions & 1 deletion resources/layouts/admin/settings/input_notpay.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<label for="fullculqi_notpay">
<input type="text" readonly="true" id="fullculqi_notpay" class="regular-text" name="fullculqi_options[notify_pay]" value="<?php echo site_url( 'fullculqi-api/webhooks' ); ?>"/><br>
<span class="form-text text-muted"> Si no iniciaste sesión con tu cuenta de CulqiPanel, tienes que configurar esta URL.</span>
<span class="form-text text-muted"> Si no iniciaste sesión con tu cuenta de CulqiPanel, tienes que configurar esta URL colocando estas credenciales:</span><br>
<b>Usuario:</b> <?php echo $GLOBALS['username']; ?>
<b>Password:</b> <?php echo $GLOBALS['password'];; ?>
</label>
9 changes: 9 additions & 0 deletions resources/layouts/admin/settings/input_password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<style>
.fullculqi_password{
display:none;
}
</style>

<label for="fullculqi_password">
<input id="fullculqi_password" name="fullculqi_options[password]" type="hidden" value="<?php echo $GLOBALS['password']; ?>">
</label>
8 changes: 8 additions & 0 deletions resources/layouts/admin/settings/input_username.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<style>
.fullculqi_username{
display:none;
}
</style>
<label for="fullculqi_username">
<input id="fullculqi_username" name="fullculqi_options[username]" type="hidden" value="<?php echo $GLOBALS['username']; ?>">
</label>

0 comments on commit 396093e

Please sign in to comment.