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'); ?>
'.__('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' );