9
9
add_filter ("gform_leads_before_export " , array ("GFDibsHook " , "modifyExportData " ) , 10 , 3 ); // gravity forms lead export
10
10
add_filter ("wp_enqueue_scripts " , array ("GFDibsHook " , "includeFrontendScripts " ) , 10 , 3 ); // front end assets
11
11
add_filter ("admin_enqueue_scripts " , array ("GFDibsHook " , "includeAdminScripts " ) , 10 , 3 ); // back end assets
12
+ add_filter ("admin_body_class " , array ("GFDibsHook " , "addAdminBodyClass " ) );
13
+
12
14
13
15
class GFDibsHook{
14
16
17
+ public static function addAdminBodyClass ( $ classes ) {
18
+ $ classes .= ' gf-dibs ' ;
19
+
20
+ return $ classes ;
21
+ }
22
+
23
+
15
24
public static function setupDBTables () {
16
25
$ DAO = new GFDibsDao ();
17
26
$ DAO ->setupTables ();
@@ -20,17 +29,17 @@ public static function setupDBTables() {
20
29
21
30
public static function includeFrontendScripts (){
22
31
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 ' );
24
33
wp_enqueue_script ('gfdibsuser ' );
25
34
}
26
35
27
36
28
37
public static function includeAdminScripts (){
29
38
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 ' );
31
40
wp_enqueue_script ('gfdibsadmin ' );
32
41
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 ' );
34
43
wp_enqueue_style ('gfdibsadmin_style ' );
35
44
}
36
45
@@ -118,28 +127,70 @@ public static function parseNotification( $mail ){
118
127
119
128
public static function disableNotifications ($ unknown , $ confirmation , $ form , $ lead ){
120
129
$ Dao = new GFDibsDao ();
130
+ _log ('GFDibsHook::disableNotifications() ' );
121
131
122
132
$ is_disabled = false ;
123
133
124
134
if ( $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]) ){
125
135
$ feed = $ Dao ->getDibsMeta ($ feed_id );
126
136
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
+ }
130
142
}
131
143
}
132
144
133
145
return $ is_disabled ;
134
146
}
135
147
136
148
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
+
137
181
public static function dibsTransition ($ confirmation , $ form , $ lead , $ ajax ){
138
182
$ Dao = new GFDibsDao ();
183
+ _log ('GFDibsHook::dibsTransition() ' );
184
+
139
185
140
186
if ( $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]) ){
141
187
$ feed = $ Dao ->getDibsMeta ($ feed_id );
142
188
189
+ // check if user has choosen an alternative payment method
190
+ if ( !self ::isDibsPayment ($ feed , $ lead ) ){
191
+ return $ confirmation ;
192
+ }
193
+
143
194
// dibs test modus
144
195
if ( isset ($ feed ->meta ['gf_dibs_mode ' ]) && $ feed ->meta ['gf_dibs_mode ' ] == '1 ' ){
145
196
$ _POST ['test ' ] = 1 ;
@@ -197,9 +248,16 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
197
248
198
249
$ _POST ['currency ' ] = get_option ('rg_gforms_currency ' );
199
250
$ _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
+
201
260
202
-
203
261
if ( isset ($ _POST ['input_9999 ' ]) ){ // input_9999 => return url
204
262
// D2
205
263
$ _POST ['callbackurl ' ] = $ _POST ['input_9999 ' ];
@@ -221,7 +279,7 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
221
279
$ confirmation = '<form action=" ' .get_option (DIBS_POST_URL ).'" name="dibs_post_form" id="dibs_post_form" method="post" > ' ;
222
280
foreach ($ _POST as $ key => $ value ) {
223
281
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 );
225
283
}
226
284
227
285
}
@@ -300,13 +358,13 @@ public static function formTag($form_tag, $form){
300
358
$ Dao = new GFDibsDao ();
301
359
302
360
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 );
307
365
}
308
366
309
- $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]);
367
+ $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]);
310
368
311
369
$ block = false ;
312
370
// $Dao->log($_SERVER);
0 commit comments