@@ -591,11 +591,11 @@ function validate_payment()
591591 die ("*ok* " );
592592 }
593593
594- // Actually process the callback data
595- $ this ->process_callback_data ($ data , $ order );
596-
597594 $ order ->update_meta_data ('cryptapi_last_checked ' , time ());
598595 $ order ->save_meta_data ();
596+
597+ // Actually process the callback data
598+ $ this ->process_callback_data ($ data , $ order );
599599 }
600600
601601 function order_status ()
@@ -619,16 +619,10 @@ function order_status()
619619 $ remaining_pending = $ calc ['remaining_pending ' ];
620620 $ remaining_fiat = $ calc ['remaining_fiat ' ];
621621
622- $ hide_refresh = 0 ;
623-
624622 $ cryptapi_pending = 0 ;
625623
626624 $ counter_calc = (int )$ order ->get_meta ('cryptapi_last_price_update ' ) + (int )$ this ->refresh_value_interval - time ();
627625
628- if ($ already_paid > 0 ) {
629- $ hide_refresh = 1 ;
630- }
631-
632626 if ($ remaining_pending <= 0 && !$ order ->is_paid ()) {
633627 $ cryptapi_pending = 1 ;
634628 }
@@ -661,7 +655,6 @@ function order_status()
661655 'fiat_remaining ' => $ remaining_fiat <= 0 ? 0 : $ remaining_fiat ,
662656 'already_paid_fiat ' => floatval ($ already_paid_fiat ) <= 0 ? 0 : floatval ($ already_paid_fiat ),
663657 'fiat_symbol ' => get_woocommerce_currency_symbol (),
664- 'hide_refresh ' => $ hide_refresh ,
665658 ];
666659
667660 echo json_encode ($ data );
@@ -679,21 +672,22 @@ function validate_logs($order, $history)
679672 {
680673 $ callbacks = CryptAPI \Helper::check_logs ($ order ->get_meta ('cryptapi_callback_url ' ), $ order ->get_meta ('cryptapi_currency ' ));
681674
675+ $ order ->update_meta_data ('cryptapi_last_checked ' , time ());
676+ $ order ->save_meta_data ();
677+
682678 foreach ($ callbacks as $ callback ) {
683679 $ logs = $ callback ->logs ;
684680 $ request_url = parse_url ($ logs [0 ]->request_url );
685681 parse_str ($ request_url ['query ' ], $ data );
686682
687- if (empty ($ history [$ callback ->uuid ]) || (!empty ($ history [$ callback ->uuid ]) && (int )$ history [$ callback ->uuid ]['pending ' ] === 1 && (int )$ data ['pending ' ] === 0 )) {
683+ if (empty ($ history [$ data ->uuid ]) || (!empty ($ history [$ data ->uuid ]) && (int )$ history [$ data ->uuid ]['pending ' ] === 1 && (int )$ data ['pending ' ] === 0 )) {
688684 $ this ->process_callback_data ($ data , $ order , true );
689685 }
690686 }
691-
692- $ order ->update_meta_data ('cryptapi_last_checked ' , time ());
693- $ order ->save_meta_data ();
694687 }
695688
696- function process_callback_data ($ data , $ order , $ validation = false ) {
689+ function process_callback_data ($ data , $ order , $ validation = false )
690+ {
697691 $ paid = floatval ($ data ['value_coin ' ]);
698692
699693 $ min_tx = floatval ($ order ->get_meta ('cryptapi_min ' ));
@@ -718,18 +712,53 @@ function process_callback_data($data, $order, $validation = false) {
718712 $ order ->update_meta_data ('cryptapi_history ' , json_encode ($ history ));
719713 $ order ->save_meta_data ();
720714
721- $ order ->add_order_note (
722- ($ data ['pending ' ] ? '[PENDING] ' : '' ) .
723- __ ('User sent a payment of ' , 'cryptapi ' ) . ' ' .
724- $ paid . ' ' . $ crypto_coin .
725- '. TXID: ' . $ data ['txid_in ' ]
726- );
727-
728715 $ calc = $ this ->calc_order (json_decode ($ order ->get_meta ('cryptapi_history ' ), true ), $ order ->get_meta ('cryptapi_total ' ), $ order ->get_meta ('cryptapi_total_fiat ' ));
729716
730717 $ remaining = $ calc ['remaining ' ];
731718 $ remaining_pending = $ calc ['remaining_pending ' ];
732719
720+ $ order_notes = $ this ->get_private_order_notes ($ order ->get_id ());
721+
722+ $ has_pending = false ;
723+ $ has_confirmed = false ;
724+
725+ foreach ($ order_notes as $ note ) {
726+ $ note_content = $ note ['note_content ' ];
727+
728+ if (strpos ((string )$ note_content , 'PENDING ' ) && strpos ((string )$ note_content , $ data ['txid_in ' ])) {
729+ $ has_pending = true ;
730+ }
731+
732+ if (strpos ((string )$ note_content , 'CONFIRMED ' ) && strpos ((string )$ note_content , $ data ['txid_in ' ])) {
733+ $ has_confirmed = true ;
734+ }
735+ }
736+
737+ if (!$ has_pending ) {
738+ $ order ->add_order_note (
739+ '[PENDING] ' .
740+ __ ('User sent a payment of ' , 'cryptapi ' ) . ' ' .
741+ $ paid . ' ' . $ crypto_coin .
742+ '. TXID: ' . $ data ['txid_in ' ]
743+ );
744+ }
745+
746+ if (!$ has_confirmed && (int )$ data ['pending ' ] === 0 ) {
747+ $ order ->add_order_note (
748+ '[CONFIRMED] ' . __ ('User sent a payment of ' , 'cryptapi ' ) . ' ' .
749+ $ paid . ' ' . $ crypto_coin .
750+ '. TXID: ' . $ data ['txid_in ' ]
751+ );
752+
753+ if ($ remaining > 0 ) {
754+ if ($ remaining < $ min_tx ) {
755+ $ order ->add_order_note (__ ('Payment detected and confirmed. Customer still need to send ' , 'cryptapi ' ) . ' ' . $ min_tx . $ crypto_coin , false );
756+ } else {
757+ $ order ->add_order_note (__ ('Payment detected and confirmed. Customer still need to send ' , 'cryptapi ' ) . ' ' . $ remaining . $ crypto_coin , false );
758+ }
759+ }
760+ }
761+
733762 if ($ remaining_pending <= 0 ) {
734763 if ($ remaining <= 0 ) {
735764 $ order ->payment_complete ($ data ['address_in ' ]);
@@ -757,14 +786,6 @@ function process_callback_data($data, $order, $validation = false) {
757786 }
758787 }
759788
760- if ($ remaining > 0 && (int )$ data ['pending ' ] === 0 ) {
761- if ($ remaining < $ min_tx ) {
762- $ order ->add_order_note (__ ('Payment detected and confirmed. Customer still need to send ' , 'cryptapi ' ) . ' ' . $ min_tx . $ crypto_coin , false );
763- } else {
764- $ order ->add_order_note (__ ('Payment detected and confirmed. Customer still need to send ' , 'cryptapi ' ) . ' ' . $ remaining . $ crypto_coin , false );
765- }
766- }
767-
768789 if ($ remaining_pending < $ min_tx ) {
769790 $ order ->update_meta_data ('cryptapi_qr_code_value ' , CryptAPI \Helper::get_static_qrcode ($ order ->get_meta ('cryptapi_address ' ), $ order ->get_meta ('cryptapi_currency ' ), $ min_tx , $ this ->qrcode_size )['qr_code ' ]);
770791 } else {
@@ -1126,8 +1147,8 @@ function ca_cronjob()
11261147 $ this ->validate_logs ($ order , $ history );
11271148 }
11281149
1129- if ($ value_refresh !== 0 && $ last_price_update + $ value_refresh <= time () && !empty ($ last_price_update )) {
1130- if ($ already_paid === 0 ) {
1150+ if ($ value_refresh !== 0 && (( int ) $ last_price_update + ( int ) $ value_refresh < time () ) && !empty ($ last_price_update )) {
1151+ if ($ remaining === $ remaining_pending && $ remaining_pending > 0 ) {
11311152 $ cryptapi_coin = $ order ->get_meta ('cryptapi_currency ' );
11321153
11331154 $ crypto_total = CryptAPI \Helper::sig_fig (CryptAPI \Helper::get_conversion ($ woocommerce_currency , $ cryptapi_coin , $ order ->get_total ('edit ' ), $ this ->disable_conversion ), 6 );
@@ -1392,4 +1413,27 @@ function add_order_link($actions, $order)
13921413 }
13931414 return $ actions ;
13941415 }
1416+
1417+ function get_private_order_notes ($ order_id )
1418+ {
1419+ global $ wpdb ;
1420+
1421+ $ table_perfixed = $ wpdb ->prefix . 'comments ' ;
1422+ $ results = $ wpdb ->get_results ("
1423+ SELECT *
1424+ FROM $ table_perfixed
1425+ WHERE `comment_post_ID` = $ order_id
1426+ AND `comment_type` LIKE 'order_note'
1427+ " );
1428+
1429+ foreach ($ results as $ note ) {
1430+ $ order_note [] = array (
1431+ 'note_id ' => $ note ->comment_ID ,
1432+ 'note_date ' => $ note ->comment_date ,
1433+ 'note_author ' => $ note ->comment_author ,
1434+ 'note_content ' => $ note ->comment_content ,
1435+ );
1436+ }
1437+ return $ order_note ;
1438+ }
13951439}
0 commit comments