id = 'vnpg'; $this->icon = apply_filters( 'woocommerce_vnpg_icon', '' ); $this->has_fields = false; $this->method_title = __( 'Vietnam Bank Transfer (VietQR)', 'vnpg' ); $this->method_description = __( 'Take payments by scanning QR code with Vietnamese banking App.', 'vnpg' ); //Get bank list from VietQR API $this->bank_list = $this->get_vietqr_bank_list(); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables. $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->account_name = $this->get_option( 'account_name' ); $this->account_number = $this->get_option( 'account_number' ); $this->template_id = $this->get_option( 'template_id' ); $this->prefix = $this->get_option('prefix'); $this->bank = $this->get_option('bank'); // Actions. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); //add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) ); add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); // Customer Emails. add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); } /** * Initialise Gateway Settings Form Fields. */ public function init_form_fields(){ //Tự động sinh prefix đơn hàng cho website. $server_domain = $_SERVER['SERVER_NAME']; $shopname = preg_replace('#^.+://[^/]+#', '', $server_domain); $shopname = str_replace(".","",$shopname); //Tạo danh sách tên ngân hàng cho select form $bank_name = []; foreach ($this->bank_list['data'] as $bank) { $bank_name[$bank['short_name']] = $bank['short_name']; } $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable Vietnam Payment Gateway', 'vnpg' ), 'default' => 'no', ), 'title' => array( 'title' => __( 'Title', 'woocommerce' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'default' => __( 'Direct Bank Transfer via Vietcombank (VietQR)', 'vnpg' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'woocommerce' ), 'type' => 'textarea', 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ), 'default' => __( 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.', 'woocommerce' ), 'desc_tip' => true, ), 'bank' => array( 'title' => __('Bank Name', 'vnpg'), 'type' => 'select', 'options' => $bank_name, ), 'account_number' => array( 'title' => __( 'Account Number', 'vnpg'), 'type' => 'text', ), 'account_name' => array( 'title' => __( 'Account Name', 'vnpg'), 'type' => 'text' ), 'prefix' => array( 'title' => __('Prefix', 'vnpg'), 'type' => 'text', 'description' => __('Prefix used to combine with order code to create money transfer content, Set rules: no spaces, no more than 15 characters and no special characters. Violations will be deleted', 'vnpg'), 'default' => $shopname, 'desc_tip' => true, ), 'template_id' => array( 'title' => __( 'VietQR Template ID', 'vnpg'), 'type' => 'text', 'default' => 'compact' ), ); } /** * Output for the order received page. * * @param int $order_id Order ID. */ public function thankyou_page( $order_id ) { $this->payment_details( $order_id ); } /** * Add content to the WC emails. * * @param WC_Order $order Order object. * @param bool $sent_to_admin Sent to admin. * @param bool $plain_text Email format: plain text or HTML. */ public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { if (!$sent_to_admin && 'vnpg' === $order->get_payment_method() && $order->has_status('on-hold')) { $this->payment_details($order->get_id()); } } private function payment_details($order_id) { // Get order and store in $order. $order = wc_get_order($order_id); // Get VietQR Image URL and Pay URL $data = $this->get_vietqr_img_url($order_id); $qrcode_image_url = $data['img_url']; $qrcode_page_url = $data['pay_url']; $html = '