[NSFW] Custom Wocommerce Payment Gateway Help
-
<?php /* Plugin Name: Liberty Dollar Financial Association (Payment Gateway) Plugin URI: http://www.ldfa.nl/ Description: Add a LDFA Buy Now Button to your website and start selling with Liberty Dollar Financial Association today. No Coding Required. Official Liberty Dollar Financial Association Partner. Version: 0.0.1 */ if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) return; add_filter( 'woocommerce_payment_gateways', 'ldfa_add_gateway_class' ); function ldfa_add_gateway_class( $gateways ) { $gateways[] = 'WC_LDFA_Gateway'; // your class name is here return $gateways; } add_action( 'plugins_loaded', 'ldfa_init_gateway_class' ); function ldfa_init_gateway_class() { class WC_LDFA_Gateway extends WC_Payment_Gateway { public $app_id; public $cart_id; public $publishable_key; public $merchant_key; public function __construct() { $this->id = 'ldfa_payment'; $this->icon = ''; $this->has_fields = false; $this->method_title = __('LDFA Payment Gateway', 'woocommerce'); $this->method_description = 'Take Payments Via Liberty Dollar Financial Association Wallet.'; $this->supports = array( 'products' ); $this->init_form_fields(); $this->init_settings(); $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->enabled = $this->get_option( 'enabled' ); $this->app_id = ''; $this->cart_id = ''; $this->publishable_key = ''; $this->merchant_key = ''; add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); } public function init_form_fields(){ $this->form_fields = array( 'enabled' => array( 'title' => __('Enable/Disable', 'woocommerce'), 'label' => 'Enable LDFA Gateway', 'type' => 'checkbox', 'description' => '', 'default' => 'no' ), 'title' => array( 'title' => __('Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => 'LDFA Payment Gateway', 'desc_tip' => true, ), 'description' => array( 'title' => __('Description', 'woocommerce'), 'type' => 'textarea', 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce'), 'default' => 'Pay via LDFA Payment Gateway.', ), 'app_id' => array( 'title' => __('Live App ID', 'woocommerce'), 'type' => 'text' ), 'publishable_key' => array( 'title' => __('Live Publish Key', 'woocommerce'), 'type' => 'text' ), 'merchant_key' => array( 'title' => __('Live Merchant Key', 'woocommerce'), 'type' => 'text' ), 'cart_id' => array( 'title' => __('Shopping Cart Key', 'woocommerce'), 'type' => 'text' ) ); } public function payment_fields() { if ( $this->description ) { echo wpautop( wp_kses_post( $this->description ) ); } } public function payment_scripts() { // Placeholder for including any necessary JavaScript files for the payment gateway } public function validate_fields() { if( empty( $_POST[ 'billing_first_name' ]) ) { wc_add_notice( 'First name is required!', 'error' ); return false; } return true; } public function process_payment( $order_id ) { global $woocommerce; $order = wc_get_order( $order_id ); $order->update_status('on-hold', __( 'Awaiting LDFA Payment Response', 'woocommerce' )); $woocommerce->cart->empty_cart(); $status_file = get_site_url().'/wp-content/plugins/ldfa-gateway/templates/order_reciept.php'; $orderDetails = json_encode(array('site_url' => $status_file, 'merchant_id' => $this->get_option( 'merchant_key' ), 'publish_key' => $this->get_option( 'publishable_key' ), 'order_id' => $order_id, 'total_cost' => $order->total)); $finalOrder = base64_encode($orderDetails); return array( 'result' => 'success', 'order_id' => $order_id, 'redirect' => get_site_url().'/wp-content/plugins/ldfa-gateway/ldfa-redirect.php?mt_r='.$finalOrder ); } public function webhook() { // Placeholder for handling webhook requests } } }I am not getting option on checkout page
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘[NSFW] Custom Wocommerce Payment Gateway Help’ is closed to new replies.