2
2
add_filter ("gform_pre_render " , array ("GFDibsHook " , "preRenderForm " )); // hidden input with return url
3
3
add_action ("gform_confirmation " , array ("GFDibsHook " , "dibsTransition " ), 10 , 4 ); // before payment on DIBS
4
4
add_filter ("gform_disable_notification " , array ("GFDibsHook " , 'disableNotifications ' ), 10 , 4 ); // disabled notification on submit
5
- add_filter ("gform_form_tag " , array ("GFDibsHook " , "formTag " ), 10 , 2 ); // after payment
5
+ add_filter ("gform_form_tag " , array ("GFDibsHook " , "formTag " ), 10 , 2 ); // shows confirmation message after payment
6
+ add_action ("init " , array ("GFDibsHook " , "updateLeadAfterPayment " ), 10 , 2 ); // checks if payment received
6
7
add_filter ("gform_pre_send_email " , array ("GFDibsHook " , "parseNotification " ), 10 , 1 ); // send notification mail after payment
7
8
add_filter ("gform_entries_column_filter " , array ("GFDibsHook " , "changeColumnData " ) , 10 , 5 ); // gravity forms backend
8
9
add_action ("gform_entry_detail " , array ("GFDibsHook " , 'addPaymentDetails ' ), 10 , 2 ); // gravity forms back end
@@ -52,6 +53,22 @@ public static function preRenderForm($form) {
52
53
53
54
// $feed = $Dao->getDibsMeta($feed_id);
54
55
56
+ // hidden input form id
57
+ $ Field = new GF_Field_Hidden ();
58
+
59
+ $ Field ->type = 'hidden ' ;
60
+ $ Field ->label = 'dibs_form_id ' ;
61
+ $ Field ->pageNumber = 1 ;
62
+ $ Field ->formId = $ form ['id ' ];
63
+
64
+ $ Field ->id = 9998 ;
65
+ $ Field ->inputName = 'dibs_form_id ' ;
66
+ $ Field ->defaultValue = $ form ['id ' ];
67
+
68
+ array_push ($ form ['fields ' ], $ Field );
69
+
70
+
71
+ // hidden input return url
55
72
$ Field = new GF_Field_Hidden ();
56
73
57
74
$ Field ->type = 'hidden ' ;
@@ -218,6 +235,7 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
218
235
unset($ feed ->meta ['gf_dibs_type ' ]);
219
236
unset($ feed ->meta ['gf_dibs_mode ' ]);
220
237
238
+
221
239
foreach ($ feed ->meta as $ key => $ value ) {
222
240
$ value = str_replace ('. ' , '_ ' , $ value );
223
241
//$Dao->log( $key );
@@ -239,7 +257,12 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
239
257
// $_POST['orderId'] = hexdec(uniqid());
240
258
$ _POST ['leadId ' ] = $ lead ['id ' ];
241
259
242
- $ order_id = uniqid (get_option (ORDER_ID_SUFFIX )."_ " );
260
+ $ order_id = uniqid ();
261
+
262
+ if ( $ suffix = get_option (ORDER_ID_SUFFIX ) ){
263
+ $ order_id = $ suffix .'_ ' .$ order_id ;
264
+ }
265
+
243
266
// dx
244
267
$ _POST ['orderId ' ] = $ order_id ;
245
268
@@ -258,6 +281,10 @@ public static function dibsTransition($confirmation, $form, $lead, $ajax){
258
281
$ _POST ['send_to_dibs ' ] = '1 ' ;
259
282
260
283
284
+ if ( isset ($ _POST ['input_9998 ' ]) ){ // input_9999 => return url
285
+ $ _POST ['dibs_form_id ' ] = $ _POST ['input_9998 ' ];
286
+ }
287
+
261
288
if ( isset ($ _POST ['input_9999 ' ]) ){ // input_9999 => return url
262
289
// D2
263
290
$ _POST ['callbackurl ' ] = $ _POST ['input_9999 ' ];
@@ -354,28 +381,101 @@ public static function replacePlaceholders( $message, $placeholders ){
354
381
return $ message ;
355
382
}
356
383
357
- public static function formTag ($ form_tag , $ form ){
358
- $ Dao = new GFDibsDao ();
359
384
360
- if ( isset ($ _POST ) && count ($ _POST ) ){
385
+ public static function hasRedirect ($ form ){
386
+ $ redirect = null ;
387
+ if ( isset ($ form ['confirmations ' ]) && is_array ($ form ['confirmations ' ]) ){
388
+ foreach ($ form ['confirmations ' ] as $ key => $ confirmation ) {
389
+ if ( is_array ($ confirmation ) && $ confirmation ['isDefault ' ] == '1 ' ){
390
+ if ( $ confirmation ['type ' ] == 'page ' ){
391
+ $ redirect = get_permalink ( $ confirmation ['pageId ' ] );
392
+ }
393
+ elseif ( $ confirmation ['type ' ] == 'redirect ' ){
394
+ $ redirect = $ confirmation ['url ' ];
395
+ }
396
+ }
397
+ }
398
+ }
399
+
400
+ return $ redirect ;
401
+ }
402
+
403
+ public static function grabOrderId ( $ post ){
404
+ $ order_id = null ;
405
+ if ( isset ($ post ['orderId ' ]) && strlen ($ post ['orderId ' ]) ){
406
+ $ order_id = $ post ['orderId ' ];
407
+ }
408
+ else if ( isset ($ post ['orderid ' ]) && strlen ($ post ['orderid ' ]) ){
409
+ $ order_id = $ post ['orderid ' ];
410
+ }
411
+
412
+ return $ order_id ;
413
+
414
+ }
415
+
416
+
417
+ public static function updateLeadAfterPayment (){
418
+
419
+ $ order_id = self ::grabOrderId ($ _POST );
420
+
421
+ if ( isset ($ _POST ) && $ order_id && isset ($ _POST ['dibs_form_id ' ]) && is_numeric ($ _POST ['dibs_form_id ' ]) ){
361
422
_log ('GF DIBS add-on ' );
423
+ _log ($ order_id );
362
424
_log ('User is coming back from DIBS ' );
363
425
_log ('Post variables ' );
364
426
_log ($ _POST );
365
- }
427
+ $ Dao = new GFDibsDao ();
428
+
429
+ $ form = GFAPI ::get_form ( $ _POST ['dibs_form_id ' ] );
430
+ $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]);
431
+ $ feed = $ Dao ->getDibsMeta ($ feed_id );
432
+
433
+ $ block = false ;
434
+ if ( isset ($ _SERVER ['HTTP_USER_AGENT ' ]) && is_numeric (strpos ($ _SERVER ['HTTP_USER_AGENT ' ], 'Java ' )) or isset ($ _SERVER ['HTTP_X_ORIG_UA ' ]) && is_numeric (strpos ($ _SERVER ['HTTP_X_ORIG_UA ' ], 'Java ' )) ){
435
+ $ block = true ;
436
+ }
366
437
367
- $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]);
368
438
369
- $ block = false ;
370
- // $Dao->log($_SERVER);
371
- if ( isset ($ _SERVER ['HTTP_USER_AGENT ' ]) && is_numeric (strpos ($ _SERVER ['HTTP_USER_AGENT ' ], 'Java ' )) or isset ($ _SERVER ['HTTP_X_ORIG_UA ' ]) && is_numeric (strpos ($ _SERVER ['HTTP_X_ORIG_UA ' ], 'Java ' )) ){
372
- $ block = true ;
439
+ if ( $ feed_id && $ order_id && !$ block ){
440
+
441
+ // update Transaction
442
+ $ Dao ->updateTransaction ($ _POST );
443
+
444
+ // send confirmation mails
445
+ _log ('confm ' );
446
+ _log ($ order_id );
447
+ if ( $ Transaction = $ Dao ->getTransactionByOrderId ($ order_id ) ){
448
+ _log ($ Transaction );
449
+ /* prod */
450
+ if ( isset ($ feed ->meta ['gf_dibs_no_confirmations ' ]) && $ feed ->meta ['gf_dibs_no_confirmations ' ] == '1 ' && !$ Dao ->getDateCompleted ($ Transaction ->lead_id ) ){
451
+ GFDibsAddOn::sendNotification ('form_submission ' , $ form , $ Transaction ->lead_id );
452
+ $ Dao ->setDateCompleted ($ Transaction ->lead_id );
453
+ }
454
+ /* test */
455
+ // GFDibsAddOn::sendNotification('form_submission', $form, $Transaction->lead_id);
456
+ //
457
+ }
458
+
459
+
460
+ if ( $ location = self ::hasRedirect ($ form ) ){
461
+ wp_redirect ( $ location );
462
+ die ();
463
+ }
464
+ }
373
465
}
466
+ }
467
+
468
+
469
+
374
470
375
- if ( $ feed_id && isset ($ _POST ['orderId ' ]) & !$ block ){
376
- // update Transaction
377
- $ Dao ->updateTransaction ($ _POST );
471
+
472
+ public static function formTag ($ form_tag , $ form ){
473
+
474
+ if ( isset ($ _POST ['orderId ' ]) ){
475
+ $ Dao = new GFDibsDao ();
476
+ $ feed_id = $ Dao ->isDibsForm ($ form ['id ' ]);
378
477
// get feed settings
478
+
379
479
$ feed = $ Dao ->getDibsMeta ($ feed_id );
380
480
381
481
$ placeholders = array ();
@@ -392,33 +492,24 @@ public static function formTag($form_tag, $form){
392
492
}
393
493
}
394
494
395
- /* prod */
396
- if ( isset ($ feed ->meta ['gf_dibs_no_confirmations ' ]) && $ feed ->meta ['gf_dibs_no_confirmations ' ] == '1 ' && !$ Dao ->getDateCompleted ($ Transaction ->lead_id ) ){
397
- GFDibsAddOn::sendNotification ('form_submission ' , $ form , $ Transaction ->lead_id );
398
- $ Dao ->setDateCompleted ($ Transaction ->lead_id );
399
- }
400
- /* test */
401
- // GFDibsAddOn::sendNotification('form_submission', $form, $Transaction->lead_id);
402
-
403
495
// get placeholders
404
496
$ placeholders = self ::getPlaceholders ($ Transaction , $ feed );
405
497
406
498
// replace placeholders
407
499
$ message = self ::replacePlaceholders ($ message , $ placeholders );
408
- }
409
500
410
- // sanitize form tag
411
- $ form_tag = preg_replace ("|action='(.*?)'| " , "style='display:none;' " , $ form_tag );
412
- ?>
413
- <div class="thank-you" style="background:#e5e4e1;padding:20px 20px;border-radius:10px;">
414
- <p><?php echo $ message ; ?> </p>
415
- </div>
416
- <?php
501
+ // sanitize form tag
502
+ $ form_tag = preg_replace ("|action='(.*?)'| " , "style='display:none;' " , $ form_tag );
503
+
504
+ printf ('<div class="thank-you"><p>%s</p></div> ' , $ message );
505
+ }
417
506
}
418
507
508
+
419
509
return $ form_tag ;
420
510
}
421
511
512
+
422
513
public static function addPaymentDetails ($ form , $ lead ){
423
514
$ Dao = new GFDibsDao ();
424
515
0 commit comments