Skip to main content
WB2
Notifications
Retirer tout

passerelle de paiement

1 Publications
1 Utilisateurs
0 Reactions
0 Vu
(@voli)
Publications: 1
New Member
Début du sujet
 
[#5971]

Bonjour je suis entrain de faire une passerelle de paiement personnalisé maintenant j'arrive pas à faire la redirection vers la page de paiement .


<?php

/**

/**

* Plugin Name: plugin_PAY

* Description: Lancer la page de paiement

* Version: 5.6.40

* Author Name: xxx

* Author: Vxxx

*/

&nbsp;

&nbsp;

&nbsp;

&nbsp;

add_filter( 'woocommerce_payment_gateways', 'pay_add_gateway_class' );

function pay_add_gateway_class( $gateways ) {

$gateways[] = 'WC_Pay_Gateway'; // your class name is here

return $gateways;

}

&nbsp;

&nbsp;

add_action( 'plugins_loaded', 'pay_init_gateway_class' );

function pay_init_gateway_class() {

&nbsp;

class WC_Pay_Gateway extends WC_Payment_Gateway {

&nbsp;

/**

* Class constructor, more about it in Step 3

*/

public function __construct() {

&nbsp;

$this->id = 'pay';

$this->icon = '';

$this->has_fields = true;

$this->method_title = 'PAY Gateway';

$this->method_description = '';

&nbsp;

$this->supports = array(

'products'

);

&nbsp;

// Method with all the options fields

$this->init_form_fields();

&nbsp;

// Load the settings.

$this->init_settings();

$this->title = $this->get_option( 'title' );

$this->description = $this->get_option( 'description' );

$this->enabled = $this->get_option( 'enabled' );

$this->testmode = 'yes' === $this->get_option( 'testmode' );

$this->login = $this->testmode ? $this->get_option( 'login_api' ) : $this->get_option( 'login' );

$this->code = $this->testmode ? $this->get_option( 'code' ) : $this->get_option( 'code' );

&nbsp;

// This action hook saves the settings

add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );

&nbsp;

// We need custom JavaScript to obtain a token

add_action( 'woocommerce_before_checkout_process', array( $this, 'payment' ) );

&nbsp;

add_action( 'wp_enqueue_scripts', array( $this, 'payment' ) );

&nbsp;

}

&nbsp;

&nbsp;

&nbsp;

&nbsp;

public function init_form_fields(){

&nbsp;

$this->form_fields = array(

'enabled' => array(

'title'       => 'Enable/Disable',

'label'       => 'Enable Pay Gateway',

'type'        => 'checkbox',

'description' => '',

'default'     => 'no'

),

'title' => array(

'title'       => 'Title',

'type'        => 'text',

'description' => 'This controls the title which the user sees during checkout.',

'default'     => 'Payment',

'desc_tip'    => true,

),

'description' => array(

'title'       => 'Description',

'type'        => 'textarea',

'description' => 'This controls the description which the user sees during checkout.',

'default'     => '.',

),

'testmode' => array(

'title'       => 'Test mode',

'label'       => 'Enable Test Mode',

'type'        => 'checkbox',

'description' => 'Place the payment gateway in test mode using test API keys.',

'default'     => 'yes',

'desc_tip'    => true,

),

'login_api' => array(

'title'       => 'Login API',

'type'        => 'text'

),

'code' => array(

'title'       => 'Mot de Passe API',

'type'        => 'password',

),

'URL success' => array(

'title'       => 'URL Success',

'type'        => 'text'

),

'URL Failed' => array(

'title'       => 'URL Failed',

'type'        => 'text'

)

);

}

&nbsp;

&nbsp;

public function payment() {

global $woocommerce;

?>

<script src="" https://;;;"></script> ;"

&nbsp;

<body >

<button type="submit" id="place_order" name="woocommerce_checkout_place_order"  class="button alt"  href=""#"" onclick="lancerPaiement('xxx','xxx','xxx','xxxx.xxx/success','xxxx.xxx/failed', <?php echo $woocommerce->cart->total; ?>)"> Payment  </button>

</body>

&nbsp;

<script> function lancerPaiement(reference, login, code, url_success, url_failed, amount){

paymentPay(reference, login, code,url_success, url_failed, amount)

}

</script>

<?php

}

public function process_payment( $order_id ) {

&nbsp;

global $woocommerce;

&nbsp;

// we need it to get any order detailes

$order = new WC_Order( $order_id );

$checkout_payment_url = $order -> get_checkout_payment_url( paiement() ) ;

&nbsp;

return  array( 'result' => 'success', 'redirect' => add_query_arg ('order_pay', $order -> id , $checkout_payment_url)) ;

&nbsp;

&nbsp;

&nbsp;

}

}

}

?>


 
Posté : 20/12/2021 6:50 pm
Share: