@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | } |
665 | 665 | |
666 | 666 | function wpinv_get_payment_key( $invoice_id = 0 ) { |
667 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
667 | + $invoice = new WPInv_Invoice( $invoice_id ); |
|
668 | 668 | return $invoice->get_key(); |
669 | 669 | } |
670 | 670 | |
@@ -1197,20 +1197,20 @@ discard block |
||
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | function wpinv_checkout_get_cc_info() { |
1200 | - $cc_info = array(); |
|
1201 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1202 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1203 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1204 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1205 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1206 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1207 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1208 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1209 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1210 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1211 | - |
|
1212 | - // Return cc info |
|
1213 | - return $cc_info; |
|
1200 | + $cc_info = array(); |
|
1201 | + $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1202 | + $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1203 | + $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1204 | + $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1205 | + $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1206 | + $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1207 | + $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1208 | + $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1209 | + $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1210 | + $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1211 | + |
|
1212 | + // Return cc info |
|
1213 | + return $cc_info; |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
@@ -1407,7 +1407,7 @@ discard block |
||
1407 | 1407 | $required_fields = wpinv_checkout_required_fields(); |
1408 | 1408 | |
1409 | 1409 | // Loop through required fields and show error messages |
1410 | - if ( !empty( $required_fields ) ) { |
|
1410 | + if ( !empty( $required_fields ) ) { |
|
1411 | 1411 | foreach ( $required_fields as $field_name => $value ) { |
1412 | 1412 | if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
1413 | 1413 | wpinv_set_error( $value['error_id'], $value['error_message'] ); |
@@ -1513,7 +1513,7 @@ discard block |
||
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | function wpinv_get_checkout_session() { |
1516 | - global $wpi_session; |
|
1516 | + global $wpi_session; |
|
1517 | 1517 | |
1518 | 1518 | return $wpi_session->get( 'wpinv_checkout' ); |
1519 | 1519 | } |
@@ -1865,57 +1865,57 @@ discard block |
||
1865 | 1865 | } |
1866 | 1866 | |
1867 | 1867 | function wpinv_get_invoice_id_by_key( $key ) { |
1868 | - global $wpdb; |
|
1868 | + global $wpdb; |
|
1869 | 1869 | |
1870 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1870 | + $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1871 | 1871 | |
1872 | - if ( $invoice_id != NULL ) |
|
1873 | - return $invoice_id; |
|
1872 | + if ( $invoice_id != NULL ) |
|
1873 | + return $invoice_id; |
|
1874 | 1874 | |
1875 | - return 0; |
|
1875 | + return 0; |
|
1876 | 1876 | } |
1877 | 1877 | |
1878 | 1878 | function wpinv_can_view_receipt( $invoice_key = '' ) { |
1879 | - $return = false; |
|
1880 | - |
|
1881 | - if ( empty( $invoice_key ) ) { |
|
1882 | - return $return; |
|
1883 | - } |
|
1884 | - |
|
1885 | - global $wpinv_receipt_args; |
|
1886 | - |
|
1887 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1888 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1889 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1890 | - } |
|
1891 | - |
|
1892 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1893 | - return $return; |
|
1894 | - } |
|
1895 | - |
|
1896 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1897 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1898 | - return $return; |
|
1899 | - } |
|
1900 | - |
|
1901 | - if ( is_user_logged_in() ) { |
|
1902 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1903 | - $return = true; |
|
1904 | - } |
|
1905 | - } |
|
1906 | - |
|
1907 | - $session = wpinv_get_checkout_session(); |
|
1908 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1909 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1910 | - |
|
1911 | - if ( wpinv_require_login_to_checkout() ) { |
|
1912 | - $return = $return && $check_key === $invoice_key; |
|
1913 | - } else { |
|
1914 | - $return = $check_key === $invoice_key; |
|
1915 | - } |
|
1916 | - } |
|
1917 | - |
|
1918 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1879 | + $return = false; |
|
1880 | + |
|
1881 | + if ( empty( $invoice_key ) ) { |
|
1882 | + return $return; |
|
1883 | + } |
|
1884 | + |
|
1885 | + global $wpinv_receipt_args; |
|
1886 | + |
|
1887 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1888 | + if ( isset( $_GET['invoice-id'] ) ) { |
|
1889 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1890 | + } |
|
1891 | + |
|
1892 | + if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1893 | + return $return; |
|
1894 | + } |
|
1895 | + |
|
1896 | + $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1897 | + if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1898 | + return $return; |
|
1899 | + } |
|
1900 | + |
|
1901 | + if ( is_user_logged_in() ) { |
|
1902 | + if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1903 | + $return = true; |
|
1904 | + } |
|
1905 | + } |
|
1906 | + |
|
1907 | + $session = wpinv_get_checkout_session(); |
|
1908 | + if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1909 | + $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1910 | + |
|
1911 | + if ( wpinv_require_login_to_checkout() ) { |
|
1912 | + $return = $return && $check_key === $invoice_key; |
|
1913 | + } else { |
|
1914 | + $return = $check_key === $invoice_key; |
|
1915 | + } |
|
1916 | + } |
|
1917 | + |
|
1918 | + return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1919 | 1919 | } |
1920 | 1920 | |
1921 | 1921 | function wpinv_pay_for_invoice() { |