prefix . $mkDbTable; $charset = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $tableName ( id mediumint(9) NOT NULL AUTO_INCREMENT, type varchar(10) NOT NULL, country char(2) NOT NULL, name varchar(25) NOT NULL, url varchar(250) NOT NULL, UNIQUE KEY id (id) ) $charset;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } register_activation_hook( __FILE__, 'mc_install' ); // On uninstall remove scheduled hook function mc_uninstall() { if (wp_next_scheduled ( 'mc_banklinks_update_cron' )) { wp_clear_scheduled_hook('mc_banklinks_update_cron'); } } register_deactivation_hook(__FILE__, 'mc_uninstall'); // WP schedule callable action add_action('mc_banklinks_update_cron', 'update_mc_banklinks'); // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) { $date = new DateTime(); $date->setTime(04,10,00); $timestamp = intval($date->format('U')); //$local = 3600 * intval(get_option('gmt_offset')); //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron'); wp_schedule_event($timestamp, 'twicedaily', 'mc_banklinks_update_cron'); } if (!class_exists('wc_makecommerce_domain')) { require_once('includes/vendor/autoload.php'); require_once('includes/Maksekeskus.php'); } function mk_check_payment() { global $woocommerce; $api = mk_get_api(); $returnUrl = home_url(); $request = stripslashes_deep($_POST); if ($api->verifyMac($request)) { $data = $api->extractRequestData($request); $reference = false; if (!empty($data['error']) ) { wc_add_notice(__('Payment failed', 'wc_makecommerce_domain'), 'error'); return $returnUrl; } if (!empty($data['message_type']) ) { if ($data['message_type'] == 'payment_return') { $transactionId = $data['transaction']; $reference = $data['reference']; $paymentStatus = $data['status']; } if ($data['message_type'] == 'token_return') { if (!empty($data['transaction']['reference'])) { $reference = $data['transaction']['reference']; } $paymentStatus = $data['transaction']['status']; $transactionId = $data['transaction']['id']; // for API backward compatibility - if we didn't find reference in the mesage, or the transaction state vas still PENDING // we'll fetch the transaction data from API, and make a payment request if needed // this all can be removed after 2017-jan if (!$reference or $paymentStatus == 'PENDING') { $transaction = $api->getTransaction($transactionId); if (!empty($transaction->reference)) { $reference = $transaction->reference; } $paymentStatus = $transaction->status; if ($paymentStatus == 'PENDING') { $paymentRequest = array( 'amount' => $transaction->amount, 'currency' => $transaction->currency, 'token' => $data['token']['id'] ); $payment = $api->createPayment($transactionId, $paymentRequest); // TODO: validate $paymentStatus = $payment->transaction->status; } } } } } // if we didn't find reference to an Order, we send user to shop landing-page. TODO: could be improved if (!$reference) { return $returnUrl; } $order = new WC_Order($reference); // if we din't find the Order, we send user to shop landing-page. TODO: could be improved if (!$order->id) { return $returnUrl; } $returnUrl = $order->get_checkout_order_received_url(); switch($paymentStatus) { case 'CANCELLED': $order->update_status( 'cancelled' ); wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error'); $returnUrl = $woocommerce->cart->get_cart_url(); break; case 'COMPLETED': $orderNote = array(); $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': '.$transactionId.''; $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true); $order->add_order_note(implode("\r\n", $orderNote)); $order->payment_complete(); $order->update_status( 'processing' ); $woocommerce->cart->empty_cart(); break; } return $returnUrl; } $MKAPI = false; function mk_get_api() { global $MKAPI; if ($MKAPI) { //return $MKAPI; } $mk_api_type = get_option('mk_api_type', false); if (!$mk_api_type) { return false; } if ($mk_api_type !== 'live') { $key_prefix = $mk_api_type.'_'; } else { $key_prefix = ''; } $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', ''); $mk_public_key = get_option('mk_'.$key_prefix.'public_key', ''); $mk_private_key = get_option('mk_'.$key_prefix.'private_key', ''); if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) { return false; } $MKAPI = new \Maksekeskus\Maksekeskus($mk_shop_id, $mk_public_key, $mk_private_key, $mk_api_type === 'live' ? false : true); return $MKAPI; } function mk_is_api_set() { $mk_api_type = get_option('mk_api_type', false); if (!$mk_api_type) { return false; } if ($mk_api_type !== 'live') { $key_prefix = $mk_api_type.'_'; } else { $key_prefix = ''; } $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', ''); $mk_public_key = get_option('mk_'.$key_prefix.'public_key', ''); $mk_private_key = get_option('mk_'.$key_prefix.'private_key', ''); if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) { return false; } return true; } function mk_admin_error() { printf( '
%2$s