@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | - include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 112 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | + include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $message = wpinv_email_style_body( $message ); |
| 190 | 190 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
| 191 | 191 | |
| 192 | - return $mailer->send( |
|
| 192 | + return $mailer->send( |
|
| 193 | 193 | $to, |
| 194 | 194 | $subject, |
| 195 | 195 | $message, |
@@ -12,207 +12,207 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Notes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Filter inovice notes. |
|
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | - |
|
| 24 | - // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | - |
|
| 28 | - // Count comments. |
|
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | - |
|
| 31 | - // Fires after notes are loaded. |
|
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Filters invoice notes query to only include our notes. |
|
| 37 | - * |
|
| 38 | - * @param WP_Comment_Query $query |
|
| 39 | - */ |
|
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | - |
|
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | - $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | - } else { |
|
| 46 | - |
|
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | - $query->query_vars['type__not_in'] = array(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $query; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Exclude notes from the comments feed. |
|
| 60 | - */ |
|
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Delete comments count cache whenever there is |
|
| 67 | - * new comment or the status of a comment changes. Cache |
|
| 68 | - * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | - * is called. |
|
| 70 | - */ |
|
| 71 | - public function delete_comments_count_cache() { |
|
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Remove invoice notes from wp_count_comments(). |
|
| 77 | - * |
|
| 78 | - * @since 2.2 |
|
| 79 | - * @param object $stats Comment stats. |
|
| 80 | - * @param int $post_id Post ID. |
|
| 81 | - * @return object |
|
| 82 | - */ |
|
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | - global $wpdb; |
|
| 85 | - |
|
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | - |
|
| 89 | - if ( ! $stats ) { |
|
| 90 | - $stats = array( |
|
| 91 | - 'total_comments' => 0, |
|
| 92 | - 'all' => 0, |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $count = $wpdb->get_results( |
|
| 96 | - " |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Filter inovice notes. |
|
| 21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | + |
|
| 24 | + // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | + add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | + add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | + |
|
| 28 | + // Count comments. |
|
| 29 | + add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | + |
|
| 31 | + // Fires after notes are loaded. |
|
| 32 | + do_action( 'wpinv_notes_init', $this ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Filters invoice notes query to only include our notes. |
|
| 37 | + * |
|
| 38 | + * @param WP_Comment_Query $query |
|
| 39 | + */ |
|
| 40 | + public function set_invoice_note_type( $query ) { |
|
| 41 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | + |
|
| 43 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | + $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | + } else { |
|
| 46 | + |
|
| 47 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | + $query->query_vars['type__not_in'] = array(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $query; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Exclude notes from the comments feed. |
|
| 60 | + */ |
|
| 61 | + function wpinv_comment_feed_where( $where ) { |
|
| 62 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Delete comments count cache whenever there is |
|
| 67 | + * new comment or the status of a comment changes. Cache |
|
| 68 | + * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | + * is called. |
|
| 70 | + */ |
|
| 71 | + public function delete_comments_count_cache() { |
|
| 72 | + delete_transient( 'getpaid_count_comments' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Remove invoice notes from wp_count_comments(). |
|
| 77 | + * |
|
| 78 | + * @since 2.2 |
|
| 79 | + * @param object $stats Comment stats. |
|
| 80 | + * @param int $post_id Post ID. |
|
| 81 | + * @return object |
|
| 82 | + */ |
|
| 83 | + public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | + global $wpdb; |
|
| 85 | + |
|
| 86 | + if ( empty( $post_id ) ) { |
|
| 87 | + $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | + |
|
| 89 | + if ( ! $stats ) { |
|
| 90 | + $stats = array( |
|
| 91 | + 'total_comments' => 0, |
|
| 92 | + 'all' => 0, |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $count = $wpdb->get_results( |
|
| 96 | + " |
|
| 97 | 97 | SELECT comment_approved, COUNT(*) AS num_comments |
| 98 | 98 | FROM {$wpdb->comments} |
| 99 | 99 | WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note') |
| 100 | 100 | GROUP BY comment_approved |
| 101 | 101 | ", |
| 102 | - ARRAY_A |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $approved = array( |
|
| 106 | - '0' => 'moderated', |
|
| 107 | - '1' => 'approved', |
|
| 108 | - 'spam' => 'spam', |
|
| 109 | - 'trash' => 'trash', |
|
| 110 | - 'post-trashed' => 'post-trashed', |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - foreach ( (array) $count as $row ) { |
|
| 114 | - // Don't count post-trashed toward totals. |
|
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | - $stats['all'] += $row['num_comments']; |
|
| 117 | - $stats['total_comments'] += $row['num_comments']; |
|
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | - $stats['total_comments'] += $row['num_comments']; |
|
| 120 | - } |
|
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $stats = (object) $stats; |
|
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | - } |
|
| 102 | + ARRAY_A |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $approved = array( |
|
| 106 | + '0' => 'moderated', |
|
| 107 | + '1' => 'approved', |
|
| 108 | + 'spam' => 'spam', |
|
| 109 | + 'trash' => 'trash', |
|
| 110 | + 'post-trashed' => 'post-trashed', |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + foreach ( (array) $count as $row ) { |
|
| 114 | + // Don't count post-trashed toward totals. |
|
| 115 | + if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | + $stats['all'] += $row['num_comments']; |
|
| 117 | + $stats['total_comments'] += $row['num_comments']; |
|
| 118 | + } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | + $stats['total_comments'] += $row['num_comments']; |
|
| 120 | + } |
|
| 121 | + if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ( $approved as $key ) { |
|
| 127 | + if ( empty( $stats[ $key ] ) ) { |
|
| 128 | + $stats[ $key ] = 0; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $stats = (object) $stats; |
|
| 133 | + set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $stats; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of invoice notes. |
|
| 142 | - * |
|
| 143 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | - * @return WP_Comment[] |
|
| 146 | - */ |
|
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | - |
|
| 149 | - // Default comment args. |
|
| 150 | - $args = array( |
|
| 151 | - 'post_id' => $invoice_id, |
|
| 152 | - 'orderby' => 'comment_ID', |
|
| 153 | - 'order' => 'ASC', |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - // Maybe only show customer comments. |
|
| 157 | - if ( $type == 'customer' ) { |
|
| 158 | - $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | - $args['meta_value'] = 1; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | - |
|
| 164 | - return get_comments( $args ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Saves an invoice comment. |
|
| 169 | - * |
|
| 170 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | - * @param string $note The note content. |
|
| 172 | - * @param string $note_author The name of the author of the note. |
|
| 173 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | - * @return int|false The new note's ID on success, false on failure. |
|
| 175 | - */ |
|
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | - |
|
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Insert the comment. |
|
| 182 | - */ |
|
| 183 | - $note_id = wp_insert_comment( |
|
| 184 | - wp_filter_comment( |
|
| 185 | - array( |
|
| 186 | - 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | - 'comment_content' => $note, |
|
| 188 | - 'comment_agent' => 'Invoicing', |
|
| 189 | - 'user_id' => get_current_user_id(), |
|
| 190 | - 'comment_author' => $note_author, |
|
| 191 | - 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | - 'comment_author_email' => $author_email, |
|
| 193 | - 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | - 'comment_type' => 'wpinv_note', |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | - |
|
| 201 | - // Are we notifying the customer? |
|
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | - return $note_id; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | - do_action( |
|
| 137 | + return $stats; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of invoice notes. |
|
| 142 | + * |
|
| 143 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | + * @return WP_Comment[] |
|
| 146 | + */ |
|
| 147 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | + |
|
| 149 | + // Default comment args. |
|
| 150 | + $args = array( |
|
| 151 | + 'post_id' => $invoice_id, |
|
| 152 | + 'orderby' => 'comment_ID', |
|
| 153 | + 'order' => 'ASC', |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + // Maybe only show customer comments. |
|
| 157 | + if ( $type == 'customer' ) { |
|
| 158 | + $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | + $args['meta_value'] = 1; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | + |
|
| 164 | + return get_comments( $args ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Saves an invoice comment. |
|
| 169 | + * |
|
| 170 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | + * @param string $note The note content. |
|
| 172 | + * @param string $note_author The name of the author of the note. |
|
| 173 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | + * @return int|false The new note's ID on success, false on failure. |
|
| 175 | + */ |
|
| 176 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | + |
|
| 178 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Insert the comment. |
|
| 182 | + */ |
|
| 183 | + $note_id = wp_insert_comment( |
|
| 184 | + wp_filter_comment( |
|
| 185 | + array( |
|
| 186 | + 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | + 'comment_content' => $note, |
|
| 188 | + 'comment_agent' => 'Invoicing', |
|
| 189 | + 'user_id' => get_current_user_id(), |
|
| 190 | + 'comment_author' => $note_author, |
|
| 191 | + 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | + 'comment_author_email' => $author_email, |
|
| 193 | + 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | + 'comment_type' => 'wpinv_note', |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | + |
|
| 201 | + // Are we notifying the customer? |
|
| 202 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | + return $note_id; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | + do_action( |
|
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
| 210 | - 'invoice_id' => $invoice->get_id(), |
|
| 211 | - 'user_note' => $note, |
|
| 210 | + 'invoice_id' => $invoice->get_id(), |
|
| 211 | + 'user_note' => $note, |
|
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | - return $note_id; |
|
| 216 | - } |
|
| 214 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | + return $note_id; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | } |
@@ -17,45 +17,45 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class BP_GetPaid_Component extends BP_Component { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Start the component setup process. |
|
| 22 | - * |
|
| 23 | - * @since 2.1.5 |
|
| 24 | - */ |
|
| 25 | - public function __construct() { |
|
| 26 | - parent::start( |
|
| 27 | - 'getpaid', |
|
| 28 | - 'GetPaid', |
|
| 29 | - buddypress()->plugin_dir, |
|
| 30 | - array( |
|
| 31 | - 'adminbar_myaccount_order' => 30, |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 34 | - } |
|
| 20 | + /** |
|
| 21 | + * Start the component setup process. |
|
| 22 | + * |
|
| 23 | + * @since 2.1.5 |
|
| 24 | + */ |
|
| 25 | + public function __construct() { |
|
| 26 | + parent::start( |
|
| 27 | + 'getpaid', |
|
| 28 | + 'GetPaid', |
|
| 29 | + buddypress()->plugin_dir, |
|
| 30 | + array( |
|
| 31 | + 'adminbar_myaccount_order' => 30, |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Set up component global variables. |
|
| 38 | - * |
|
| 39 | - * @since 2.1.5 |
|
| 40 | - * |
|
| 41 | - * |
|
| 42 | - * @param array $args { |
|
| 43 | - * All values are optional. |
|
| 44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
| 45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
| 46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
| 47 | - * component has a root directory (the slug will be overridden by the |
|
| 48 | - * post_name of the directory page). Default: the slug of the directory page |
|
| 49 | - * if one is found, otherwise an empty string. |
|
| 50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
| 51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
| 52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
| 53 | - * 'Search Groups...'. |
|
| 54 | - * @type array $global_tables Optional. An array of database table names. |
|
| 55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
| 56 | - * } |
|
| 57 | - */ |
|
| 58 | - public function setup_globals( $args = array() ) { |
|
| 37 | + * Set up component global variables. |
|
| 38 | + * |
|
| 39 | + * @since 2.1.5 |
|
| 40 | + * |
|
| 41 | + * |
|
| 42 | + * @param array $args { |
|
| 43 | + * All values are optional. |
|
| 44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
| 45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
| 46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
| 47 | + * component has a root directory (the slug will be overridden by the |
|
| 48 | + * post_name of the directory page). Default: the slug of the directory page |
|
| 49 | + * if one is found, otherwise an empty string. |
|
| 50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
| 51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
| 52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
| 53 | + * 'Search Groups...'. |
|
| 54 | + * @type array $global_tables Optional. An array of database table names. |
|
| 55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
| 56 | + * } |
|
| 57 | + */ |
|
| 58 | + public function setup_globals( $args = array() ) { |
|
| 59 | 59 | parent::setup_globals( |
| 60 | 60 | array( |
| 61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | 'has_directory' => false, |
| 65 | 65 | ) |
| 66 | 66 | ); |
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Set up component navigation. |
|
| 71 | - * |
|
| 72 | - * @since 2.1.5 |
|
| 73 | - * |
|
| 74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
| 75 | - * |
|
| 76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
| 77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
| 78 | - */ |
|
| 79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
| 80 | - |
|
| 81 | - // Abort if the integration is inactive. |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Set up component navigation. |
|
| 71 | + * |
|
| 72 | + * @since 2.1.5 |
|
| 73 | + * |
|
| 74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
| 75 | + * |
|
| 76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
| 77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
| 78 | + */ |
|
| 79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
| 80 | + |
|
| 81 | + // Abort if the integration is inactive. |
|
| 82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
| 83 | 83 | return; |
| 84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - // Determine user to use. |
|
| 92 | - $user_domain = bp_loggedin_user_domain(); |
|
| 93 | - $slug = 'getpaid'; |
|
| 94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
| 95 | - |
|
| 96 | - // Add 'Payments' to the main navigation. |
|
| 97 | - $main_nav = array( |
|
| 98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
| 99 | - 'slug' => $slug, |
|
| 100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
| 101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
| 102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
| 91 | + // Determine user to use. |
|
| 92 | + $user_domain = bp_loggedin_user_domain(); |
|
| 93 | + $slug = 'getpaid'; |
|
| 94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
| 95 | + |
|
| 96 | + // Add 'Payments' to the main navigation. |
|
| 97 | + $main_nav = array( |
|
| 98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
| 99 | + 'slug' => $slug, |
|
| 100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
| 101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
| 102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
| 103 | 103 | 'show_for_displayed_user' => false, |
| 104 | - 'item_css_id' => $this->id, |
|
| 105 | - 'parent_url' => $user_domain, |
|
| 106 | - 'parent_slug' => buddypress()->slug, |
|
| 107 | - ); |
|
| 104 | + 'item_css_id' => $this->id, |
|
| 105 | + 'parent_url' => $user_domain, |
|
| 106 | + 'parent_slug' => buddypress()->slug, |
|
| 107 | + ); |
|
| 108 | 108 | |
| 109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
| 109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
| 110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
| 111 | 111 | |
| 112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | 'parent_slug' => $slug, |
| 117 | 117 | 'position' => 10, |
| 118 | 118 | 'screen_function' => function() use ( $tab ) { |
| 119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
| 120 | - $this->display_current_tab(); |
|
| 119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
| 120 | + $this->display_current_tab(); |
|
| 121 | 121 | }, |
| 122 | 122 | 'show_for_displayed_user' => false, |
| 123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Set up the component entries in the WordPress Admin Bar. |
|
| 133 | - * |
|
| 134 | - * @since 2.1.5 |
|
| 135 | - * |
|
| 136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
| 137 | - * parameter array. |
|
| 138 | - * |
|
| 139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
| 140 | - * description. |
|
| 141 | - */ |
|
| 142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
| 128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
| 129 | + } |
|
| 143 | 130 | |
| 144 | - // Menus for logged in user. |
|
| 145 | - if ( is_user_logged_in() ) { |
|
| 146 | - |
|
| 147 | - // Setup the logged in user variables. |
|
| 148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
| 131 | + /** |
|
| 132 | + * Set up the component entries in the WordPress Admin Bar. |
|
| 133 | + * |
|
| 134 | + * @since 2.1.5 |
|
| 135 | + * |
|
| 136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
| 137 | + * parameter array. |
|
| 138 | + * |
|
| 139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
| 140 | + * description. |
|
| 141 | + */ |
|
| 142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
| 143 | + |
|
| 144 | + // Menus for logged in user. |
|
| 145 | + if ( is_user_logged_in() ) { |
|
| 146 | + |
|
| 147 | + // Setup the logged in user variables. |
|
| 148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
| 149 | 149 | |
| 150 | 150 | // Add the "Payments" sub menu. |
| 151 | 151 | $wp_admin_nav[] = array( |
@@ -168,48 +168,48 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Retrieves the current tab. |
|
| 176 | - * |
|
| 177 | - * @since 2.1.5 |
|
| 178 | - */ |
|
| 179 | - public function get_current_tab() { |
|
| 180 | - global $getpaid_bp_current_tab; |
|
| 181 | - |
|
| 182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
| 183 | - return array( |
|
| 184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
| 185 | - 'content' => '[wpinv_history]', |
|
| 186 | - 'icon' => 'fas fa-file-invoice', |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $getpaid_bp_current_tab; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Displays the current tab. |
|
| 195 | - * |
|
| 196 | - * @since 2.1.5 |
|
| 197 | - */ |
|
| 198 | - public function display_current_tab() { |
|
| 199 | - |
|
| 200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
| 201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
| 171 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Retrieves the current tab. |
|
| 176 | + * |
|
| 177 | + * @since 2.1.5 |
|
| 178 | + */ |
|
| 179 | + public function get_current_tab() { |
|
| 180 | + global $getpaid_bp_current_tab; |
|
| 181 | + |
|
| 182 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
| 183 | + return array( |
|
| 184 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
| 185 | + 'content' => '[wpinv_history]', |
|
| 186 | + 'icon' => 'fas fa-file-invoice', |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $getpaid_bp_current_tab; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Displays the current tab. |
|
| 195 | + * |
|
| 196 | + * @since 2.1.5 |
|
| 197 | + */ |
|
| 198 | + public function display_current_tab() { |
|
| 199 | + |
|
| 200 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
| 201 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
| 202 | 202 | |
| 203 | 203 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Handles the actual display of the current tab. |
|
| 208 | - * |
|
| 209 | - * @since 2.1.5 |
|
| 210 | - */ |
|
| 211 | - public function handle_display_current_tab() { |
|
| 212 | - getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
| 213 | - } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Handles the actual display of the current tab. |
|
| 208 | + * |
|
| 209 | + * @since 2.1.5 |
|
| 210 | + */ |
|
| 211 | + public function handle_display_current_tab() { |
|
| 212 | + getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | } |
@@ -15,31 +15,31 @@ discard block |
||
| 15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Class constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct() { |
|
| 18 | + * Class constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct() { |
|
| 21 | 21 | parent::__construct(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * Returns the API URL. |
|
| 26 | - * |
|
| 27 | - * |
|
| 28 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function get_api_url( $invoice ) { |
|
| 25 | + * Returns the API URL. |
|
| 26 | + * |
|
| 27 | + * |
|
| 28 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function get_api_url( $invoice ) { |
|
| 32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Communicates with authorize.net |
|
| 37 | - * |
|
| 38 | - * |
|
| 39 | - * @param array $post Data to post. |
|
| 36 | + * Communicates with authorize.net |
|
| 37 | + * |
|
| 38 | + * |
|
| 39 | + * @param array $post Data to post. |
|
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | - * @return stdClass|WP_Error |
|
| 42 | - */ |
|
| 41 | + * @return stdClass|WP_Error |
|
| 42 | + */ |
|
| 43 | 43 | public function post( $post, $invoice ) { |
| 44 | 44 | |
| 45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Returns the API authentication params. |
|
| 93 | - * |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function get_auth_params() { |
|
| 92 | + * Returns the API authentication params. |
|
| 93 | + * |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function get_auth_params() { |
|
| 98 | 98 | |
| 99 | 99 | return array( |
| 100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Cancels a subscription remotely |
|
| 108 | - * |
|
| 109 | - * |
|
| 110 | - * @param WPInv_Subscription $subscription Subscription. |
|
| 107 | + * Cancels a subscription remotely |
|
| 108 | + * |
|
| 109 | + * |
|
| 110 | + * @param WPInv_Subscription $subscription Subscription. |
|
| 111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
| 112 | - */ |
|
| 113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 112 | + */ |
|
| 113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
| 114 | 114 | |
| 115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * Processes ipns. |
|
| 130 | - * |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - public function verify_ipn() { |
|
| 129 | + * Processes ipns. |
|
| 130 | + * |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + public function verify_ipn() { |
|
| 134 | 134 | |
| 135 | 135 | $this->maybe_process_old_ipn(); |
| 136 | 136 | |
| 137 | 137 | // Validate the IPN. |
| 138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * Validates IPN invoices. |
|
| 179 | - * |
|
| 178 | + * Validates IPN invoices. |
|
| 179 | + * |
|
| 180 | 180 | * @param WPInv_Invoice $invoice |
| 181 | 181 | * @param object $payload |
| 182 | - * @return void |
|
| 183 | - */ |
|
| 184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 182 | + * @return void |
|
| 183 | + */ |
|
| 184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
| 186 | 186 | exit; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * Process subscriptio IPNS. |
|
| 192 | - * |
|
| 193 | - * @return void |
|
| 194 | - */ |
|
| 195 | - public function maybe_process_old_ipn() { |
|
| 191 | + * Process subscriptio IPNS. |
|
| 192 | + * |
|
| 193 | + * @return void |
|
| 194 | + */ |
|
| 195 | + public function maybe_process_old_ipn() { |
|
| 196 | 196 | |
| 197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
| 198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Validates the old IPN signature. |
|
| 237 | + * Validates the old IPN signature. |
|
| 238 | 238 | * |
| 239 | 239 | * @param array $posted |
| 240 | - */ |
|
| 241 | - public function validate_old_ipn_signature( $posted ) { |
|
| 240 | + */ |
|
| 241 | + public function validate_old_ipn_signature( $posted ) { |
|
| 242 | 242 | |
| 243 | 243 | $signature = $this->get_option( 'signature_key' ); |
| 244 | 244 | if ( ! empty( $signature ) ) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Check Authorize.NET IPN validity. |
|
| 260 | - */ |
|
| 261 | - public function validate_ipn() { |
|
| 259 | + * Check Authorize.NET IPN validity. |
|
| 260 | + */ |
|
| 261 | + public function validate_ipn() { |
|
| 262 | 262 | |
| 263 | 263 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
| 264 | 264 | |
@@ -12,473 +12,473 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $id = 'paypal'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Payment method object. |
|
| 24 | - * |
|
| 25 | - * @var GetPaid_Paypal_Gateway |
|
| 26 | - */ |
|
| 27 | - protected $gateway; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Class constructor. |
|
| 31 | - * |
|
| 32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | - */ |
|
| 34 | - public function __construct( $gateway ) { |
|
| 35 | - $this->gateway = $gateway; |
|
| 36 | - $this->verify_ipn(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes ipns and marks payments as complete. |
|
| 41 | - * |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function verify_ipn() { |
|
| 45 | - |
|
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 47 | - |
|
| 48 | - // Validate the IPN. |
|
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Process the IPN. |
|
| 54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | - |
|
| 57 | - // Abort if it was not paid by our gateway. |
|
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | - |
|
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 68 | - |
|
| 69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | - wp_die( 'Processed', 200 ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Retrieves IPN Invoice. |
|
| 82 | - * |
|
| 83 | - * @param array $posted |
|
| 84 | - * @return WPInv_Invoice |
|
| 85 | - */ |
|
| 86 | - protected function get_ipn_invoice( $posted ) { |
|
| 87 | - |
|
| 88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 89 | - |
|
| 90 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | - |
|
| 93 | - if ( $invoice->exists() ) { |
|
| 94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 95 | - return $invoice; |
|
| 96 | - } |
|
| 15 | + /** |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $id = 'paypal'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Payment method object. |
|
| 24 | + * |
|
| 25 | + * @var GetPaid_Paypal_Gateway |
|
| 26 | + */ |
|
| 27 | + protected $gateway; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Class constructor. |
|
| 31 | + * |
|
| 32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | + */ |
|
| 34 | + public function __construct( $gateway ) { |
|
| 35 | + $this->gateway = $gateway; |
|
| 36 | + $this->verify_ipn(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes ipns and marks payments as complete. |
|
| 41 | + * |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function verify_ipn() { |
|
| 45 | + |
|
| 46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 47 | + |
|
| 48 | + // Validate the IPN. |
|
| 49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Process the IPN. |
|
| 54 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | + |
|
| 57 | + // Abort if it was not paid by our gateway. |
|
| 58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | + |
|
| 66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 68 | + |
|
| 69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | + wp_die( 'Processed', 200 ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Retrieves IPN Invoice. |
|
| 82 | + * |
|
| 83 | + * @param array $posted |
|
| 84 | + * @return WPInv_Invoice |
|
| 85 | + */ |
|
| 86 | + protected function get_ipn_invoice( $posted ) { |
|
| 87 | + |
|
| 88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 89 | + |
|
| 90 | + if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | + |
|
| 93 | + if ( $invoice->exists() ) { |
|
| 94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 95 | + return $invoice; |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Check PayPal IPN validity. |
|
| 105 | - */ |
|
| 106 | - protected function validate_ipn() { |
|
| 99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Check PayPal IPN validity. |
|
| 105 | + */ |
|
| 106 | + protected function validate_ipn() { |
|
| 107 | 107 | |
| 108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 109 | - |
|
| 110 | - // Retrieve the associated invoice. |
|
| 111 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 113 | - |
|
| 114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Validate the IPN. |
|
| 119 | - $posted['cmd'] = '_notify-validate'; |
|
| 120 | - |
|
| 121 | - // Send back post vars to paypal. |
|
| 122 | - $params = array( |
|
| 123 | - 'body' => $posted, |
|
| 124 | - 'timeout' => 60, |
|
| 125 | - 'httpversion' => '1.1', |
|
| 126 | - 'compress' => false, |
|
| 127 | - 'decompress' => false, |
|
| 128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 129 | - ); |
|
| 130 | - |
|
| 131 | - // Post back to get a response. |
|
| 132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 133 | - |
|
| 134 | - // Check to see if the request was valid. |
|
| 135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 137 | - return true; |
|
| 138 | - } |
|
| 108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 109 | + |
|
| 110 | + // Retrieve the associated invoice. |
|
| 111 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 113 | + |
|
| 114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // Validate the IPN. |
|
| 119 | + $posted['cmd'] = '_notify-validate'; |
|
| 120 | + |
|
| 121 | + // Send back post vars to paypal. |
|
| 122 | + $params = array( |
|
| 123 | + 'body' => $posted, |
|
| 124 | + 'timeout' => 60, |
|
| 125 | + 'httpversion' => '1.1', |
|
| 126 | + 'compress' => false, |
|
| 127 | + 'decompress' => false, |
|
| 128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 129 | + ); |
|
| 130 | + |
|
| 131 | + // Post back to get a response. |
|
| 132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 133 | + |
|
| 134 | + // Check to see if the request was valid. |
|
| 135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 136 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if ( is_wp_error( $response ) ) { |
|
| 141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 140 | + if ( is_wp_error( $response ) ) { |
|
| 141 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 146 | - return false; |
|
| 145 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 146 | + return false; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Check currency from IPN matches the invoice. |
|
| 152 | - * |
|
| 153 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 154 | - * @param string $currency currency to validate. |
|
| 155 | - */ |
|
| 156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 150 | + /** |
|
| 151 | + * Check currency from IPN matches the invoice. |
|
| 152 | + * |
|
| 153 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 154 | + * @param string $currency currency to validate. |
|
| 155 | + */ |
|
| 156 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 157 | 157 | |
| 158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 158 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | 159 | |
| 160 | - /* translators: %s: currency code. */ |
|
| 161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 160 | + /* translators: %s: currency code. */ |
|
| 161 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 162 | 162 | |
| 163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 164 | - } |
|
| 163 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 167 | - } |
|
| 166 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Check payment amount from IPN matches the invoice. |
|
| 171 | - * |
|
| 172 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 173 | - * @param float $amount amount to validate. |
|
| 174 | - */ |
|
| 175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 169 | + /** |
|
| 170 | + * Check payment amount from IPN matches the invoice. |
|
| 171 | + * |
|
| 172 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 173 | + * @param float $amount amount to validate. |
|
| 174 | + */ |
|
| 175 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 176 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 177 | 177 | |
| 178 | - /* translators: %s: Amount. */ |
|
| 179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 178 | + /* translators: %s: Amount. */ |
|
| 179 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 180 | 180 | |
| 181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 182 | - } |
|
| 181 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 185 | - } |
|
| 184 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Verify receiver email from PayPal. |
|
| 189 | - * |
|
| 190 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 191 | - * @param string $receiver_email Email to validate. |
|
| 192 | - */ |
|
| 193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 187 | + /** |
|
| 188 | + * Verify receiver email from PayPal. |
|
| 189 | + * |
|
| 190 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 191 | + * @param string $receiver_email Email to validate. |
|
| 192 | + */ |
|
| 193 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 194 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 195 | 195 | |
| 196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 196 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 197 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 198 | 198 | |
| 199 | - /* translators: %s: email address . */ |
|
| 200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 199 | + /* translators: %s: email address . */ |
|
| 200 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 201 | 201 | |
| 202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 203 | - } |
|
| 202 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 206 | - } |
|
| 205 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Handles one time payments. |
|
| 210 | - * |
|
| 211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | - * @param array $posted Posted data. |
|
| 213 | - */ |
|
| 214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 208 | + /** |
|
| 209 | + * Handles one time payments. |
|
| 210 | + * |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | + * @param array $posted Posted data. |
|
| 213 | + */ |
|
| 214 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 215 | 215 | |
| 216 | - // Collect payment details |
|
| 217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 216 | + // Collect payment details |
|
| 217 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
| 218 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 219 | 219 | |
| 220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 220 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 221 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 222 | 222 | |
| 223 | - // Update the transaction id. |
|
| 224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 226 | - $invoice->save(); |
|
| 227 | - } |
|
| 223 | + // Update the transaction id. |
|
| 224 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 225 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 226 | + $invoice->save(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
| 229 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
| 230 | 230 | |
| 231 | - // Process a refund. |
|
| 232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 231 | + // Process a refund. |
|
| 232 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 233 | 233 | |
| 234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 235 | 235 | |
| 236 | - if ( ! $invoice->is_refunded() ) { |
|
| 237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 238 | - } |
|
| 236 | + if ( ! $invoice->is_refunded() ) { |
|
| 237 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
| 241 | - } |
|
| 240 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - // Process payments. |
|
| 244 | - if ( $payment_status == 'completed' ) { |
|
| 243 | + // Process payments. |
|
| 244 | + if ( $payment_status == 'completed' ) { |
|
| 245 | 245 | |
| 246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 248 | - } |
|
| 246 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 247 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 251 | 251 | |
| 252 | - $note = ''; |
|
| 252 | + $note = ''; |
|
| 253 | 253 | |
| 254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 256 | - } |
|
| 254 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 255 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 260 | - } |
|
| 258 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
| 259 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 262 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 263 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 264 | 264 | |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // Pending payments. |
|
| 268 | - if ( $payment_status == 'pending' ) { |
|
| 267 | + // Pending payments. |
|
| 268 | + if ( $payment_status == 'pending' ) { |
|
| 269 | 269 | |
| 270 | - /* translators: %s: pending reason. */ |
|
| 271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 270 | + /* translators: %s: pending reason. */ |
|
| 271 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 272 | 272 | |
| 273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 274 | - } |
|
| 273 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /* translators: %s: payment status. */ |
|
| 277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 276 | + /* translators: %s: payment status. */ |
|
| 277 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 278 | 278 | |
| 279 | - } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Handles one time payments. |
|
| 283 | - * |
|
| 284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 285 | - * @param array $posted Posted data. |
|
| 286 | - */ |
|
| 287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 289 | - } |
|
| 281 | + /** |
|
| 282 | + * Handles one time payments. |
|
| 283 | + * |
|
| 284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 285 | + * @param array $posted Posted data. |
|
| 286 | + */ |
|
| 287 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 288 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Handles subscription sign ups. |
|
| 293 | - * |
|
| 294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 295 | - * @param array $posted Posted data. |
|
| 296 | - */ |
|
| 297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 291 | + /** |
|
| 292 | + * Handles subscription sign ups. |
|
| 293 | + * |
|
| 294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 295 | + * @param array $posted Posted data. |
|
| 296 | + */ |
|
| 297 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 298 | 298 | |
| 299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
| 299 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
| 300 | 300 | |
| 301 | - // Make sure the invoice has a subscription. |
|
| 302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 301 | + // Make sure the invoice has a subscription. |
|
| 302 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 303 | 303 | |
| 304 | - if ( empty( $subscription ) ) { |
|
| 305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 306 | - } |
|
| 304 | + if ( empty( $subscription ) ) { |
|
| 305 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 308 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 309 | 309 | |
| 310 | - // Validate the IPN. |
|
| 311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 310 | + // Validate the IPN. |
|
| 311 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 312 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 313 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 314 | 314 | |
| 315 | - // Activate the subscription. |
|
| 316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 320 | - $subscription->activate(); |
|
| 315 | + // Activate the subscription. |
|
| 316 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 317 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 318 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 319 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 320 | + $subscription->activate(); |
|
| 321 | 321 | |
| 322 | - // Set the transaction id. |
|
| 323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 326 | - } |
|
| 322 | + // Set the transaction id. |
|
| 323 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 324 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 325 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - // Update the payment status. |
|
| 329 | - $invoice->mark_paid(); |
|
| 328 | + // Update the payment status. |
|
| 329 | + $invoice->mark_paid(); |
|
| 330 | 330 | |
| 331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 331 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 332 | 332 | |
| 333 | - wpinv_error_log( 'Subscription started.', false ); |
|
| 334 | - } |
|
| 333 | + wpinv_error_log( 'Subscription started.', false ); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * Handles subscription renewals. |
|
| 338 | - * |
|
| 339 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 340 | - * @param array $posted Posted data. |
|
| 341 | - */ |
|
| 342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 336 | + /** |
|
| 337 | + * Handles subscription renewals. |
|
| 338 | + * |
|
| 339 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 340 | + * @param array $posted Posted data. |
|
| 341 | + */ |
|
| 342 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 343 | 343 | |
| 344 | - // Make sure the invoice has a subscription. |
|
| 345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 344 | + // Make sure the invoice has a subscription. |
|
| 345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 346 | 346 | |
| 347 | - if ( empty( $subscription ) ) { |
|
| 348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 349 | - } |
|
| 347 | + if ( empty( $subscription ) ) { |
|
| 348 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 351 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 352 | 352 | |
| 353 | - // PayPal sends a subscr_payment for the first payment too. |
|
| 354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 353 | + // PayPal sends a subscr_payment for the first payment too. |
|
| 354 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 355 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 356 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 357 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 358 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 359 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 360 | 360 | |
| 361 | - foreach ( $dates as $date ) { |
|
| 361 | + foreach ( $dates as $date ) { |
|
| 362 | 362 | |
| 363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 364 | - continue; |
|
| 365 | - } |
|
| 363 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 364 | + continue; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 370 | - } |
|
| 367 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 368 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 369 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - return $invoice->mark_paid(); |
|
| 373 | - |
|
| 374 | - } |
|
| 372 | + return $invoice->mark_paid(); |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 377 | - |
|
| 378 | - // Abort if the payment is already recorded. |
|
| 379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $args = array( |
|
| 384 | - 'transaction_id' => $posted['txn_id'], |
|
| 385 | - 'gateway' => $this->id, |
|
| 386 | - ); |
|
| 387 | - |
|
| 388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 376 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 377 | + |
|
| 378 | + // Abort if the payment is already recorded. |
|
| 379 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 380 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $args = array( |
|
| 384 | + 'transaction_id' => $posted['txn_id'], |
|
| 385 | + 'gateway' => $this->id, |
|
| 386 | + ); |
|
| 387 | + |
|
| 388 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 389 | 389 | |
| 390 | - if ( empty( $invoice ) ) { |
|
| 391 | - return; |
|
| 392 | - } |
|
| 390 | + if ( empty( $invoice ) ) { |
|
| 391 | + return; |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 396 | 396 | |
| 397 | - $subscription->renew(); |
|
| 398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
| 397 | + $subscription->renew(); |
|
| 398 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
| 399 | 399 | |
| 400 | - } |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * Handles subscription cancelations. |
|
| 404 | - * |
|
| 405 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 406 | - */ |
|
| 407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 402 | + /** |
|
| 403 | + * Handles subscription cancelations. |
|
| 404 | + * |
|
| 405 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 406 | + */ |
|
| 407 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 408 | 408 | |
| 409 | - // Make sure the invoice has a subscription. |
|
| 410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 411 | - |
|
| 412 | - if ( empty( $subscription ) ) { |
|
| 413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 417 | - $subscription->cancel(); |
|
| 418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 409 | + // Make sure the invoice has a subscription. |
|
| 410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 411 | + |
|
| 412 | + if ( empty( $subscription ) ) { |
|
| 413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 417 | + $subscription->cancel(); |
|
| 418 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 419 | 419 | |
| 420 | - } |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - /** |
|
| 423 | - * Handles subscription completions. |
|
| 424 | - * |
|
| 425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 426 | - * @param array $posted Posted data. |
|
| 427 | - */ |
|
| 428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 422 | + /** |
|
| 423 | + * Handles subscription completions. |
|
| 424 | + * |
|
| 425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 426 | + * @param array $posted Posted data. |
|
| 427 | + */ |
|
| 428 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 429 | 429 | |
| 430 | - // Make sure the invoice has a subscription. |
|
| 431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 430 | + // Make sure the invoice has a subscription. |
|
| 431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 432 | 432 | |
| 433 | - if ( empty( $subscription ) ) { |
|
| 434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 435 | - } |
|
| 433 | + if ( empty( $subscription ) ) { |
|
| 434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 438 | - $subscription->complete(); |
|
| 439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
| 437 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 438 | + $subscription->complete(); |
|
| 439 | + wpinv_error_log( 'Subscription completed.', false ); |
|
| 440 | 440 | |
| 441 | - } |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | - /** |
|
| 444 | - * Handles subscription fails. |
|
| 445 | - * |
|
| 446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 447 | - * @param array $posted Posted data. |
|
| 448 | - */ |
|
| 449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 443 | + /** |
|
| 444 | + * Handles subscription fails. |
|
| 445 | + * |
|
| 446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 447 | + * @param array $posted Posted data. |
|
| 448 | + */ |
|
| 449 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 450 | 450 | |
| 451 | - // Make sure the invoice has a subscription. |
|
| 452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 451 | + // Make sure the invoice has a subscription. |
|
| 452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 453 | 453 | |
| 454 | - if ( empty( $subscription ) ) { |
|
| 455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 456 | - } |
|
| 454 | + if ( empty( $subscription ) ) { |
|
| 455 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 459 | - $subscription->failing(); |
|
| 460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 458 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 459 | + $subscription->failing(); |
|
| 460 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 461 | 461 | |
| 462 | - } |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - /** |
|
| 465 | - * Handles subscription suspensions. |
|
| 466 | - * |
|
| 467 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 468 | - * @param array $posted Posted data. |
|
| 469 | - */ |
|
| 470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 464 | + /** |
|
| 465 | + * Handles subscription suspensions. |
|
| 466 | + * |
|
| 467 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 468 | + * @param array $posted Posted data. |
|
| 469 | + */ |
|
| 470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 471 | 471 | |
| 472 | - // Make sure the invoice has a subscription. |
|
| 473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 472 | + // Make sure the invoice has a subscription. |
|
| 473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 474 | 474 | |
| 475 | - if ( empty( $subscription ) ) { |
|
| 476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 480 | - $subscription->cancel(); |
|
| 481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 482 | - } |
|
| 475 | + if ( empty( $subscription ) ) { |
|
| 476 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 480 | + $subscription->cancel(); |
|
| 481 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | 484 | } |
@@ -13,58 +13,58 @@ discard block |
||
| 13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'authorizenet'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 4; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Endpoint for requests from Authorize.net. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $notify_url; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Endpoint for requests to Authorize.net. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 37 | + * Endpoint for requests from Authorize.net. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $notify_url; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Endpoint for requests to Authorize.net. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $endpoint; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Class constructor. |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 65 | + * Class constructor. |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | 68 | |
| 69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
| 70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Displays the payment method select field. |
|
| 80 | - * |
|
| 81 | - * @param int $invoice_id 0 or invoice id. |
|
| 82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | - */ |
|
| 79 | + * Displays the payment method select field. |
|
| 80 | + * |
|
| 81 | + * @param int $invoice_id 0 or invoice id. |
|
| 82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | + */ |
|
| 84 | 84 | public function payment_fields( $invoice_id, $form ) { |
| 85 | 85 | |
| 86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Creates a customer profile. |
|
| 95 | - * |
|
| 96 | - * |
|
| 97 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 94 | + * Creates a customer profile. |
|
| 95 | + * |
|
| 96 | + * |
|
| 97 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 98 | 98 | * @param array $submission_data Posted checkout fields. |
| 99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
| 100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 101 | - * @return string|WP_Error Payment profile id. |
|
| 102 | - */ |
|
| 103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 101 | + * @return string|WP_Error Payment profile id. |
|
| 102 | + */ |
|
| 103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 104 | 104 | |
| 105 | 105 | // Remove non-digits from the number |
| 106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Retrieves a customer profile. |
|
| 186 | - * |
|
| 187 | - * |
|
| 188 | - * @param string $profile_id profile id. |
|
| 189 | - * @return string|WP_Error Profile id. |
|
| 185 | + * Retrieves a customer profile. |
|
| 186 | + * |
|
| 187 | + * |
|
| 188 | + * @param string $profile_id profile id. |
|
| 189 | + * @return string|WP_Error Profile id. |
|
| 190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 191 | - */ |
|
| 192 | - public function get_customer_profile( $profile_id ) { |
|
| 191 | + */ |
|
| 192 | + public function get_customer_profile( $profile_id ) { |
|
| 193 | 193 | |
| 194 | 194 | // Generate args. |
| 195 | 195 | $args = array( |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Creates a customer profile. |
|
| 208 | - * |
|
| 209 | - * |
|
| 207 | + * Creates a customer profile. |
|
| 208 | + * |
|
| 209 | + * |
|
| 210 | 210 | * @param string $profile_id profile id. |
| 211 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 212 | 212 | * @param array $submission_data Posted checkout fields. |
| 213 | 213 | * @param bool $save Whether or not to save the payment as a token. |
| 214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 215 | - * @return string|WP_Error Profile id. |
|
| 216 | - */ |
|
| 217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 215 | + * @return string|WP_Error Profile id. |
|
| 216 | + */ |
|
| 217 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 218 | 218 | |
| 219 | 219 | // Remove non-digits from the number |
| 220 | 220 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | - * Retrieves payment details from cache. |
|
| 306 | - * |
|
| 307 | - * |
|
| 305 | + * Retrieves payment details from cache. |
|
| 306 | + * |
|
| 307 | + * |
|
| 308 | 308 | * @param array $payment_details. |
| 309 | - * @return array|false Profile id. |
|
| 310 | - */ |
|
| 311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 309 | + * @return array|false Profile id. |
|
| 310 | + */ |
|
| 311 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 312 | 312 | |
| 313 | 313 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
| 314 | 314 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | - * Securely adds payment details to cache. |
|
| 337 | - * |
|
| 338 | - * |
|
| 336 | + * Securely adds payment details to cache. |
|
| 337 | + * |
|
| 338 | + * |
|
| 339 | 339 | * @param array $payment_details. |
| 340 | 340 | * @param string $payment_profile_id. |
| 341 | - */ |
|
| 342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 341 | + */ |
|
| 342 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 343 | 343 | |
| 344 | 344 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
| 345 | 345 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -351,15 +351,15 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
| 354 | - * Retrieves a customer payment profile. |
|
| 355 | - * |
|
| 356 | - * |
|
| 357 | - * @param string $customer_profile_id customer profile id. |
|
| 354 | + * Retrieves a customer payment profile. |
|
| 355 | + * |
|
| 356 | + * |
|
| 357 | + * @param string $customer_profile_id customer profile id. |
|
| 358 | 358 | * @param string $payment_profile_id payment profile id. |
| 359 | - * @return string|WP_Error Profile id. |
|
| 359 | + * @return string|WP_Error Profile id. |
|
| 360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 361 | - */ |
|
| 362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 361 | + */ |
|
| 362 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 363 | 363 | |
| 364 | 364 | // Generate args. |
| 365 | 365 | $args = array( |
@@ -375,15 +375,15 @@ discard block |
||
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | - * Charges a customer payment profile. |
|
| 379 | - * |
|
| 378 | + * Charges a customer payment profile. |
|
| 379 | + * |
|
| 380 | 380 | * @param string $customer_profile_id customer profile id. |
| 381 | 381 | * @param string $payment_profile_id payment profile id. |
| 382 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 382 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 384 | - * @return WP_Error|object |
|
| 385 | - */ |
|
| 386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 384 | + * @return WP_Error|object |
|
| 385 | + */ |
|
| 386 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 387 | 387 | |
| 388 | 388 | // Generate args. |
| 389 | 389 | $args = array( |
@@ -429,41 +429,41 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
| 432 | - * Processes a customer charge. |
|
| 433 | - * |
|
| 432 | + * Processes a customer charge. |
|
| 433 | + * |
|
| 434 | 434 | * @param stdClass $result Api response. |
| 435 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 436 | - */ |
|
| 437 | - public function process_charge_response( $result, $invoice ) { |
|
| 435 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 436 | + */ |
|
| 437 | + public function process_charge_response( $result, $invoice ) { |
|
| 438 | 438 | |
| 439 | 439 | wpinv_clear_errors(); |
| 440 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
| 440 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
| 441 | 441 | |
| 442 | - // Succeeded. |
|
| 443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 442 | + // Succeeded. |
|
| 443 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
| 444 | 444 | |
| 445 | - // Maybe set a transaction id. |
|
| 446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 448 | - } |
|
| 445 | + // Maybe set a transaction id. |
|
| 446 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 447 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 450 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 451 | 451 | |
| 452 | - if ( 1 == $response_code ) { |
|
| 453 | - return $invoice->mark_paid(); |
|
| 454 | - } |
|
| 452 | + if ( 1 == $response_code ) { |
|
| 453 | + return $invoice->mark_paid(); |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 457 | - $invoice->add_note( |
|
| 456 | + $invoice->set_status( 'wpi-onhold' ); |
|
| 457 | + $invoice->add_note( |
|
| 458 | 458 | sprintf( |
| 459 | 459 | __( 'Held for review: %s', 'invoicing' ), |
| 460 | 460 | $result->transactionResponse->messages->message[0]->description |
| 461 | 461 | ) |
| 462 | - ); |
|
| 462 | + ); |
|
| 463 | 463 | |
| 464 | - return $invoice->save(); |
|
| 464 | + return $invoice->save(); |
|
| 465 | 465 | |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
| 469 | 469 | |
@@ -475,13 +475,13 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | - * Returns payment information. |
|
| 479 | - * |
|
| 480 | - * |
|
| 481 | - * @param array $card Card details. |
|
| 482 | - * @return array |
|
| 483 | - */ |
|
| 484 | - public function get_payment_information( $card ) { |
|
| 478 | + * Returns payment information. |
|
| 479 | + * |
|
| 480 | + * |
|
| 481 | + * @param array $card Card details. |
|
| 482 | + * @return array |
|
| 483 | + */ |
|
| 484 | + public function get_payment_information( $card ) { |
|
| 485 | 485 | return array( |
| 486 | 486 | |
| 487 | 487 | 'creditCard' => array( |
@@ -494,25 +494,25 @@ discard block |
||
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
| 497 | - * Returns the customer profile meta name. |
|
| 498 | - * |
|
| 499 | - * |
|
| 500 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 501 | - * @return string |
|
| 502 | - */ |
|
| 503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 497 | + * Returns the customer profile meta name. |
|
| 498 | + * |
|
| 499 | + * |
|
| 500 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 501 | + * @return string |
|
| 502 | + */ |
|
| 503 | + public function get_customer_profile_meta_name( $invoice ) { |
|
| 504 | 504 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | - * Validates the submitted data. |
|
| 509 | - * |
|
| 510 | - * |
|
| 511 | - * @param array $submission_data Posted checkout fields. |
|
| 508 | + * Validates the submitted data. |
|
| 509 | + * |
|
| 510 | + * |
|
| 511 | + * @param array $submission_data Posted checkout fields. |
|
| 512 | 512 | * @param WPInv_Invoice $invoice |
| 513 | - * @return WP_Error|string The payment profile id |
|
| 514 | - */ |
|
| 515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 513 | + * @return WP_Error|string The payment profile id |
|
| 514 | + */ |
|
| 515 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
| 516 | 516 | |
| 517 | 517 | // Validate authentication details. |
| 518 | 518 | $auth = $this->get_auth_params(); |
@@ -544,13 +544,13 @@ discard block |
||
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Returns invoice line items. |
|
| 548 | - * |
|
| 549 | - * |
|
| 550 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 551 | - * @return array |
|
| 552 | - */ |
|
| 553 | - public function get_line_items( $invoice ) { |
|
| 547 | + * Returns invoice line items. |
|
| 548 | + * |
|
| 549 | + * |
|
| 550 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 551 | + * @return array |
|
| 552 | + */ |
|
| 553 | + public function get_line_items( $invoice ) { |
|
| 554 | 554 | $items = array(); |
| 555 | 555 | |
| 556 | 556 | foreach ( $invoice->get_items() as $item ) { |
@@ -587,15 +587,15 @@ discard block |
||
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
| 590 | - * Process Payment. |
|
| 591 | - * |
|
| 592 | - * |
|
| 593 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 594 | - * @param array $submission_data Posted checkout fields. |
|
| 595 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 596 | - * @return array |
|
| 597 | - */ |
|
| 598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 590 | + * Process Payment. |
|
| 591 | + * |
|
| 592 | + * |
|
| 593 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 594 | + * @param array $submission_data Posted checkout fields. |
|
| 595 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 596 | + * @return array |
|
| 597 | + */ |
|
| 598 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 599 | 599 | |
| 600 | 600 | // Validate the submitted data. |
| 601 | 601 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -628,45 +628,45 @@ discard block |
||
| 628 | 628 | |
| 629 | 629 | exit; |
| 630 | 630 | |
| 631 | - } |
|
| 631 | + } |
|
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Processes the initial payment. |
|
| 635 | - * |
|
| 633 | + /** |
|
| 634 | + * Processes the initial payment. |
|
| 635 | + * |
|
| 636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
| 637 | - */ |
|
| 638 | - protected function process_initial_payment( $invoice ) { |
|
| 637 | + */ |
|
| 638 | + protected function process_initial_payment( $invoice ) { |
|
| 639 | 639 | |
| 640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 640 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 641 | 641 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
| 642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 642 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 643 | 643 | |
| 644 | - // Do we have an error? |
|
| 645 | - if ( is_wp_error( $result ) ) { |
|
| 646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 647 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 648 | - } |
|
| 644 | + // Do we have an error? |
|
| 645 | + if ( is_wp_error( $result ) ) { |
|
| 646 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 647 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - // Process the response. |
|
| 651 | - $this->process_charge_response( $result, $invoice ); |
|
| 650 | + // Process the response. |
|
| 651 | + $this->process_charge_response( $result, $invoice ); |
|
| 652 | 652 | |
| 653 | - if ( wpinv_get_errors() ) { |
|
| 654 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 655 | - } |
|
| 653 | + if ( wpinv_get_errors() ) { |
|
| 654 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 655 | + } |
|
| 656 | 656 | |
| 657 | - } |
|
| 657 | + } |
|
| 658 | 658 | |
| 659 | 659 | /** |
| 660 | - * Processes recurring payments. |
|
| 661 | - * |
|
| 660 | + * Processes recurring payments. |
|
| 661 | + * |
|
| 662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
| 663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
| 664 | - */ |
|
| 665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
| 664 | + */ |
|
| 665 | + public function process_subscription( $invoice, $subscriptions ) { |
|
| 666 | 666 | |
| 667 | 667 | // Check if there is an initial amount to charge. |
| 668 | 668 | if ( (float) $invoice->get_total() > 0 ) { |
| 669 | - $this->process_initial_payment( $invoice ); |
|
| 669 | + $this->process_initial_payment( $invoice ); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Activate the subscriptions. |
@@ -684,36 +684,36 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - // Redirect to the success page. |
|
| 687 | + // Redirect to the success page. |
|
| 688 | 688 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
| 689 | 689 | |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * (Maybe) renews an authorize.net subscription profile. |
|
| 694 | - * |
|
| 695 | - * |
|
| 692 | + /** |
|
| 693 | + * (Maybe) renews an authorize.net subscription profile. |
|
| 694 | + * |
|
| 695 | + * |
|
| 696 | 696 | * @param WPInv_Subscription $subscription |
| 697 | - */ |
|
| 698 | - public function maybe_renew_subscription( $subscription ) { |
|
| 697 | + */ |
|
| 698 | + public function maybe_renew_subscription( $subscription ) { |
|
| 699 | 699 | |
| 700 | 700 | // Ensure its our subscription && it's active. |
| 701 | 701 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
| 702 | 702 | $this->renew_subscription( $subscription ); |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | 707 | /** |
| 708 | - * Renews a subscription. |
|
| 709 | - * |
|
| 708 | + * Renews a subscription. |
|
| 709 | + * |
|
| 710 | 710 | * @param WPInv_Subscription $subscription |
| 711 | - */ |
|
| 712 | - public function renew_subscription( $subscription ) { |
|
| 711 | + */ |
|
| 712 | + public function renew_subscription( $subscription ) { |
|
| 713 | 713 | |
| 714 | - // Generate the renewal invoice. |
|
| 715 | - $new_invoice = $subscription->create_payment(); |
|
| 716 | - $old_invoice = $subscription->get_parent_payment(); |
|
| 714 | + // Generate the renewal invoice. |
|
| 715 | + $new_invoice = $subscription->create_payment(); |
|
| 716 | + $old_invoice = $subscription->get_parent_payment(); |
|
| 717 | 717 | |
| 718 | 718 | if ( empty( $new_invoice ) ) { |
| 719 | 719 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -722,37 +722,37 @@ discard block |
||
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | // Charge the payment method. |
| 725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 728 | - |
|
| 729 | - // Do we have an error? |
|
| 730 | - if ( is_wp_error( $result ) ) { |
|
| 731 | - |
|
| 732 | - $old_invoice->add_note( |
|
| 733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 734 | - true, |
|
| 735 | - false, |
|
| 736 | - true |
|
| 737 | - ); |
|
| 738 | - $subscription->failing(); |
|
| 739 | - return; |
|
| 740 | - |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Process the response. |
|
| 744 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 745 | - |
|
| 746 | - if ( wpinv_get_errors() ) { |
|
| 747 | - |
|
| 748 | - $old_invoice->add_note( |
|
| 749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 750 | - true, |
|
| 751 | - false, |
|
| 752 | - true |
|
| 753 | - ); |
|
| 754 | - $subscription->failing(); |
|
| 755 | - return; |
|
| 725 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 726 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 727 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 728 | + |
|
| 729 | + // Do we have an error? |
|
| 730 | + if ( is_wp_error( $result ) ) { |
|
| 731 | + |
|
| 732 | + $old_invoice->add_note( |
|
| 733 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 734 | + true, |
|
| 735 | + false, |
|
| 736 | + true |
|
| 737 | + ); |
|
| 738 | + $subscription->failing(); |
|
| 739 | + return; |
|
| 740 | + |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Process the response. |
|
| 744 | + $this->process_charge_response( $result, $new_invoice ); |
|
| 745 | + |
|
| 746 | + if ( wpinv_get_errors() ) { |
|
| 747 | + |
|
| 748 | + $old_invoice->add_note( |
|
| 749 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 750 | + true, |
|
| 751 | + false, |
|
| 752 | + true |
|
| 753 | + ); |
|
| 754 | + $subscription->failing(); |
|
| 755 | + return; |
|
| 756 | 756 | |
| 757 | 757 | } |
| 758 | 758 | |
@@ -761,13 +761,13 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
| 764 | - * Processes invoice addons. |
|
| 765 | - * |
|
| 766 | - * @param WPInv_Invoice $invoice |
|
| 767 | - * @param GetPaid_Form_Item[] $items |
|
| 768 | - * @return WPInv_Invoice |
|
| 769 | - */ |
|
| 770 | - public function process_addons( $invoice, $items ) { |
|
| 764 | + * Processes invoice addons. |
|
| 765 | + * |
|
| 766 | + * @param WPInv_Invoice $invoice |
|
| 767 | + * @param GetPaid_Form_Item[] $items |
|
| 768 | + * @return WPInv_Invoice |
|
| 769 | + */ |
|
| 770 | + public function process_addons( $invoice, $items ) { |
|
| 771 | 771 | |
| 772 | 772 | global $getpaid_authorize_addons; |
| 773 | 773 | |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | $invoice->recalculate_total(); |
| 787 | 787 | |
| 788 | 788 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
| 789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 789 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 790 | 790 | |
| 791 | 791 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
| 792 | 792 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -801,11 +801,11 @@ discard block |
||
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
| 804 | - * Processes invoice addons. |
|
| 805 | - * |
|
| 804 | + * Processes invoice addons. |
|
| 805 | + * |
|
| 806 | 806 | * @param array $args |
| 807 | - * @return array |
|
| 808 | - */ |
|
| 807 | + * @return array |
|
| 808 | + */ |
|
| 809 | 809 | public function filter_addons_request( $args ) { |
| 810 | 810 | |
| 811 | 811 | global $getpaid_authorize_addons; |
@@ -839,11 +839,11 @@ discard block |
||
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
| 842 | - * Filters the gateway settings. |
|
| 843 | - * |
|
| 844 | - * @param array $admin_settings |
|
| 845 | - */ |
|
| 846 | - public function admin_settings( $admin_settings ) { |
|
| 842 | + * Filters the gateway settings. |
|
| 843 | + * |
|
| 844 | + * @param array $admin_settings |
|
| 845 | + */ |
|
| 846 | + public function admin_settings( $admin_settings ) { |
|
| 847 | 847 | |
| 848 | 848 | $currencies = sprintf( |
| 849 | 849 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | 'readonly' => true, |
| 884 | 884 | ); |
| 885 | 885 | |
| 886 | - return $admin_settings; |
|
| 887 | - } |
|
| 886 | + return $admin_settings; |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | 889 | } |
@@ -13,65 +13,65 @@ discard block |
||
| 13 | 13 | class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'worldpay'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Payment method order. |
|
| 24 | - * |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 23 | + * Payment method order. |
|
| 24 | + * |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | 27 | public $order = 5; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Endpoint for requests from Worldpay. |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $notify_url; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Endpoint for requests to Worldpay. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 30 | + * Endpoint for requests from Worldpay. |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $notify_url; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Endpoint for requests to Worldpay. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | 41 | protected $endpoint; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * An array of features that this gateway supports. |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 44 | + * An array of features that this gateway supports. |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | 48 | protected $supports = array( 'sandbox' ); |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a subscription. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 65 | + * URL to view a subscription. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Class constructor. |
|
| 73 | - */ |
|
| 74 | - public function __construct() { |
|
| 72 | + * Class constructor. |
|
| 73 | + */ |
|
| 74 | + public function __construct() { |
|
| 75 | 75 | |
| 76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
| 77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * Process Payment. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | - * @param array $submission_data Posted checkout fields. |
|
| 93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 88 | + * Process Payment. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | + * @param array $submission_data Posted checkout fields. |
|
| 93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * Get the Worldpay request URL for an invoice. |
|
| 132 | - * |
|
| 133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_request_url( $invoice ) { |
|
| 131 | + * Get the Worldpay request URL for an invoice. |
|
| 132 | + * |
|
| 133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_request_url( $invoice ) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Get Worldpay Args for passing to Worldpay. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 152 | - |
|
| 153 | - return apply_filters( |
|
| 154 | - 'getpaid_worldpay_args', |
|
| 155 | - array( |
|
| 146 | + * Get Worldpay Args for passing to Worldpay. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + protected function get_worldpay_args( $invoice ) { |
|
| 152 | + |
|
| 153 | + return apply_filters( |
|
| 154 | + 'getpaid_worldpay_args', |
|
| 155 | + array( |
|
| 156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
| 157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
| 158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
| 178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
| 179 | 179 | ), |
| 180 | - $invoice |
|
| 181 | - ); |
|
| 180 | + $invoice |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Secures worldpay args with an md5 hash. |
|
| 187 | - * |
|
| 188 | - * @param array $args Gateway args. |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function hash_args( $args ) { |
|
| 186 | + * Secures worldpay args with an md5 hash. |
|
| 187 | + * |
|
| 188 | + * @param array $args Gateway args. |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function hash_args( $args ) { |
|
| 192 | 192 | |
| 193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
| 194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Processes ipns and marks payments as complete. |
|
| 208 | - * |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function verify_ipn() { |
|
| 207 | + * Processes ipns and marks payments as complete. |
|
| 208 | + * |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function verify_ipn() { |
|
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | - } |
|
| 215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - // Update the ip address. |
|
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 232 | + // Update the ip address. |
|
| 233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * Check Worldpay IPN validity. |
|
| 261 | - */ |
|
| 262 | - public function validate_ipn() { |
|
| 260 | + * Check Worldpay IPN validity. |
|
| 261 | + */ |
|
| 262 | + public function validate_ipn() { |
|
| 263 | 263 | |
| 264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
| 265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Filters the gateway settings. |
|
| 309 | - * |
|
| 310 | - * @param array $admin_settings |
|
| 311 | - */ |
|
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 308 | + * Filters the gateway settings. |
|
| 309 | + * |
|
| 310 | + * @param array $admin_settings |
|
| 311 | + */ |
|
| 312 | + public function admin_settings( $admin_settings ) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | 'readonly' => true, |
| 351 | 351 | ); |
| 352 | 352 | |
| 353 | - return $admin_settings; |
|
| 354 | - } |
|
| 353 | + return $admin_settings; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | } |
@@ -13,299 +13,299 @@ |
||
| 13 | 13 | class GetPaid_Subscription_Notification_Emails { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * The array of subscription email actions. |
|
| 17 | - * |
|
| 18 | - * @param array |
|
| 19 | - */ |
|
| 20 | - public $subscription_actions; |
|
| 16 | + * The array of subscription email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $subscription_actions; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Class constructor |
|
| 23 | + * Class constructor |
|
| 24 | 24 | * |
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - |
|
| 28 | - $this->subscription_actions = apply_filters( |
|
| 29 | - 'getpaid_notification_email_subscription_triggers', |
|
| 30 | - array( |
|
| 31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - $this->init_hooks(); |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->subscription_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_subscription_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + $this->init_hooks(); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Registers email hooks. |
|
| 45 | - */ |
|
| 46 | - public function init_hooks() { |
|
| 47 | - |
|
| 48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | - |
|
| 51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | - |
|
| 53 | - if ( ! $email->is_active() ) { |
|
| 54 | - continue; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( method_exists( $this, $email_type ) ) { |
|
| 58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | - continue; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Filters subscription merge tags. |
|
| 70 | - * |
|
| 71 | - * @param array $merge_tags |
|
| 72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | - */ |
|
| 74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 75 | - |
|
| 76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | - $merge_tags = array_merge( |
|
| 78 | - $merge_tags, |
|
| 79 | - $this->get_subscription_merge_tags( $object ) |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return $merge_tags; |
|
| 84 | - |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Generates subscription merge tags. |
|
| 89 | - * |
|
| 90 | - * @param WPInv_Subscription $subscription |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | - |
|
| 95 | - // Abort if it does not exist. |
|
| 96 | - if ( ! $subscription->get_id() ) { |
|
| 97 | - return array(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $invoice = $subscription->get_parent_invoice(); |
|
| 101 | - return array( |
|
| 102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if we should send a notification for a subscription. |
|
| 118 | - * |
|
| 119 | - * @param WPInv_Invoice $invoice |
|
| 120 | - * @return bool |
|
| 121 | - */ |
|
| 122 | - public function should_send_notification( $invoice ) { |
|
| 123 | - return 0 != $invoice->get_id(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Returns notification recipients. |
|
| 128 | - * |
|
| 129 | - * @param WPInv_Invoice $invoice |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function get_recipients( $invoice ) { |
|
| 133 | - $recipients = array( $invoice->get_email() ); |
|
| 134 | - |
|
| 135 | - $cc = $invoice->get_email_cc(); |
|
| 136 | - |
|
| 137 | - if ( ! empty( $cc ) ) { |
|
| 138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $recipients; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Helper function to send an email. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Subscription $subscription |
|
| 149 | - * @param GetPaid_Notification_Email $email |
|
| 150 | - * @param string $type |
|
| 151 | - * @param array $extra_args Extra template args. |
|
| 152 | - */ |
|
| 153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | - |
|
| 155 | - // Abort in case the parent invoice does not exist. |
|
| 156 | - $invoice = $subscription->get_parent_invoice(); |
|
| 157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 166 | - |
|
| 167 | - $recipients = $this->get_recipients( $invoice ); |
|
| 168 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 169 | - $merge_tags = $email->get_merge_tags(); |
|
| 170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 172 | - $attachments = $email->get_attachments(); |
|
| 173 | - |
|
| 174 | - $result = $mailer->send( |
|
| 175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 176 | - $subject, |
|
| 177 | - $content, |
|
| 178 | - $attachments |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - // Maybe send a copy to the admin. |
|
| 182 | - if ( $email->include_admin_bcc() ) { |
|
| 183 | - $mailer->send( |
|
| 184 | - wpinv_get_admin_email(), |
|
| 185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 186 | - $content, |
|
| 187 | - $attachments |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if ( $result ) { |
|
| 192 | - $invoice->add_system_note( |
|
| 193 | - sprintf( |
|
| 194 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 195 | - sanitize_key( $type ), |
|
| 196 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 197 | - ) |
|
| 198 | - ); |
|
| 199 | - } else { |
|
| 200 | - $invoice->add_system_note( |
|
| 201 | - sprintf( |
|
| 202 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 203 | - sanitize_key( $type ), |
|
| 204 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 210 | - |
|
| 211 | - } |
|
| 44 | + * Registers email hooks. |
|
| 45 | + */ |
|
| 46 | + public function init_hooks() { |
|
| 47 | + |
|
| 48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | + |
|
| 51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | + |
|
| 53 | + if ( ! $email->is_active() ) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( method_exists( $this, $email_type ) ) { |
|
| 58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + } |
|
| 212 | 67 | |
| 213 | 68 | /** |
| 214 | - * Sends a new trial notification. |
|
| 215 | - * |
|
| 216 | - * @param WPInv_Subscription $subscription |
|
| 217 | - */ |
|
| 218 | - public function subscription_trial( $subscription ) { |
|
| 69 | + * Filters subscription merge tags. |
|
| 70 | + * |
|
| 71 | + * @param array $merge_tags |
|
| 72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | + */ |
|
| 74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 219 | 75 | |
| 220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | + $merge_tags = array_merge( |
|
| 78 | + $merge_tags, |
|
| 79 | + $this->get_subscription_merge_tags( $object ) |
|
| 80 | + ); |
|
| 81 | + } |
|
| 222 | 82 | |
| 223 | - } |
|
| 83 | + return $merge_tags; |
|
| 224 | 84 | |
| 225 | - /** |
|
| 226 | - * Sends a cancelled subscription notification. |
|
| 227 | - * |
|
| 228 | - * @param WPInv_Subscription $subscription |
|
| 229 | - */ |
|
| 230 | - public function subscription_cancelled( $subscription ) { |
|
| 85 | + } |
|
| 231 | 86 | |
| 232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 87 | + /** |
|
| 88 | + * Generates subscription merge tags. |
|
| 89 | + * |
|
| 90 | + * @param WPInv_Subscription $subscription |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | + |
|
| 95 | + // Abort if it does not exist. |
|
| 96 | + if ( ! $subscription->get_id() ) { |
|
| 97 | + return array(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $invoice = $subscription->get_parent_invoice(); |
|
| 101 | + return array( |
|
| 102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | + ); |
|
| 234 | 113 | |
| 235 | - } |
|
| 114 | + } |
|
| 236 | 115 | |
| 237 | - /** |
|
| 238 | - * Sends a subscription expired notification. |
|
| 239 | - * |
|
| 240 | - * @param WPInv_Subscription $subscription |
|
| 241 | - */ |
|
| 242 | - public function subscription_expired( $subscription ) { |
|
| 116 | + /** |
|
| 117 | + * Checks if we should send a notification for a subscription. |
|
| 118 | + * |
|
| 119 | + * @param WPInv_Invoice $invoice |
|
| 120 | + * @return bool |
|
| 121 | + */ |
|
| 122 | + public function should_send_notification( $invoice ) { |
|
| 123 | + return 0 != $invoice->get_id(); |
|
| 124 | + } |
|
| 243 | 125 | |
| 244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 126 | + /** |
|
| 127 | + * Returns notification recipients. |
|
| 128 | + * |
|
| 129 | + * @param WPInv_Invoice $invoice |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function get_recipients( $invoice ) { |
|
| 133 | + $recipients = array( $invoice->get_email() ); |
|
| 246 | 134 | |
| 247 | - } |
|
| 135 | + $cc = $invoice->get_email_cc(); |
|
| 248 | 136 | |
| 249 | - /** |
|
| 250 | - * Sends a completed subscription notification. |
|
| 251 | - * |
|
| 252 | - * @param WPInv_Subscription $subscription |
|
| 253 | - */ |
|
| 254 | - public function subscription_complete( $subscription ) { |
|
| 137 | + if ( ! empty( $cc ) ) { |
|
| 138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | + } |
|
| 255 | 141 | |
| 256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 142 | + return $recipients; |
|
| 143 | + } |
|
| 258 | 144 | |
| 259 | - } |
|
| 145 | + /** |
|
| 146 | + * Helper function to send an email. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Subscription $subscription |
|
| 149 | + * @param GetPaid_Notification_Email $email |
|
| 150 | + * @param string $type |
|
| 151 | + * @param array $extra_args Extra template args. |
|
| 152 | + */ |
|
| 153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | + |
|
| 155 | + // Abort in case the parent invoice does not exist. |
|
| 156 | + $invoice = $subscription->get_parent_invoice(); |
|
| 157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 166 | + |
|
| 167 | + $recipients = $this->get_recipients( $invoice ); |
|
| 168 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 169 | + $merge_tags = $email->get_merge_tags(); |
|
| 170 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 172 | + $attachments = $email->get_attachments(); |
|
| 173 | + |
|
| 174 | + $result = $mailer->send( |
|
| 175 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 176 | + $subject, |
|
| 177 | + $content, |
|
| 178 | + $attachments |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + // Maybe send a copy to the admin. |
|
| 182 | + if ( $email->include_admin_bcc() ) { |
|
| 183 | + $mailer->send( |
|
| 184 | + wpinv_get_admin_email(), |
|
| 185 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 186 | + $content, |
|
| 187 | + $attachments |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if ( $result ) { |
|
| 192 | + $invoice->add_system_note( |
|
| 193 | + sprintf( |
|
| 194 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 195 | + sanitize_key( $type ), |
|
| 196 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 197 | + ) |
|
| 198 | + ); |
|
| 199 | + } else { |
|
| 200 | + $invoice->add_system_note( |
|
| 201 | + sprintf( |
|
| 202 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 203 | + sanitize_key( $type ), |
|
| 204 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 260 | 210 | |
| 261 | - /** |
|
| 262 | - * Sends a subscription renewal reminder notification. |
|
| 263 | - * |
|
| 264 | - */ |
|
| 265 | - public function renewal_reminder() { |
|
| 211 | + } |
|
| 266 | 212 | |
| 267 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 213 | + /** |
|
| 214 | + * Sends a new trial notification. |
|
| 215 | + * |
|
| 216 | + * @param WPInv_Subscription $subscription |
|
| 217 | + */ |
|
| 218 | + public function subscription_trial( $subscription ) { |
|
| 268 | 219 | |
| 269 | - // Fetch reminder days. |
|
| 270 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 220 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 271 | 222 | |
| 272 | - // Abort if non is set. |
|
| 273 | - if ( empty( $reminder_days ) ) { |
|
| 274 | - return; |
|
| 275 | - } |
|
| 223 | + } |
|
| 276 | 224 | |
| 277 | - // Fetch matching subscriptions. |
|
| 225 | + /** |
|
| 226 | + * Sends a cancelled subscription notification. |
|
| 227 | + * |
|
| 228 | + * @param WPInv_Subscription $subscription |
|
| 229 | + */ |
|
| 230 | + public function subscription_cancelled( $subscription ) { |
|
| 231 | + |
|
| 232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 234 | + |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sends a subscription expired notification. |
|
| 239 | + * |
|
| 240 | + * @param WPInv_Subscription $subscription |
|
| 241 | + */ |
|
| 242 | + public function subscription_expired( $subscription ) { |
|
| 243 | + |
|
| 244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Sends a completed subscription notification. |
|
| 251 | + * |
|
| 252 | + * @param WPInv_Subscription $subscription |
|
| 253 | + */ |
|
| 254 | + public function subscription_complete( $subscription ) { |
|
| 255 | + |
|
| 256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 258 | + |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Sends a subscription renewal reminder notification. |
|
| 263 | + * |
|
| 264 | + */ |
|
| 265 | + public function renewal_reminder() { |
|
| 266 | + |
|
| 267 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 268 | + |
|
| 269 | + // Fetch reminder days. |
|
| 270 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 271 | + |
|
| 272 | + // Abort if non is set. |
|
| 273 | + if ( empty( $reminder_days ) ) { |
|
| 274 | + return; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // Fetch matching subscriptions. |
|
| 278 | 278 | $args = array( |
| 279 | 279 | 'number' => -1, |
| 280 | - 'count_total' => false, |
|
| 281 | - 'status' => 'trialling active', |
|
| 280 | + 'count_total' => false, |
|
| 281 | + 'status' => 'trialling active', |
|
| 282 | 282 | 'date_expires_query' => array( |
| 283 | - 'relation' => 'OR', |
|
| 283 | + 'relation' => 'OR', |
|
| 284 | 284 | ), |
| 285 | - ); |
|
| 285 | + ); |
|
| 286 | 286 | |
| 287 | - foreach ( $reminder_days as $days ) { |
|
| 288 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 287 | + foreach ( $reminder_days as $days ) { |
|
| 288 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 289 | 289 | |
| 290 | - $args['date_expires_query'][] = array( |
|
| 291 | - 'year' => $date['year'], |
|
| 292 | - 'month' => $date['month'], |
|
| 293 | - 'day' => $date['day'], |
|
| 294 | - ); |
|
| 290 | + $args['date_expires_query'][] = array( |
|
| 291 | + 'year' => $date['year'], |
|
| 292 | + 'month' => $date['month'], |
|
| 293 | + 'day' => $date['day'], |
|
| 294 | + ); |
|
| 295 | 295 | |
| 296 | - } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 298 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 299 | 299 | |
| 300 | 300 | foreach ( $subscriptions as $subscription ) { |
| 301 | 301 | |
| 302 | - // Skip packages. |
|
| 303 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
| 304 | - $email->object = $subscription; |
|
| 305 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 306 | - } |
|
| 302 | + // Skip packages. |
|
| 303 | + if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
| 304 | + $email->object = $subscription; |
|
| 305 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 306 | + } |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - } |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | 311 | } |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | $args = wp_parse_args( |
| 58 | 58 | $args, |
| 59 | 59 | array( |
| 60 | - 'status' => array( 'publish' ), |
|
| 61 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | - 'page' => 1, |
|
| 63 | - 'exclude' => array(), |
|
| 64 | - 'orderby' => 'date', |
|
| 65 | - 'order' => 'DESC', |
|
| 66 | - 'type' => wpinv_item_types(), |
|
| 67 | - 'meta_query' => array(), |
|
| 68 | - 'return' => 'objects', |
|
| 69 | - 'paginate' => false, |
|
| 60 | + 'status' => array( 'publish' ), |
|
| 61 | + 'limit' => get_option( 'posts_per_page' ), |
|
| 62 | + 'page' => 1, |
|
| 63 | + 'exclude' => array(), |
|
| 64 | + 'orderby' => 'date', |
|
| 65 | + 'order' => 'DESC', |
|
| 66 | + 'type' => wpinv_item_types(), |
|
| 67 | + 'meta_query' => array(), |
|
| 68 | + 'return' => 'objects', |
|
| 69 | + 'paginate' => false, |
|
| 70 | 70 | ) |
| 71 | 71 | ); |
| 72 | 72 | |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | function wpinv_get_item_types() { |
| 208 | 208 | $item_types = array( |
| 209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 211 | - ); |
|
| 209 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
| 210 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
| 211 | + ); |
|
| 212 | 212 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
| 250 | 250 | if ( $post_ids ) { |
| 251 | 251 | $args = array( |
| 252 | - 'post_type' => 'wpi_item', |
|
| 253 | - 'orderby' => 'rand', |
|
| 254 | - 'post_count' => $num, |
|
| 255 | - 'fields' => 'ids', |
|
| 256 | - ); |
|
| 252 | + 'post_type' => 'wpi_item', |
|
| 253 | + 'orderby' => 'rand', |
|
| 254 | + 'post_count' => $num, |
|
| 255 | + 'fields' => 'ids', |
|
| 256 | + ); |
|
| 257 | 257 | } else { |
| 258 | 258 | $args = array( |
| 259 | - 'post_type' => 'wpi_item', |
|
| 260 | - 'orderby' => 'rand', |
|
| 261 | - 'post_count' => $num, |
|
| 262 | - ); |
|
| 259 | + 'post_type' => 'wpi_item', |
|
| 260 | + 'orderby' => 'rand', |
|
| 261 | + 'post_count' => $num, |
|
| 262 | + ); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $args = apply_filters( 'wpinv_get_random_items', $args ); |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | $bill_times = $item->get_recurring_limit(); |
| 427 | 427 | |
| 428 | 428 | if ( ! empty( $bill_times ) ) { |
| 429 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 430 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 431 | - } |
|
| 429 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
| 430 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | 433 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
| 434 | 434 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |