Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Commit 5ba0948

Browse files
committed
versjon 1.2.0
1 parent e1adcdd commit 5ba0948

File tree

5 files changed

+130
-23
lines changed

5 files changed

+130
-23
lines changed

GFDibsAddOn.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public static function dibsPage(){
163163

164164

165165
public function pluginPage() {
166+
166167
$this->DAO = new GFDibsDao();
167168

168169
if(rgpost('action') == "delete"){
@@ -357,6 +358,8 @@ function editPage(){
357358
</div>
358359

359360

361+
<hr/>
362+
360363
<!-- transaction type -->
361364
<div class="margin_vertical_10">
362365
<label class="left_header" for="gf_dibs_type"><?php _e("Transaction Type", DIBS_LANG); ?></label>
@@ -368,12 +371,24 @@ function editPage(){
368371
</select>
369372
</div>
370373

374+
<hr/>
375+
371376
<!-- captureNow -->
372377
<div class="margin_vertical_10" id="capture_now" >
373378
<label class="left_header" for="gf_dibs_capture_now"><?php _e("Capture after authorization", DIBS_LANG); ?></label>
374379
<input type="checkbox" name="gf_dibs_capture_now" id="gf_dibs_capture_now" value="1" <?php checked( $this->getArrayValue($feed->meta, 'gf_dibs_capture_now'), 1 ); ?> />
375380
</div>
376381

382+
<hr/>
383+
384+
<div class="margin_vertical_10" id="custom_merchant_id" >
385+
<label class="left_header" for="gf_dibs_custom_merchant_id"><?php _e("Custom merchant id", DIBS_LANG); ?></label>
386+
<input type="text" name="gf_dibs_custom_merchant_id" id="gf_dibs_custom_merchant_id" value="<?php echo (( isset($feed->meta['gf_dibs_custom_merchant_id'])) ? $feed->meta['gf_dibs_custom_merchant_id'] : null) ?>" />
387+
<span style="padding-left:202px;display:block;color: #cc0000;">Overwrites the <a href="<?php echo get_admin_url(); ?>admin.php?page=gf_settings&amp;subview=DIBS">global merchant id</a>
388+
</div>
389+
390+
<hr/>
391+
377392

378393
<!-- gf form id -->
379394
<div id="paypal_form_container" valign="top" class="margin_vertical_10" >
@@ -457,6 +472,16 @@ function editPage(){
457472
<select id="billingPostalPlace" name="billingPostalPlace" class="form_field"><option value="" class="default"><?php _e('Select field', DIBS_LANG); ?></option></select>
458473
</div>
459474

475+
<hr/>
476+
477+
<div class="margin_vertical_10">
478+
<div class="left_header" for="paymentMethods"><?php _e("Payment methods", DIBS_LANG); ?></div>
479+
<select id="paymentMethods" name="paymentMethods" class="form_field"><option value="" class="default"><?php _e('Select field', DIBS_LANG); ?></option></select>
480+
</div>
481+
482+
483+
<hr/>
484+
460485

461486
<h3><?php _e("Notifications", DIBS_LANG); ?></h3>
462487
<!-- Confirmation mail -->

GFDibsHook.php

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@
99
add_filter("gform_leads_before_export", array("GFDibsHook" , "modifyExportData") , 10, 3); // gravity forms lead export
1010
add_filter("wp_enqueue_scripts", array("GFDibsHook" , "includeFrontendScripts") , 10, 3); // front end assets
1111
add_filter("admin_enqueue_scripts", array("GFDibsHook" , "includeAdminScripts") , 10, 3); // back end assets
12+
add_filter("admin_body_class", array("GFDibsHook" , "addAdminBodyClass") );
13+
1214

1315
class GFDibsHook{
1416

17+
public static function addAdminBodyClass( $classes ) {
18+
$classes .= ' gf-dibs ';
19+
20+
return $classes;
21+
}
22+
23+
1524
public static function setupDBTables() {
1625
$DAO = new GFDibsDao();
1726
$DAO->setupTables();
@@ -20,17 +29,17 @@ public static function setupDBTables() {
2029

2130
public static function includeFrontendScripts(){
2231
wp_enqueue_script('jquery');
23-
wp_register_script( 'gfdibsuser', plugin_dir_url(__FILE__).'/assets/gfdibs_user.js' );
32+
wp_register_script( 'gfdibsuser', plugin_dir_url(__FILE__).'/assets/gfdibs_user.js', null, '1.2.0' );
2433
wp_enqueue_script('gfdibsuser');
2534
}
2635

2736

2837
public static function includeAdminScripts(){
2938
wp_enqueue_script('jquery');
30-
wp_register_script( 'gfdibsadmin', plugin_dir_url(__FILE__).'/assets/gfdibs_admin.js' );
39+
wp_register_script( 'gfdibsadmin', plugin_dir_url(__FILE__).'/assets/gfdibs_admin.js', null, '1.2.0' );
3140
wp_enqueue_script('gfdibsadmin');
3241

33-
wp_register_style( 'gfdibsadmin_style', plugin_dir_url(__FILE__).'/assets/gfdibs_admin.css' );
42+
wp_register_style( 'gfdibsadmin_style', plugin_dir_url(__FILE__).'/assets/gfdibs_admin.css', null, '1.2.0' );
3443
wp_enqueue_style('gfdibsadmin_style');
3544
}
3645

@@ -118,28 +127,70 @@ public static function parseNotification( $mail ){
118127

119128
public static function disableNotifications($unknown, $confirmation, $form, $lead){
120129
$Dao = new GFDibsDao();
130+
_log('GFDibsHook::disableNotifications()');
121131

122132
$is_disabled = false;
123133

124134
if ( $feed_id = $Dao->isDibsForm($form['id']) ){
125135
$feed = $Dao->getDibsMeta($feed_id);
126136

127-
$Dao->log($feed->meta['gf_dibs_no_confirmations']);
128-
if ( isset($feed->meta['gf_dibs_no_confirmations']) && $feed->meta['gf_dibs_no_confirmations'] == '1' ){
129-
$is_disabled = true;
137+
if( self::isDibsPayment($feed, $lead) ){
138+
$Dao->log($feed->meta['gf_dibs_no_confirmations']);
139+
if ( isset($feed->meta['gf_dibs_no_confirmations']) && $feed->meta['gf_dibs_no_confirmations'] == '1' ){
140+
$is_disabled = true;
141+
}
130142
}
131143
}
132144

133145
return $is_disabled;
134146
}
135147

136148

149+
public static function isDibsPayment($feed, $lead){
150+
// _log('$feed');
151+
// _log($feed);
152+
// _log('$lead');
153+
// _log($lead);
154+
$is_dibs_payment = true;
155+
156+
if ( isset($feed->meta['paymentMethods']) && trim($feed->meta['paymentMethods']) ){
157+
$payment_method_field_id = $feed->meta['paymentMethods'];
158+
159+
if ( isset($lead[$payment_method_field_id]) && trim($lead[$payment_method_field_id]) && strtolower($lead[$payment_method_field_id]) != 'dibs' ){
160+
$is_dibs_payment = false;
161+
}
162+
}
163+
164+
return $is_dibs_payment;
165+
}
166+
167+
168+
public static function checkIfCustomMerchantId($feed){
169+
$custom_merchant_id = null;
170+
if ( isset($feed->meta['gf_dibs_custom_merchant_id']) ){
171+
$tmp_cmid = trim($feed->meta['gf_dibs_custom_merchant_id']);
172+
if ( is_numeric($tmp_cmid) ){
173+
$custom_merchant_id = $tmp_cmid;
174+
}
175+
}
176+
177+
return $custom_merchant_id;
178+
}
179+
180+
137181
public static function dibsTransition($confirmation, $form, $lead, $ajax){
138182
$Dao = new GFDibsDao();
183+
_log('GFDibsHook::dibsTransition()');
184+
139185

140186
if ( $feed_id = $Dao->isDibsForm($form['id']) ){
141187
$feed = $Dao->getDibsMeta($feed_id);
142188

189+
// check if user has choosen an alternative payment method
190+
if( !self::isDibsPayment($feed, $lead) ){
191+
return $confirmation;
192+
}
193+
143194
// dibs test modus
144195
if ( isset($feed->meta['gf_dibs_mode']) && $feed->meta['gf_dibs_mode'] == '1' ){
145196
$_POST['test'] = 1;
@@ -197,9 +248,16 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
197248

198249
$_POST['currency'] = get_option('rg_gforms_currency');
199250
$_POST['language'] = 'nb_NO';
200-
$_POST['merchant'] = get_option(MERCHANT);
251+
$_POST['merchant'] = trim(get_option(MERCHANT));
252+
253+
if ( $custom_merchant_id = self::checkIfCustomMerchantId($feed) ){
254+
$_POST['merchant'] = $custom_merchant_id;
255+
}
256+
257+
258+
$_POST['send_to_dibs'] = '1';
259+
201260

202-
203261
if ( isset($_POST['input_9999']) ){ // input_9999 => return url
204262
// D2
205263
$_POST['callbackurl'] = $_POST['input_9999'];
@@ -221,7 +279,7 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
221279
$confirmation = '<form action="'.get_option(DIBS_POST_URL).'" name="dibs_post_form" id="dibs_post_form" method="post" >';
222280
foreach ($_POST as $key => $value) {
223281
if ( !is_numeric(strpos($key, 'input')) && !is_numeric(strpos($key, 'MAX_FILE_SIZE')) && !is_numeric(strpos($key, 'state')) && !is_numeric(strpos($key, 'gform')) ){
224-
$confirmation .= sprintf('<input type="hidden" name="%s" value="%s" />', $key, $value );
282+
$confirmation .= sprintf('<input type="hidden" name="%s" id="%s" value="%s" />', $key, $key, $value );
225283
}
226284

227285
}
@@ -300,13 +358,13 @@ public static function formTag($form_tag, $form){
300358
$Dao = new GFDibsDao();
301359

302360
if ( isset($_POST) && count($_POST) ){
303-
$Dao->log('GF DIBS add-on');
304-
$Dao->log('User is coming back from DIBS');
305-
$Dao->log('Post variables');
306-
$Dao->log($_POST);
361+
_log('GF DIBS add-on');
362+
_log('User is coming back from DIBS');
363+
_log('Post variables');
364+
_log($_POST);
307365
}
308366

309-
$feed_id = $Dao->isDibsForm($form['id']);
367+
$feed_id = $Dao->isDibsForm($form['id']);
310368

311369
$block = false;
312370
// $Dao->log($_SERVER);

assets/gfdibs_admin.css

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ input.licence{
4242
padding:0px 0px !important;
4343
}
4444

45-
#paypal_submit_container{clear:both;}
46-
.paypal_col_heading{padding-bottom:2px; border-bottom: 1px solid #ccc; font-weight:bold; width:120px;}
47-
.paypal_field_cell {padding: 6px 17px 0 0; margin-right:15px;}
48-
49-
.paypal_validation_error{ background-color:#FFDFDF; margin-top:4px; margin-bottom:6px; padding-top:6px; padding-bottom:6px; border:1px dotted #C89797;}
50-
.paypal_validation_error span {color: red;}
5145
.left_header{float:left; width:200px;}
5246
.margin_vertical_10{margin: 10px 0; padding-left:5px;}
5347
.margin_vertical_30{margin: 30px 0; padding-left:5px;}
5448
.width-1{width:300px;}
55-
.gf_paypal_invalid_form{margin-top:30px; background-color:#FFEBE8;border:1px solid #CC0000; padding:10px; width:600px;}
49+
50+
51+
body.gf-dibs #wpfooter{
52+
display: none;
53+
}

assets/gfdibs_user.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
jQuery(document).ready(function(){
22
jQuery(document).bind('gform_confirmation_loaded', function(){
3-
document.dibs_post_form.submit();
3+
if ( jQuery('#send_to_dibs').length ){
4+
document.dibs_post_form.submit();
5+
}
46
});
57
}
68
);

gravityformsdibs.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Gravity Forms DIBS
44
Plugin URI: http://nettbutikk.mediebruket.no
55
Description: DIBS add-on for Gravity Forms. Supports D2 and DX platform.
6-
Version: 1.1.1
6+
Version: 1.2.0
77
Author: Mediebruket
88
Author URI: http://mediebruket.no
99
*/
@@ -25,4 +25,28 @@ function _debug($message = null){
2525

2626
register_activation_hook( $plugin_file , array('GFDibsHook', 'setupDBTables') );
2727
$GFDibsUpdater = new GFDibsUpdater( __FILE__ );
28+
29+
if(!function_exists('_log')){
30+
function _log( $message ) {
31+
if( WP_DEBUG === true ){
32+
if( is_array( $message ) || is_object( $message ) ){
33+
error_log( print_r( $message, true ) );
34+
} else {
35+
error_log( $message );
36+
}
37+
}
38+
}
39+
}
40+
41+
if(!function_exists('_debug')){
42+
function _debug($message) {
43+
if( WP_DEBUG === true ){
44+
if( is_array( $message ) || is_object( $message ) ){
45+
echo "<pre>" . print_r($message, true) . "</pre>";
46+
} else {
47+
echo "<pre>" . $message . "</pre>";
48+
}
49+
}
50+
}
51+
}
2852
?>

0 commit comments

Comments
 (0)