@@ -52,6 +52,7 @@ public function __construct() {
5252 $ this ->require_upi = $ this ->get_option ( 'require_upi ' , 'yes ' );
5353 $ this ->theme = $ this ->get_option ( 'theme ' , 'light ' );
5454 $ this ->transaction_id = $ this ->get_option ( 'transaction_id ' , 'show_require ' );
55+ $ this ->transaction_image = $ this ->get_option ( 'transaction_image ' , 'show_require ' );
5556 $ this ->intent = $ this ->get_option ( 'intent ' , 'no ' );
5657 $ this ->download_qr = $ this ->get_option ( 'download_qr ' , 'no ' );
5758 $ this ->qrcode_mobile = $ this ->get_option ( 'qrcode_mobile ' , 'yes ' );
@@ -279,6 +280,18 @@ public function init_form_fields() {
279280 'show_require ' => __ ( 'Show & Require Input Field ' , 'upi-qr-code-payment-for-woocommerce ' ),
280281 ),
281282 ),
283+ 'transaction_image ' => array (
284+ 'title ' => __ ( 'UPI Screenshot / Image: ' , 'upi-qr-code-payment-for-woocommerce ' ),
285+ 'type ' => 'select ' ,
286+ 'description ' => __ ( 'If you want to collect transaction screenshot from customers on payment page, set it here. ' , 'upi-qr-code-payment-for-woocommerce ' ),
287+ 'desc_tip ' => false ,
288+ 'default ' => 'show_require ' ,
289+ 'options ' => array (
290+ 'hide ' => __ ( 'Hide Field ' , 'upi-qr-code-payment-for-woocommerce ' ),
291+ 'show ' => __ ( 'Show Upload Field ' , 'upi-qr-code-payment-for-woocommerce ' ),
292+ 'show_require ' => __ ( 'Show & Require Input Field ' , 'upi-qr-code-payment-for-woocommerce ' ),
293+ ),
294+ ),
282295 'intent ' => array (
283296 'title ' => __ ( 'Payment Buttons: ' , 'upi-qr-code-payment-for-woocommerce ' ),
284297 'type ' => 'checkbox ' ,
@@ -472,25 +485,28 @@ public function validate_fields() {
472485 * Custom CSS and JS
473486 */
474487 public function payment_scripts () {
475- $ order_id = get_query_var ( 'order-pay ' );
476-
477- if ( ! is_cart () && ! is_checkout () && ! $ order_id ) {
488+ if ( 'no ' === $ this ->enabled ) {
478489 return ;
479490 }
480491
481- $ order = wc_get_order ( $ order_id );
482-
483- if ( 'no ' === $ this ->enabled || ! is_a ( $ order , 'WC_Order ' ) ) {
484- return ;
485- }
486-
487492 if ( is_checkout () && $ this ->upi_address !== 'hide ' ) {
488493 wp_enqueue_style ( 'upiwc-selectize ' , plugins_url ( 'css/selectize.min.css ' , __FILE__ ), array (), '0.15.2 ' );
489494 wp_enqueue_style ( 'upiwc-checkout ' , plugins_url ( 'css/checkout.min.css ' , __FILE__ ), array ( 'upiwc-selectize ' ), UPIWC_VERSION );
490495
491496 wp_enqueue_script ( 'upiwc-selectize ' , plugins_url ( 'js/selectize.min.js ' , __FILE__ ), array ( 'jquery ' ), '0.15.2 ' , false );
492497 }
493498
499+ $ order_id = get_query_var ( 'order-pay ' );
500+
501+ if ( ! $ order_id ) {
502+ return ;
503+ }
504+
505+ $ order = wc_get_order ( $ order_id );
506+
507+ if ( ! is_a ( $ order , 'WC_Order ' ) ) {
508+ return ;
509+ }
494510
495511 wp_register_style ( 'upiwc-inter-font ' , 'https://fonts.googleapis.com/css?family=Inter&display=swap ' );
496512 wp_register_style ( 'upiwc-jquery-confirm ' , plugins_url ( 'css/jquery-confirm.min.css ' , __FILE__ ), array (), '3.3.4 ' );
@@ -514,6 +530,7 @@ public function payment_scripts() {
514530 'payment_url ' => $ order ->get_checkout_payment_url (),
515531 'cancel_url ' => apply_filters ( 'upiwc_payment_cancel_url ' , wc_get_checkout_url (), $ this ->get_return_url ( $ order ), $ order ),
516532 'transaction_id ' => $ this ->transaction_id ,
533+ 'transaction_image ' => $ this ->transaction_image ,
517534 'mc_code ' => $ this ->mc_code ? $ this ->mc_code : 8931 ,
518535 'btn_timer ' => apply_filters ( 'upiwc_enable_button_timer ' , true ),
519536 'btn_show_interval ' => apply_filters ( 'upiwc_button_show_interval ' , 30000 ),
@@ -696,18 +713,31 @@ public function generate_qr_code( $order_id ) {
696713 <?php } ?>
697714 </div>
698715 <div class="upiwc-payment-confirm" style="display: none;">
699- <?php if ( $ this ->transaction_id !== 'hide ' ) { ?>
716+ <?php if ( $ this ->transaction_id !== 'hide ' || $ this -> transaction_image !== ' hide ' ) { ?>
700717 <div class="upiwc-payment-confirm-form-container">
701718 <form id="upiwc-payment-confirm-form" class="upiwc-payment-confirm-form">
702- <div class="form-row">
703- <label for="upiwc-payment-transaction-number">
704- <strong><?php esc_html_e ( 'Enter 12-digit Transaction / UTR / Reference ID: ' , 'upi-qr-code-payment-for-woocommerce ' ); ?> </strong>
705- <?php if ( $ this ->transaction_id === 'show_require ' ) { ?>
706- <span class="field-required">*</span>
707- <?php } ?>
708- </label>
709- <input type="text" id="upiwc-payment-transaction-number" class="" placeholder="" maxlength="12" onkeypress="return upiwcIsNumber(event)" />
710- </div>
719+ <?php if ( $ this ->transaction_id !== 'hide ' ) { ?>
720+ <div class="upiwc-form-row">
721+ <label for="upiwc-payment-transaction-number">
722+ <strong><?php esc_html_e ( 'Enter 12-digit Transaction / UTR / Reference ID: ' , 'upi-qr-code-payment-for-woocommerce ' ); ?> </strong>
723+ <?php if ( $ this ->transaction_id === 'show_require ' ) { ?>
724+ <span class="field-required">*</span>
725+ <?php } ?>
726+ </label>
727+ <input type="text" id="upiwc-payment-transaction-number" name="upiwc_transaction_id" maxlength="12" onkeypress="return upiwcIsNumber(event)" />
728+ </div>
729+ <?php } ?>
730+ <?php if ( $ this ->transaction_image !== 'hide ' ) { ?>
731+ <div class="upiwc-form-row">
732+ <label for="upiwc-payment-file">
733+ <strong><?php esc_html_e ( 'Upload Screenshot: ' , 'upi-qr-code-payment-for-woocommerce ' ); ?> </strong>
734+ <?php if ( $ this ->transaction_image === 'show_require ' ) { ?>
735+ <span class="field-required">*</span>
736+ <?php } ?>
737+ </label>
738+ <input type="file" id="upiwc-payment-file" name="upiwc_file" accept=".jpg, .jpeg, .png," />
739+ </div>
740+ <?php } ?>
711741 </form>
712742 <div class="upiwc-payment-error" style="display: none;"></div>
713743 </div>
@@ -730,7 +760,7 @@ public function capture_payment() {
730760 }
731761
732762 // generate order
733- $ order_id = wc_get_order_id_by_order_key ( sanitize_text_field ( $ _POST ['wc_order_key ' ] ) );
763+ $ order_id = wc_get_order_id_by_order_key ( sanitize_text_field ( $ _POST ['upiwc_order_key ' ] ) );
734764 $ order = wc_get_order ( $ order_id );
735765
736766 // check if it an order
@@ -739,8 +769,8 @@ public function capture_payment() {
739769 $ order ->update_status ( $ status_to_update );
740770
741771 // set upi id as trnsaction id
742- if ( isset ( $ _POST ['wc_transaction_id ' ] ) && ! empty ( $ _POST ['wc_transaction_id ' ] ) ) {
743- $ transaction_id = sanitize_text_field ( $ _POST ['wc_transaction_id ' ] );
772+ if ( isset ( $ _POST ['upiwc_transaction_id ' ] ) && ! empty ( $ _POST ['upiwc_transaction_id ' ] ) ) {
773+ $ transaction_id = sanitize_text_field ( $ _POST ['upiwc_transaction_id ' ] );
744774 $ order ->set_transaction_id ( $ transaction_id );
745775 }
746776
@@ -755,6 +785,29 @@ public function capture_payment() {
755785
756786 // update post meta
757787 $ order ->update_meta_data ( '_upiwc_order_paid ' , 'yes ' );
788+
789+ if ( ! empty ( $ _FILES ['upiwc_file ' ] ) ) {
790+ $ allowed_extensions = array ( 'image/jpeg ' , 'image/png ' );
791+
792+ if ( in_array ( $ _FILES ['upiwc_file ' ]['type ' ], $ allowed_extensions ) ) {
793+ require_once ( ABSPATH . 'wp-admin/includes/media.php ' );
794+ require_once ( ABSPATH . 'wp-admin/includes/file.php ' );
795+ require_once ( ABSPATH . 'wp-admin/includes/image.php ' );
796+
797+ $ attachment_id = media_handle_upload ( 'upiwc_file ' , 0 );
798+
799+ if ( is_wp_error ( $ attachment_id ) ) {
800+ $ order ->add_order_note ( $ attachment_id ->get_error_message (), false );
801+ } else {
802+ $ order ->update_meta_data ( '_upiwc_order_attachment_id ' , $ attachment_id );
803+ $ order_note = __ ( 'Screenshot uploaded successfully. ' , 'upi-qr-code-payment-for-woocommerce ' );
804+ $ order ->add_order_note ( sprintf ( '%s <a href="%s" target="_blank">%s</a> ' , $ order_note , wp_get_attachment_url ( esc_attr ( $ attachment_id ) ), __ ( 'View ' , 'upi-qr-code-payment-for-woocommerce ' ) ), false );
805+ }
806+ } else {
807+ $ order ->add_order_note ( __ ( 'File type is not valid! ' , 'upi-qr-code-payment-for-woocommerce ' ), false );
808+ }
809+ }
810+
758811 $ order ->save ();
759812
760813 // add custom actions
0 commit comments