id = '8pay'; $this->icon = '">Crypto '; echo ''; if ( count( $subscriptions ) ) { $selected_plan_id = array_values($options)[0]['plan_id']; echo ''; } echo '
Select a chain
'; echo '
'; foreach ( $chains as $chain ) { $selected = $chain == $selected_chain ? 'selected' : ''; echo '
'; echo ' '; echo ' ' . WC_8Pay_Chain::name( $chain ) . ''; echo '
'; } echo '
'; echo '
Select a token
'; echo '
'; foreach ( $options as $option ) { $style = $option['chain'] != $selected_chain ? 'style="display: none;"' : ''; $selected = $option['chain'] == $selected_chain && $option['token'] == $selected_token ? 'selected' : ''; echo '
'; echo ' '; echo ' ' . $option['token'] . ''; echo '
'; } echo '
'; } /** * Outputs scripts and styles used for 8Pay payment */ public function payment_scripts() { wp_register_script( 'woocommerce_8pay', plugins_url( 'public/js/8pay.js?v=1.1.5', WC_8PAY_MAIN_FILE ), ['jquery'], WC_8PAY_VERSION, true ); wp_enqueue_script( 'woocommerce_8pay' ); wp_register_style( '8pay_styles', plugins_url( 'public/css/8pay-styles.css?v=1.1.5', WC_8PAY_MAIN_FILE ), [], WC_8PAY_VERSION ); wp_enqueue_style( '8pay_styles' ); } /** * Process the payment * * @param int $order_id Reference. * * @throws Exception If payment will not be accepted. * @return array|void */ public function process_payment( $order_id ) { global $woocommerce; $order = wc_get_order( $order_id ); $order_id = $order->get_id(); $currency = $order->get_currency(); $total_amount = floatval( $order->get_total() ); $chain = $_POST['8pay_payment_gateway_chain']; $token = $_POST['8pay_payment_gateway_token']; $plan_id = isset( $_POST['8pay_payment_gateway_plan_id'] ) ? $_POST['8pay_payment_gateway_plan_id'] : null; $order->add_meta_data( 'chain', $chain, true ); $order->add_meta_data( 'token', $token, true ); $extra = [ '8PayWoocommerceGateway' => 1, 'orderId' => $order_id, ]; if ( $plan_id ) { $type = WC_8Pay_BillingModel::FIXED_RECURRING; $data = [ 'planId' => $plan_id, 'params' => [], ]; $order->add_meta_data( 'plan_id', $plan_id, true ); $extra['webhook'] = WC_8Pay_Helper::get_webhook_url(); } else { $amount = WC_8Pay_Rates::convert_fiat_amount( $currency, $total_amount, $chain, $token ); $type = WC_8Pay_BillingModel::ONE_TIME; $data = [ 'params' => [ 'description' => 'Order #' . $order_id, 'token' => $token, 'receivers' => [ $this->receiver ], 'amounts' => [ $amount ], 'category' => 'Shop', 'webhook' => WC_8Pay_Helper::get_webhook_url(), ], ]; $order->add_meta_data( 'amount', $amount, true ); $order->add_meta_data( 'receiver', $this->receiver, true ); } $data['params']['extra'] = $extra; $data['params']['callbackSuccess'] = $this->get_return_url( $order ); try { $short_url = WC_8Pay_API_WooCommerce::create_short_url( $chain, [ 'type' => $type, 'data' => $data ] ); $checkout_domain = $chain == WC_8Pay_Chain::PRIVATE ? self::CHECKOUT_DEVELOPMENT : self::CHECKOUT_PRODUCTION; $checkout_url = $checkout_domain . '/' . $short_url->path; WC_8Pay_Logger::log( 'Created new short-url: ' . $checkout_url . PHP_EOL . print_r( $short_url, true ) ); $order->save_meta_data(); $order->update_status('on-hold', 'Awaiting 8Pay webhook'); $woocommerce->cart->empty_cart(); return [ 'result' => 'success', 'redirect' => $checkout_url, ]; } catch( Exception $e ) { wc_add_notice( __('Payment error:', 'woothemes') . $e->getMessage(), 'error' ); return; } } public function admin_options() { ?>

8Pay

generate_settings_html(); ?>
get_post_data(); $test_mode = isset( $post_data['woocommerce_8pay_test_mode'] ) && $post_data['woocommerce_8pay_test_mode'] == 1; $info = WC_8Pay_Auth::token_info( $value, $test_mode ); if ( !isset( $info->token ) ) { WC_Admin_Settings::add_error( 'The provided api key is invalid' ); $value = ''; } return $value; } public function validate_receiver_field( $key, $value ) { if ( !preg_match( '/^(0x)?[0-9a-f]{40}$/i', $value ) ) { WC_Admin_Settings::add_error( 'The provided receiver address is invalid' ); $value = ''; } return $value; } }