id = 'moneybookers'; $this->title = 'Moneybookers'; $this->icon = $woocommerce->plugin_url() . '/assets/images/icons/moneybookers.png'; $this->has_fields = false; $this->enabled = get_option('woocommerce_moneybookers_enabled'); $this->title = get_option('woocommerce_moneybookers_title'); $this->email = get_option('woocommerce_moneybookers_email'); add_action( 'init', array(&$this, 'check_status_response') ); if(isset($_GET['moneybookersPayment']) && $_GET['moneybookersPayment'] == true): add_action( 'init', array(&$this, 'generate_moneybookers_form') ); endif; add_action('valid-moneybookers-status-report', array(&$this, 'successful_request') ); add_action('woocommerce_update_options', array(&$this, 'process_admin_options')); add_option('woocommerce_moneybookers_enabled', 'yes'); add_option('woocommerce_moneybookers_email', ''); add_option('woocommerce_moneybookers_title', 'moneybookers'); add_action('receipt_moneybookers', array(&$this, 'receipt_moneybookers')); } /** * Admin Panel Options * - Options for bits like 'title' and availability on a country-by-country basis **/ public function admin_options() { ?>
'.__('Thank you for your order, please complete the secure (SSL) form below to pay with Moneybookers.', 'woothemes').'
'; echo ''; } /** * Check Moneybookers status report validity **/ function check_status_report_is_valid() { // Get Moneybookers post data array $params = $_POST; if(!isset($params['transaction_id'])) return false; $order_id = $params['transaction_id']; $_moneybookersmd = strtoupper(get_post_meta($order_id, '_moneybookersmd', true)); // Check MD5 signiture if($params['md5sig'] == $_moneybookersmd) return true; return false; } /** * Check for Moneybookers Status Response **/ function check_status_response() { if (isset($_GET['moneybookersListener']) && $_GET['moneybookersListener'] == 'moneybookers_status'): $_POST = stripslashes_deep($_POST); if ($this->check_status_report_is_valid()) : do_action("valid-moneybookers-status-report", $_POST); endif; endif; } /** * Successful Payment! **/ function successful_request( $posted ) { // Custom holds post ID if ( !empty($posted['mb_transaction_id']) ) { $order = new woocommerce_order( (int) $posted['transaction_id'] ); if ($order->status !== 'completed') : // We are here so lets check status and do actions switch ($posted['status']) : case '2' : // Processed $order->add_order_note( __('Moneybookers payment completed', 'woothemes') ); $order->payment_complete(); break; case '0' : // Pending case '-2' : // Failed $order->update_status('on-hold', sprintf(__('Moneybookers payment failed (%s)', 'woothemes'), strtolower(sanitize($posted['status'])) ) ); break; case '-1' : // Cancelled $order->update_status('cancelled', __('Moneybookers payment cancelled', 'woothemes')); break; default: $order->update_status('cancelled', __('Moneybookers exception', 'woothemes')); break; endswitch; endif; exit; } } } /** Add the gateway to WooCommerce **/ function add_moneybookers_gateway( $methods ) { $methods[] = 'woocommerce_moneybookers'; return $methods; } add_filter('woocommerce_payment_gateways', 'add_moneybookers_gateway' );