id = 'dibs'; $this->icon = ''; $this->has_fields = false; $this->enabled = get_option('jigoshop_dibs_enabled'); $this->title = get_option('jigoshop_dibs_title'); $this->merchant = get_option('jigoshop_dibs_merchant'); $this->description = get_option('jigoshop_dibs_description'); $this->testmode = get_option('jigoshop_dibs_testmode'); $this->key1 = get_option('jigoshop_dibs_key1'); $this->key2 = get_option('jigoshop_dibs_key2'); add_action('init', array(&$this, 'check_callback') ); add_action('valid-dibs-callback', array(&$this, 'successful_request') ); add_action('jigoshop_update_options', array(&$this, 'process_admin_options')); add_action('receipt_dibs', array(&$this, 'receipt_page')); add_option('jigoshop_dibs_enabled', 'yes'); add_option('jigoshop_dibs_merchant', ''); add_option('jigoshop_dibs_key1', ''); add_option('jigoshop_dibs_key2', ''); add_option('jigoshop_dibs_title', __('DIBS', 'jigoshop') ); add_option('jigoshop_dibs_description', __("Pay via DIBS using credit card or bank transfer.", 'jigoshop') ); add_option('jigoshop_dibs_testmode', 'no'); } /** * Admin Panel Options * - Options for bits like 'title' and availability on a country-by-country basis **/ public function admin_options() { ?> DIBS to enter their payment information.', 'jigoshop'); ?> : : : : : : : '208', // Danish Kroner 'EUR' => '978', // Euro 'USD' => '840', // US Dollar $ 'GBP' => '826', // English Pound £ 'SEK' => '752', // Swedish Kroner 'AUD' => '036', // Australian Dollar 'CAD' => '124', // Canadian Dollar 'ISK' => '352', // Icelandic Kroner 'JPY' => '392', // Japanese Yen 'NZD' => '554', // New Zealand Dollar 'NOK' => '578', // Norwegian Kroner 'CHF' => '756', // Swiss Franc 'TRY' => '949', // Turkish Lire ); // filter redirect page $checkout_redirect = apply_filters( 'jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks') ); $args = array( // Merchant 'merchant' => $this->merchant, 'decorator' => 'default', // Session 'lang' => 'sv', // Order 'amount' => $order->order_total * 100, 'orderid' => $order_id, 'uniqueoid' => $order->order_key, 'currency' => $dibs_currency[get_option('jigoshop_currency')], 'ordertext' => 'TEST', // URLs 'callbackurl' => site_url('/jigoshop/dibscallback.php'), // TODO these urls will not work correctly since DIBS ignores the querystring 'accepturl' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))), 'cancelurl' => $order->get_cancel_order_url(), ); // Calculate key // http://tech.dibs.dk/dibs_api/other_features/md5-key_control/ $args['md5key'] = MD5(get_option('jigoshop_dibs_key2') . MD5(get_option('jigoshop_dibs_key1') . 'merchant=' . $args['merchant'] . '&orderid=' . $args['orderid'] . '¤cy=' . $args['currency'] . '&amount=' . $args['amount'])); if( !empty($_SERVER['HTTP_CLIENT_IP']) ) { $args['ip'] = $_SERVER['HTTP_CLIENT_IP']; } if ( $this->testmode == 'yes' ) { $args['test'] = 'yes'; } $fields = ''; foreach ($args as $key => $value) { $fields .= ''; } return '
' . $fields . ' '.__('Cancel order & restore cart', 'jigoshop').'
'; } /** * Process the payment and return the result **/ function process_payment( $order_id ) { $order = new jigoshop_order( $order_id ); return array( 'result' => 'success', 'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, apply_filters('jigoshop_get_return_url', get_permalink(jigoshop_get_page_id('pay'))))) ); } /** * receipt_page **/ function receipt_page( $order ) { echo '

'.__('Thank you for your order, please click the button below to pay with DIBS.', 'jigoshop').'

'; echo $this->generate_form( $order ); } /** * Check for DIBS Response **/ function check_callback() { if ( strpos($_SERVER["REQUEST_URI"], '/jigoshop/dibscallback.php') ) { error_log('Dibs callback!'); $_POST = stripslashes_deep($_POST); do_action("valid-dibs-callback", $_POST); } } /** * Successful Payment! **/ function successful_request( $posted ) { // Custom holds post ID if ( !empty($posted['transact']) && !empty($posted['orderid']) && is_numeric($posted['orderid']) ) { // Verify MD5 checksum // http://tech.dibs.dk/dibs_api/other_features/md5-key_control/ $key1 = get_option('jigoshop_dibs_key1'); $key2 = get_option('jigoshop_dibs_key2'); $vars = 'transact='. $posted['transact'] . '&amount=' . $posted['amount'] . '¤cy=' . $posted['currency']; $md5 = MD5($key2 . MD5($key1 . $vars)); if($posted['authkey'] != $md5) { error_log('MD5 check failed for Dibs callback with order_id:'.$posted['orderid']); exit(); } $order = new jigoshop_order( (int) $posted['orderid'] ); if ($order->order_key !== $posted['uniqueoid']) { error_log('Unique ID check failed for Dibs callback with order_id:'.$posted['orderid']); exit; } if ($order->status !== 'completed') { $order->add_order_note( __('Callback payment completed', 'jigoshop') ); $order->payment_complete(); } exit; } } } /** * Add the gateway to JigoShop **/ function add_dibs_gateway( $methods ) { $methods[] = 'dibs'; return $methods; } add_filter('jigoshop_payment_gateways', 'add_dibs_gateway' );