← Back
Editing: class.payzeep-block.php
<?php use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; use Automattic\WooCommerce\StoreApi\Payments\PaymentContext; use Automattic\WooCommerce\StoreApi\Payments\PaymentResult; final class Payzeep_Blocks extends AbstractPaymentMethodType { // private $gateway; protected $name = 'pzeep'; public function __construct() { add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'checkout_process_payment_with_context' ), 10, 2 ); } public function initialize() { // $this->settings = get_option('woocommerce_payzeep_settings', []); // $this->settings = get_option('woocommerce_pzeep_settings', []); $this->settings = get_option("woocommerce_{$this->name}_settings", []); // you can also initialize your payment gateway here // $gateways = WC()->payment_gateways->payment_gateways(); // $this->gateway = $gateways[ $this->name ]; } // public function initialize() { // // get payment gateway settings. // $this->settings = get_option( "woocommerce_{$this->name}_settings", array() ); // } public function is_active() { return isset($this->settings['enabled']) && $this->settings['enabled'] === 'yes'; // return ! empty( $this->settings[ 'enabled' ] ) && 'yes' === $this->settings[ 'enabled' ]; // return true; } public function get_payment_method_script_handles() { wp_register_script( 'wc-custom-blocks-integration', // plugin_dir_url( __DIR__ ) . 'build/index.js', plugin_dir_url( __FILE__ ) . 'build/index.js', // plugin_dir_url( dirname( __FILE__ ) ) . 'build/index.js', array( 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', ), null, // or time() or filemtime( ... ) to skip caching true // filemtime( plugin_dir_path( dirname( __FILE__ ) ) . 'build/index.js' ), // true ); // return array( 'wc-misha-blocks-integration' ); return ['wc-custom-blocks-integration']; } // public function get_payment_method_script_handles() { // $asset_path = plugin_dir_path( __DIR__ ) . 'build/index.asset.php'; // $version = null; // $dependencies = array(); // if( file_exists( $asset_path ) ) { // $asset = require $asset_path; // $version = isset( $asset[ 'version' ] ) ? $asset[ 'version' ] : $version; // $dependencies = isset( $asset[ 'dependencies' ] ) ? $asset[ 'dependencies' ] : $dependencies; // } // wp_register_script( // 'wc-misha-blocks-integration', // plugin_dir_url( __DIR__ ) . 'build/index.js', // $dependencies, // $version, // true // ); // return array( 'wc-misha-blocks-integration' ); // } public function get_payment_method_data() { return [ 'title' => $this->settings['title'] ?? 'Payzeep Payment Gateway', 'description' => $this->settings['description'] ?? 'Pay with Payzeep.', 'icon' => plugin_dir_url( __DIR__ ) . 'payzeep-pg/assets/payzeep-logo.png', // if $this->gateway was initialized on line 21 // 'supports' => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] ), // example of getting a public key // 'publicKey' => $this->get_publishable_key(), ]; } //private function get_publishable_key() { // $test_mode = ( ! empty( $this->settings[ 'testmode' ] ) && 'yes' === $this->settings[ 'testmode' ] ); // $setting_key = $test_mode ? 'test_publishable_key' : 'publishable_key'; // return ! empty( $this->settings[ $setting_key ] ) ? $this->settings[ $setting_key ] : ''; //} public function checkout_process_payment_with_context( PaymentContext $context ) { // $order = $context->order; // $gateway = new Payzeep_Woocommerce(); // $result = $gateway->process_payment( $order->get_id() ); // $payment_result = new PaymentResult(); // if ( $result['result'] === 'success' ) { // $payment_result->set_status( 'success' ); // $payment_result->set_redirect_url( $result['redirect'] ); // } else { // $payment_result->set_status( 'failure' ); // $payment_result->set_message( __( 'Payment failed', 'payzeep' ) ); // } // return $payment_result; } }
Save File
Cancel