Reputation: 21
I'm totally new to WP I am building a payment method in WC and I have built the basic plugin that is visible on checkout. Now I this plugin to send product id or cart id(if there is something like that), cart price
I want to retrieve the data on my application(website)
I also want to send confirmation data back to Woocommerce. All the transaction must happen in my external website. I have no idea what hooks will be used to perform the whole functionailty
add_filter( 'woocommerce_payment_gateways', 'add_your_gateway_class' );
function add_your_gateway_class( $methods ) {
$methods[] = 'WC_Custom_PG';
return $methods;
}
add_action( 'plugins_loaded', 'init_wc_custom_payment_gateway' );
function init_wc_custom_payment_gateway(){
class WC_Custom_PG extends WC_Payment_Gateway {
function __construct(){
$this->id = 'wc_custom_pg';
$this->method_title = 'Custom Payment Gateway';
$this->title = 'Custom Payment Gateway';
$this->has_fields = true;
$this->method_description = 'Your description of the payment gateway';
$this->init_form_fields();
$this->init_settings();
$this->enabled = $this->get_option('enabled');
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option('description');
//process settings with parent method
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
public function init_form_fields(){
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable Custom Payment Gateway',
'default' => 'yes'
),
'title' => array(
'title' => 'Method Title',
'type' => 'text',
'description' => 'This controls the payment method title',
'default' => 'Custom Payment Gatwaye',
'desc_tip' => true,
),
'description' => array(
'title' => 'Customer Message',
'type' => 'textarea',
'css' => 'width:500px;',
'default' => 'Your Payment Gateway Description',
'description' => 'The message which you want it to appear to the customer in the checkout page.',
)
);
}
//this function lets you add fields that can collect payment information in the checkout page like card details and pass it on to your payment gateway API through the process_payment function defined above.
public function payment_fields(){
?>
<fieldset>
<p class="form-row form-row-wide">
<?php echo esc_attr($this->description); ?>
</p>
<div class="clear"></div>
</fieldset>
<?php
}
}
}
Upvotes: 1
Views: 690