@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - echo aui()->alert( |
|
| 29 | - array( |
|
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 28 | + echo aui()->alert( |
|
| 29 | + array( |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | 36 | |
| 37 | - // Display a single subscription. |
|
| 38 | - wpinv_recurring_subscription_details(); |
|
| 39 | - } else { |
|
| 37 | + // Display a single subscription. |
|
| 38 | + wpinv_recurring_subscription_details(); |
|
| 39 | + } else { |
|
| 40 | 40 | |
| 41 | - // Display a list of available subscriptions. |
|
| 42 | - getpaid_print_subscriptions_list(); |
|
| 43 | - } |
|
| 41 | + // Display a list of available subscriptions. |
|
| 42 | + getpaid_print_subscriptions_list(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - ?> |
|
| 45 | + ?> |
|
| 46 | 46 | |
| 47 | 47 | </div> |
| 48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function getpaid_print_subscriptions_list() { |
| 61 | 61 | |
| 62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | - $subscribers_table->prepare_items(); |
|
| 62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | + $subscribers_table->prepare_items(); |
|
| 64 | 64 | |
| 65 | - ?> |
|
| 65 | + ?> |
|
| 66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
| 67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | - // Fetch the subscription. |
|
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->get_id() ) { |
|
| 83 | + // Fetch the subscription. |
|
| 84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | + if ( ! $sub->get_id() ) { |
|
| 86 | 86 | |
| 87 | - echo aui()->alert( |
|
| 88 | - array( |
|
| 89 | - 'type' => 'danger', |
|
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 87 | + echo aui()->alert( |
|
| 88 | + array( |
|
| 89 | + 'type' => 'danger', |
|
| 90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - return; |
|
| 95 | - } |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Use metaboxes to display the subscription details. |
|
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 97 | + // Use metaboxes to display the subscription details. |
|
| 98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 102 | 102 | |
| 103 | - ?> |
|
| 103 | + ?> |
|
| 104 | 104 | |
| 105 | 105 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
| 106 | 106 | |
@@ -140,41 +140,41 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 142 | 142 | |
| 143 | - // Prepare subscription detail columns. |
|
| 144 | - $fields = apply_filters( |
|
| 145 | - 'getpaid_subscription_admin_page_fields', |
|
| 146 | - array( |
|
| 147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - |
|
| 160 | - if ( ! $sub->is_active() ) { |
|
| 161 | - |
|
| 162 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | - unset( $fields['renews_on'] ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ( isset( $fields['gateway'] ) ) { |
|
| 167 | - unset( $fields['gateway'] ); |
|
| 168 | - } |
|
| 143 | + // Prepare subscription detail columns. |
|
| 144 | + $fields = apply_filters( |
|
| 145 | + 'getpaid_subscription_admin_page_fields', |
|
| 146 | + array( |
|
| 147 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | + 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + |
|
| 160 | + if ( ! $sub->is_active() ) { |
|
| 161 | + |
|
| 162 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | + unset( $fields['renews_on'] ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ( isset( $fields['gateway'] ) ) { |
|
| 167 | + unset( $fields['gateway'] ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - $profile_id = $sub->get_profile_id(); |
|
| 173 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | - unset( $fields['profile_id'] ); |
|
| 175 | - } |
|
| 172 | + $profile_id = $sub->get_profile_id(); |
|
| 173 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | + unset( $fields['profile_id'] ); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - ?> |
|
| 177 | + ?> |
|
| 178 | 178 | |
| 179 | 179 | <table class="table table-borderless" style="font-size: 14px;"> |
| 180 | 180 | <tbody> |
@@ -208,20 +208,20 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 210 | 210 | |
| 211 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 211 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 212 | 212 | |
| 213 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | - if ( $user ) { |
|
| 213 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | + if ( $user ) { |
|
| 215 | 215 | |
| 216 | - $username = sprintf( |
|
| 217 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 218 | - absint( $user->ID ), |
|
| 219 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 220 | - ); |
|
| 216 | + $username = sprintf( |
|
| 217 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 218 | + absint( $user->ID ), |
|
| 219 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 220 | + ); |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - echo $username; |
|
| 224 | + echo $username; |
|
| 225 | 225 | } |
| 226 | 226 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 227 | 227 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * @param WPInv_Subscription $subscription |
| 232 | 232 | */ |
| 233 | 233 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 234 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 235 | - echo "<span>$amount</span>"; |
|
| 234 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 235 | + echo "<span>$amount</span>"; |
|
| 236 | 236 | } |
| 237 | 237 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 238 | 238 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param WPInv_Subscription $subscription |
| 243 | 243 | */ |
| 244 | 244 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 245 | - echo '#' . absint( $subscription->get_id() ); |
|
| 245 | + echo '#' . absint( $subscription->get_id() ); |
|
| 246 | 246 | } |
| 247 | 247 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
| 248 | 248 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param WPInv_Subscription $subscription |
| 253 | 253 | */ |
| 254 | 254 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 255 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 255 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 256 | 256 | } |
| 257 | 257 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
| 258 | 258 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @param WPInv_Subscription $subscription |
| 263 | 263 | */ |
| 264 | 264 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 265 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 265 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 266 | 266 | } |
| 267 | 267 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 268 | 268 | |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | * @param WPInv_Subscription $subscription |
| 273 | 273 | */ |
| 274 | 274 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 275 | - $max_bills = $subscription->get_bill_times(); |
|
| 276 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 275 | + $max_bills = $subscription->get_bill_times(); |
|
| 276 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 277 | 277 | } |
| 278 | 278 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 279 | 279 | /** |
@@ -283,16 +283,16 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
| 285 | 285 | |
| 286 | - $item = get_post( $subscription->get_product_id() ); |
|
| 286 | + $item = get_post( $subscription->get_product_id() ); |
|
| 287 | 287 | |
| 288 | - if ( ! empty( $item ) ) { |
|
| 289 | - $link = get_edit_post_link( $item ); |
|
| 290 | - $link = esc_url( $link ); |
|
| 291 | - $name = esc_html( get_the_title( $item ) ); |
|
| 292 | - echo "<a href='$link'>$name</a>"; |
|
| 293 | - } else { |
|
| 294 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 295 | - } |
|
| 288 | + if ( ! empty( $item ) ) { |
|
| 289 | + $link = get_edit_post_link( $item ); |
|
| 290 | + $link = esc_url( $link ); |
|
| 291 | + $name = esc_html( get_the_title( $item ) ); |
|
| 292 | + echo "<a href='$link'>$name</a>"; |
|
| 293 | + } else { |
|
| 294 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | 297 | } |
| 298 | 298 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 306 | 306 | |
| 307 | - $gateway = $subscription->get_gateway(); |
|
| 307 | + $gateway = $subscription->get_gateway(); |
|
| 308 | 308 | |
| 309 | - if ( ! empty( $gateway ) ) { |
|
| 310 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 311 | - } else { |
|
| 312 | - echo "—"; |
|
| 313 | - } |
|
| 309 | + if ( ! empty( $gateway ) ) { |
|
| 310 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 311 | + } else { |
|
| 312 | + echo "—"; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | } |
| 316 | 316 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @param WPInv_Subscription $subscription |
| 322 | 322 | */ |
| 323 | 323 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 324 | - echo $subscription->get_status_label_html(); |
|
| 324 | + echo $subscription->get_status_label_html(); |
|
| 325 | 325 | } |
| 326 | 326 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 327 | 327 | |
@@ -332,29 +332,29 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 334 | 334 | |
| 335 | - $profile_id = $subscription->get_profile_id(); |
|
| 336 | - |
|
| 337 | - $input = aui()->input( |
|
| 338 | - array( |
|
| 339 | - 'type' => 'text', |
|
| 340 | - 'id' => 'wpinv_subscription_profile_id', |
|
| 341 | - 'name' => 'wpinv_subscription_profile_id', |
|
| 342 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 343 | - 'label_type' => 'hidden', |
|
| 344 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 345 | - 'value' => sanitize_text_field( $profile_id ), |
|
| 346 | - 'input_group_right' => '', |
|
| 347 | - 'no_wrap' => true, |
|
| 348 | - ) |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
| 352 | - |
|
| 353 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 354 | - if ( ! empty( $url ) ) { |
|
| 355 | - $url = esc_url_raw( $url ); |
|
| 356 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 357 | - } |
|
| 335 | + $profile_id = $subscription->get_profile_id(); |
|
| 336 | + |
|
| 337 | + $input = aui()->input( |
|
| 338 | + array( |
|
| 339 | + 'type' => 'text', |
|
| 340 | + 'id' => 'wpinv_subscription_profile_id', |
|
| 341 | + 'name' => 'wpinv_subscription_profile_id', |
|
| 342 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
| 343 | + 'label_type' => 'hidden', |
|
| 344 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
| 345 | + 'value' => sanitize_text_field( $profile_id ), |
|
| 346 | + 'input_group_right' => '', |
|
| 347 | + 'no_wrap' => true, |
|
| 348 | + ) |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
| 352 | + |
|
| 353 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
| 354 | + if ( ! empty( $url ) ) { |
|
| 355 | + $url = esc_url_raw( $url ); |
|
| 356 | + echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | 359 | } |
| 360 | 360 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -366,39 +366,39 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 368 | 368 | |
| 369 | - ?> |
|
| 369 | + ?> |
|
| 370 | 370 | <div class="mt-3"> |
| 371 | 371 | |
| 372 | 372 | <?php |
| 373 | - echo aui()->select( |
|
| 374 | - array( |
|
| 375 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 376 | - 'name' => 'subscription_status', |
|
| 377 | - 'id' => 'subscription_status_update_select', |
|
| 378 | - 'required' => true, |
|
| 379 | - 'no_wrap' => false, |
|
| 380 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 381 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 382 | - 'select2' => true, |
|
| 383 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 384 | - ) |
|
| 385 | - ); |
|
| 386 | - ?> |
|
| 373 | + echo aui()->select( |
|
| 374 | + array( |
|
| 375 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 376 | + 'name' => 'subscription_status', |
|
| 377 | + 'id' => 'subscription_status_update_select', |
|
| 378 | + 'required' => true, |
|
| 379 | + 'no_wrap' => false, |
|
| 380 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 381 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 382 | + 'select2' => true, |
|
| 383 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 384 | + ) |
|
| 385 | + ); |
|
| 386 | + ?> |
|
| 387 | 387 | |
| 388 | 388 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 389 | 389 | |
| 390 | 390 | <?php |
| 391 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 391 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 392 | 392 | |
| 393 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 394 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 395 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 393 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 394 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 395 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 396 | 396 | |
| 397 | - if ( $subscription->is_active() ) { |
|
| 398 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 399 | - } |
|
| 397 | + if ( $subscription->is_active() ) { |
|
| 398 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - echo '</div></div>'; |
|
| 401 | + echo '</div></div>'; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -408,33 +408,33 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
| 410 | 410 | |
| 411 | - $columns = apply_filters( |
|
| 412 | - 'getpaid_subscription_related_invoices_columns', |
|
| 413 | - array( |
|
| 414 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 415 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 416 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 417 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 418 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 419 | - ), |
|
| 420 | - $subscription |
|
| 421 | - ); |
|
| 422 | - |
|
| 423 | - // Prepare the invoices. |
|
| 424 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 425 | - $parent = $subscription->get_parent_invoice(); |
|
| 426 | - |
|
| 427 | - if ( $parent->get_id() ) { |
|
| 428 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 429 | - } |
|
| 411 | + $columns = apply_filters( |
|
| 412 | + 'getpaid_subscription_related_invoices_columns', |
|
| 413 | + array( |
|
| 414 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 415 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 416 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 417 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 418 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 419 | + ), |
|
| 420 | + $subscription |
|
| 421 | + ); |
|
| 422 | + |
|
| 423 | + // Prepare the invoices. |
|
| 424 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 425 | + $parent = $subscription->get_parent_invoice(); |
|
| 426 | + |
|
| 427 | + if ( $parent->get_id() ) { |
|
| 428 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - $table_class = 'w-100 bg-white'; |
|
| 431 | + $table_class = 'w-100 bg-white'; |
|
| 432 | 432 | |
| 433 | - if ( ! is_admin() ) { |
|
| 434 | - $table_class = 'table table-bordered table-striped'; |
|
| 435 | - } |
|
| 433 | + if ( ! is_admin() ) { |
|
| 434 | + $table_class = 'table table-bordered table-striped'; |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - ?> |
|
| 437 | + ?> |
|
| 438 | 438 | <div class="m-0" style="overflow: auto;"> |
| 439 | 439 | |
| 440 | 440 | <table class="<?php echo $table_class; ?>"> |
@@ -442,13 +442,13 @@ discard block |
||
| 442 | 442 | <thead> |
| 443 | 443 | <tr> |
| 444 | 444 | <?php |
| 445 | - foreach ( $columns as $key => $label ) { |
|
| 446 | - $key = esc_attr( $key ); |
|
| 447 | - $label = sanitize_text_field( $label ); |
|
| 445 | + foreach ( $columns as $key => $label ) { |
|
| 446 | + $key = esc_attr( $key ); |
|
| 447 | + $label = sanitize_text_field( $label ); |
|
| 448 | 448 | |
| 449 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>"; |
|
| 450 | - } |
|
| 451 | - ?> |
|
| 449 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>"; |
|
| 450 | + } |
|
| 451 | + ?> |
|
| 452 | 452 | </tr> |
| 453 | 453 | </thead> |
| 454 | 454 | |
@@ -464,66 +464,66 @@ discard block |
||
| 464 | 464 | |
| 465 | 465 | <?php |
| 466 | 466 | |
| 467 | - foreach( $payments as $payment ) : |
|
| 467 | + foreach( $payments as $payment ) : |
|
| 468 | 468 | |
| 469 | - // Ensure that we have an invoice. |
|
| 470 | - $payment = new WPInv_Invoice( $payment ); |
|
| 469 | + // Ensure that we have an invoice. |
|
| 470 | + $payment = new WPInv_Invoice( $payment ); |
|
| 471 | 471 | |
| 472 | - // Abort if the invoice is invalid. |
|
| 473 | - if ( ! $payment->get_id() ) { |
|
| 474 | - continue; |
|
| 475 | - } |
|
| 472 | + // Abort if the invoice is invalid. |
|
| 473 | + if ( ! $payment->get_id() ) { |
|
| 474 | + continue; |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - echo '<tr>'; |
|
| 477 | + echo '<tr>'; |
|
| 478 | 478 | |
| 479 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 479 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 480 | 480 | |
| 481 | - echo '<td class="p-2 text-left">'; |
|
| 481 | + echo '<td class="p-2 text-left">'; |
|
| 482 | 482 | |
| 483 | - switch( $key ) { |
|
| 483 | + switch( $key ) { |
|
| 484 | 484 | |
| 485 | - case 'total': |
|
| 486 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
| 487 | - break; |
|
| 485 | + case 'total': |
|
| 486 | + echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
| 487 | + break; |
|
| 488 | 488 | |
| 489 | - case 'relationship': |
|
| 490 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 491 | - break; |
|
| 489 | + case 'relationship': |
|
| 490 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 491 | + break; |
|
| 492 | 492 | |
| 493 | - case 'date': |
|
| 494 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 495 | - break; |
|
| 493 | + case 'date': |
|
| 494 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 495 | + break; |
|
| 496 | 496 | |
| 497 | - case 'status': |
|
| 497 | + case 'status': |
|
| 498 | 498 | |
| 499 | - $status = $payment->get_status_nicename(); |
|
| 500 | - if ( is_admin() ) { |
|
| 501 | - $status = $payment->get_status_label_html(); |
|
| 502 | - } |
|
| 499 | + $status = $payment->get_status_nicename(); |
|
| 500 | + if ( is_admin() ) { |
|
| 501 | + $status = $payment->get_status_label_html(); |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - echo $status; |
|
| 505 | - break; |
|
| 504 | + echo $status; |
|
| 505 | + break; |
|
| 506 | 506 | |
| 507 | - case 'invoice': |
|
| 508 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 507 | + case 'invoice': |
|
| 508 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 509 | 509 | |
| 510 | - if ( ! is_admin() ) { |
|
| 511 | - $link = esc_url( $payment->get_view_url() ); |
|
| 512 | - } |
|
| 510 | + if ( ! is_admin() ) { |
|
| 511 | + $link = esc_url( $payment->get_view_url() ); |
|
| 512 | + } |
|
| 513 | 513 | |
| 514 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 515 | - echo "<a href='$link'>$invoice</a>"; |
|
| 516 | - break; |
|
| 517 | - } |
|
| 514 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 515 | + echo "<a href='$link'>$invoice</a>"; |
|
| 516 | + break; |
|
| 517 | + } |
|
| 518 | 518 | |
| 519 | - echo '</td>'; |
|
| 519 | + echo '</td>'; |
|
| 520 | 520 | |
| 521 | - } |
|
| 521 | + } |
|
| 522 | 522 | |
| 523 | - echo '</tr>'; |
|
| 523 | + echo '</tr>'; |
|
| 524 | 524 | |
| 525 | - endforeach; |
|
| 526 | - ?> |
|
| 525 | + endforeach; |
|
| 526 | + ?> |
|
| 527 | 527 | |
| 528 | 528 | </tbody> |
| 529 | 529 | |
@@ -12,456 +12,456 @@ |
||
| 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_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 | - |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Check PayPal IPN validity. |
|
| 106 | - */ |
|
| 107 | - protected function validate_ipn() { |
|
| 108 | - |
|
| 109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 110 | - |
|
| 111 | - // Retrieve the associated invoice. |
|
| 112 | - $posted = wp_unslash( $_POST ); |
|
| 113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 114 | - |
|
| 115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Validate the IPN. |
|
| 120 | - $posted['cmd'] = '_notify-validate'; |
|
| 121 | - |
|
| 122 | - // Send back post vars to paypal. |
|
| 123 | - $params = array( |
|
| 124 | - 'body' => $posted, |
|
| 125 | - 'timeout' => 60, |
|
| 126 | - 'httpversion' => '1.1', |
|
| 127 | - 'compress' => false, |
|
| 128 | - 'decompress' => false, |
|
| 129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - // Post back to get a response. |
|
| 133 | - $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 ); |
|
| 134 | - |
|
| 135 | - // Check to see if the request was valid. |
|
| 136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 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_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 | + |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Check PayPal IPN validity. |
|
| 106 | + */ |
|
| 107 | + protected function validate_ipn() { |
|
| 108 | + |
|
| 109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 110 | + |
|
| 111 | + // Retrieve the associated invoice. |
|
| 112 | + $posted = wp_unslash( $_POST ); |
|
| 113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 114 | + |
|
| 115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Validate the IPN. |
|
| 120 | + $posted['cmd'] = '_notify-validate'; |
|
| 121 | + |
|
| 122 | + // Send back post vars to paypal. |
|
| 123 | + $params = array( |
|
| 124 | + 'body' => $posted, |
|
| 125 | + 'timeout' => 60, |
|
| 126 | + 'httpversion' => '1.1', |
|
| 127 | + 'compress' => false, |
|
| 128 | + 'decompress' => false, |
|
| 129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + // Post back to get a response. |
|
| 133 | + $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 ); |
|
| 134 | + |
|
| 135 | + // Check to see if the request was valid. |
|
| 136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | + wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ( is_wp_error( $response ) ) { |
|
| 142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | - return false; |
|
| 148 | - |
|
| 149 | - } |
|
| 146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | + return false; |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Check currency from IPN matches the invoice. |
|
| 153 | - * |
|
| 154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | - * @param string $currency currency to validate. |
|
| 156 | - */ |
|
| 157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 151 | + /** |
|
| 152 | + * Check currency from IPN matches the invoice. |
|
| 153 | + * |
|
| 154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | + * @param string $currency currency to validate. |
|
| 156 | + */ |
|
| 157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 158 | 158 | |
| 159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 160 | 160 | |
| 161 | - /* translators: %s: currency code. */ |
|
| 162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 161 | + /* translators: %s: currency code. */ |
|
| 162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 163 | 163 | |
| 164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | - } |
|
| 164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 168 | - } |
|
| 167 | + wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Check payment amount from IPN matches the invoice. |
|
| 172 | - * |
|
| 173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | - * @param float $amount amount to validate. |
|
| 175 | - */ |
|
| 176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 170 | + /** |
|
| 171 | + * Check payment amount from IPN matches the invoice. |
|
| 172 | + * |
|
| 173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | + * @param float $amount amount to validate. |
|
| 175 | + */ |
|
| 176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 178 | 178 | |
| 179 | - /* translators: %s: Amount. */ |
|
| 180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 179 | + /* translators: %s: Amount. */ |
|
| 180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 181 | 181 | |
| 182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | - } |
|
| 182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 186 | - } |
|
| 185 | + wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Verify receiver email from PayPal. |
|
| 190 | - * |
|
| 191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | - * @param string $receiver_email Email to validate. |
|
| 193 | - */ |
|
| 194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 188 | + /** |
|
| 189 | + * Verify receiver email from PayPal. |
|
| 190 | + * |
|
| 191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | + * @param string $receiver_email Email to validate. |
|
| 193 | + */ |
|
| 194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 196 | 196 | |
| 197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 199 | 199 | |
| 200 | - /* translators: %s: email address . */ |
|
| 201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 200 | + /* translators: %s: email address . */ |
|
| 201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 202 | 202 | |
| 203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | - } |
|
| 203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 207 | - } |
|
| 206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Handles one time payments. |
|
| 211 | - * |
|
| 212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | - * @param array $posted Posted data. |
|
| 214 | - */ |
|
| 215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | - |
|
| 217 | - // Collect payment details |
|
| 218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | - |
|
| 221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | - |
|
| 224 | - // Update the transaction id. |
|
| 225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | - $invoice->save(); |
|
| 228 | - } |
|
| 209 | + /** |
|
| 210 | + * Handles one time payments. |
|
| 211 | + * |
|
| 212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | + * @param array $posted Posted data. |
|
| 214 | + */ |
|
| 215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | + |
|
| 217 | + // Collect payment details |
|
| 218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | + |
|
| 221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | + |
|
| 224 | + // Update the transaction id. |
|
| 225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | + $invoice->save(); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - // Process a refund. |
|
| 231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 230 | + // Process a refund. |
|
| 231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 232 | 232 | |
| 233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | 234 | |
| 235 | - if ( ! $invoice->is_refunded() ) { |
|
| 236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | - } |
|
| 235 | + if ( ! $invoice->is_refunded() ) { |
|
| 236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
| 240 | - } |
|
| 239 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - // Process payments. |
|
| 243 | - if ( $payment_status == 'completed' ) { |
|
| 242 | + // Process payments. |
|
| 243 | + if ( $payment_status == 'completed' ) { |
|
| 244 | 244 | |
| 245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 247 | - } |
|
| 245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | 250 | |
| 251 | - $note = ''; |
|
| 251 | + $note = ''; |
|
| 252 | 252 | |
| 253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | - } |
|
| 253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | - } |
|
| 257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // Pending payments. |
|
| 267 | - if ( $payment_status == 'pending' ) { |
|
| 266 | + // Pending payments. |
|
| 267 | + if ( $payment_status == 'pending' ) { |
|
| 268 | 268 | |
| 269 | - /* translators: %s: pending reason. */ |
|
| 270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 269 | + /* translators: %s: pending reason. */ |
|
| 270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 271 | 271 | |
| 272 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 273 | - } |
|
| 272 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /* translators: %s: payment status. */ |
|
| 276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 275 | + /* translators: %s: payment status. */ |
|
| 276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 277 | 277 | |
| 278 | - } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Handles one time payments. |
|
| 282 | - * |
|
| 283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | - * @param array $posted Posted data. |
|
| 285 | - */ |
|
| 286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * Handles one time payments. |
|
| 282 | + * |
|
| 283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | + * @param array $posted Posted data. |
|
| 285 | + */ |
|
| 286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Handles subscription sign ups. |
|
| 292 | - * |
|
| 293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | - * @param array $posted Posted data. |
|
| 295 | - */ |
|
| 296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 290 | + /** |
|
| 291 | + * Handles subscription sign ups. |
|
| 292 | + * |
|
| 293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | + * @param array $posted Posted data. |
|
| 295 | + */ |
|
| 296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 297 | 297 | |
| 298 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
| 298 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
| 299 | 299 | |
| 300 | - // Make sure the invoice has a subscription. |
|
| 301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 300 | + // Make sure the invoice has a subscription. |
|
| 301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 302 | 302 | |
| 303 | - if ( empty( $subscription ) ) { |
|
| 304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 305 | - } |
|
| 303 | + if ( empty( $subscription ) ) { |
|
| 304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - // Validate the IPN. |
|
| 308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 307 | + // Validate the IPN. |
|
| 308 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 311 | 311 | |
| 312 | - // Activate the subscription. |
|
| 313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 317 | - $subscription->activate(); |
|
| 312 | + // Activate the subscription. |
|
| 313 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 314 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 315 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 316 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 317 | + $subscription->activate(); |
|
| 318 | 318 | |
| 319 | - // Set the transaction id. |
|
| 320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 322 | - } |
|
| 319 | + // Set the transaction id. |
|
| 320 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 321 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - // Update the payment status. |
|
| 325 | - $invoice->mark_paid(); |
|
| 324 | + // Update the payment status. |
|
| 325 | + $invoice->mark_paid(); |
|
| 326 | 326 | |
| 327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 327 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 328 | 328 | |
| 329 | - wpinv_error_log( 'Subscription started.', false ); |
|
| 330 | - } |
|
| 329 | + wpinv_error_log( 'Subscription started.', false ); |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - /** |
|
| 333 | - * Handles subscription renewals. |
|
| 334 | - * |
|
| 335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 336 | - * @param array $posted Posted data. |
|
| 337 | - */ |
|
| 338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 332 | + /** |
|
| 333 | + * Handles subscription renewals. |
|
| 334 | + * |
|
| 335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 336 | + * @param array $posted Posted data. |
|
| 337 | + */ |
|
| 338 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 339 | 339 | |
| 340 | - // Make sure the invoice has a subscription. |
|
| 341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 340 | + // Make sure the invoice has a subscription. |
|
| 341 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 342 | 342 | |
| 343 | - if ( empty( $subscription ) ) { |
|
| 344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 345 | - } |
|
| 343 | + if ( empty( $subscription ) ) { |
|
| 344 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - // Abort if this is the first payment. |
|
| 348 | - if ( ( $invoice->is_paid() && date( 'Ynd', strtotime( $invoice->get_date_completed() ) ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) || date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 347 | + // Abort if this is the first payment. |
|
| 348 | + if ( ( $invoice->is_paid() && date( 'Ynd', strtotime( $invoice->get_date_completed() ) ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) || date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 349 | 349 | |
| 350 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 351 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 352 | - $invoice->mark_paid(); |
|
| 353 | - $invoice->save(); |
|
| 354 | - } |
|
| 350 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 351 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 352 | + $invoice->mark_paid(); |
|
| 353 | + $invoice->save(); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return; |
|
| 357 | - } |
|
| 356 | + return; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 359 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 360 | 360 | |
| 361 | - // Abort if the payment is already recorded. |
|
| 362 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 363 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - $args = array( |
|
| 367 | - 'transaction_id' => $posted['txn_id'], |
|
| 368 | - 'gateway' => $this->id, |
|
| 369 | - ); |
|
| 370 | - |
|
| 371 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 372 | - |
|
| 373 | - if ( empty( $invoice ) ) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 378 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 379 | - |
|
| 380 | - $subscription->renew(); |
|
| 381 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
| 382 | - |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Handles subscription cancelations. |
|
| 387 | - * |
|
| 388 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 389 | - */ |
|
| 390 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 391 | - |
|
| 392 | - // Make sure the invoice has a subscription. |
|
| 393 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 394 | - |
|
| 395 | - if ( empty( $subscription ) ) { |
|
| 396 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 400 | - $subscription->cancel(); |
|
| 401 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 402 | - |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Handles subscription completions. |
|
| 407 | - * |
|
| 408 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 409 | - * @param array $posted Posted data. |
|
| 410 | - */ |
|
| 411 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 412 | - |
|
| 413 | - // Make sure the invoice has a subscription. |
|
| 414 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 361 | + // Abort if the payment is already recorded. |
|
| 362 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 363 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + $args = array( |
|
| 367 | + 'transaction_id' => $posted['txn_id'], |
|
| 368 | + 'gateway' => $this->id, |
|
| 369 | + ); |
|
| 370 | + |
|
| 371 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 372 | + |
|
| 373 | + if ( empty( $invoice ) ) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 378 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 379 | + |
|
| 380 | + $subscription->renew(); |
|
| 381 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
| 382 | + |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Handles subscription cancelations. |
|
| 387 | + * |
|
| 388 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 389 | + */ |
|
| 390 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 391 | + |
|
| 392 | + // Make sure the invoice has a subscription. |
|
| 393 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 394 | + |
|
| 395 | + if ( empty( $subscription ) ) { |
|
| 396 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 400 | + $subscription->cancel(); |
|
| 401 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 402 | + |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Handles subscription completions. |
|
| 407 | + * |
|
| 408 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 409 | + * @param array $posted Posted data. |
|
| 410 | + */ |
|
| 411 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 412 | + |
|
| 413 | + // Make sure the invoice has a subscription. |
|
| 414 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 415 | 415 | |
| 416 | - if ( empty( $subscription ) ) { |
|
| 417 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 418 | - } |
|
| 416 | + if ( empty( $subscription ) ) { |
|
| 417 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 421 | - $subscription->complete(); |
|
| 422 | - wpinv_error_log( 'Subscription completed.', false ); |
|
| 420 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 421 | + $subscription->complete(); |
|
| 422 | + wpinv_error_log( 'Subscription completed.', false ); |
|
| 423 | 423 | |
| 424 | - } |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - /** |
|
| 427 | - * Handles subscription fails. |
|
| 428 | - * |
|
| 429 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 430 | - * @param array $posted Posted data. |
|
| 431 | - */ |
|
| 432 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 433 | - |
|
| 434 | - // Make sure the invoice has a subscription. |
|
| 435 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 426 | + /** |
|
| 427 | + * Handles subscription fails. |
|
| 428 | + * |
|
| 429 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 430 | + * @param array $posted Posted data. |
|
| 431 | + */ |
|
| 432 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 433 | + |
|
| 434 | + // Make sure the invoice has a subscription. |
|
| 435 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 436 | 436 | |
| 437 | - if ( empty( $subscription ) ) { |
|
| 438 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 439 | - } |
|
| 437 | + if ( empty( $subscription ) ) { |
|
| 438 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 442 | - $subscription->failing(); |
|
| 443 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 441 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 442 | + $subscription->failing(); |
|
| 443 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - /** |
|
| 448 | - * Handles subscription suspensions. |
|
| 449 | - * |
|
| 450 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 451 | - * @param array $posted Posted data. |
|
| 452 | - */ |
|
| 453 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 447 | + /** |
|
| 448 | + * Handles subscription suspensions. |
|
| 449 | + * |
|
| 450 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 451 | + * @param array $posted Posted data. |
|
| 452 | + */ |
|
| 453 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 454 | 454 | |
| 455 | - // Make sure the invoice has a subscription. |
|
| 456 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 455 | + // Make sure the invoice has a subscription. |
|
| 456 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 457 | 457 | |
| 458 | - if ( empty( $subscription ) ) { |
|
| 459 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 463 | - $subscription->cancel(); |
|
| 464 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 465 | - } |
|
| 458 | + if ( empty( $subscription ) ) { |
|
| 459 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 463 | + $subscription->cancel(); |
|
| 464 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | 467 | } |
@@ -13,467 +13,467 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - // Register gateway. |
|
| 142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | - |
|
| 144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | - |
|
| 146 | - // Enable Subscriptions. |
|
| 147 | - if ( $this->supports( 'subscription' ) ) { |
|
| 148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Enable sandbox. |
|
| 152 | - if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Invoice addons. |
|
| 157 | - if ( $this->supports( 'addons' ) ) { |
|
| 158 | - add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
| 159 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // Gateway settings. |
|
| 163 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + // Register gateway. |
|
| 142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | + |
|
| 144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | + |
|
| 146 | + // Enable Subscriptions. |
|
| 147 | + if ( $this->supports( 'subscription' ) ) { |
|
| 148 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Enable sandbox. |
|
| 152 | + if ( $this->supports( 'sandbox' ) ) { |
|
| 153 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Invoice addons. |
|
| 157 | + if ( $this->supports( 'addons' ) ) { |
|
| 158 | + add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
| 159 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // Gateway settings. |
|
| 163 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 164 | 164 | |
| 165 | 165 | |
| 166 | - // Gateway checkout fiellds. |
|
| 167 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 168 | - |
|
| 169 | - // Process payment. |
|
| 170 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 166 | + // Gateway checkout fiellds. |
|
| 167 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 168 | + |
|
| 169 | + // Process payment. |
|
| 170 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 171 | + |
|
| 172 | + // Change the checkout button text. |
|
| 173 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 174 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // Check if a gateway is valid for a given currency. |
|
| 178 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 179 | + |
|
| 180 | + // Generate the transaction url. |
|
| 181 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 182 | + |
|
| 183 | + // Generate the subscription url. |
|
| 184 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 185 | + |
|
| 186 | + // Confirm payments. |
|
| 187 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 188 | + |
|
| 189 | + // Verify IPNs. |
|
| 190 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Checks if this gateway is a given gateway. |
|
| 196 | + * |
|
| 197 | + * @since 1.0.19 |
|
| 198 | + * @return bool |
|
| 199 | + */ |
|
| 200 | + public function is( $gateway ) { |
|
| 201 | + return $gateway == $this->id; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns a users saved tokens for this gateway. |
|
| 206 | + * |
|
| 207 | + * @since 1.0.19 |
|
| 208 | + * @return array |
|
| 209 | + */ |
|
| 210 | + public function get_tokens( $sandbox = null ) { |
|
| 211 | + |
|
| 212 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 213 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 214 | + |
|
| 215 | + if ( is_array( $tokens ) ) { |
|
| 216 | + $this->tokens = $tokens; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if ( ! is_bool( $sandbox ) ) { |
|
| 222 | + return $this->tokens; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 226 | + return wp_list_filter( $this->tokens, $args ); |
|
| 227 | + |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Saves a token for this gateway. |
|
| 232 | + * |
|
| 233 | + * @since 1.0.19 |
|
| 234 | + */ |
|
| 235 | + public function save_token( $token ) { |
|
| 236 | + |
|
| 237 | + $tokens = $this->get_tokens(); |
|
| 238 | + $tokens[] = $token; |
|
| 239 | + |
|
| 240 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 241 | + |
|
| 242 | + $this->tokens = $tokens; |
|
| 243 | + |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Return the title for admin screens. |
|
| 248 | + * |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_method_title() { |
|
| 252 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Return the description for admin screens. |
|
| 257 | + * |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public function get_method_description() { |
|
| 261 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Get the success url. |
|
| 266 | + * |
|
| 267 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 268 | + * @return string |
|
| 269 | + */ |
|
| 270 | + public function get_return_url( $invoice ) { |
|
| 271 | + |
|
| 272 | + // Payment success url |
|
| 273 | + $return_url = add_query_arg( |
|
| 274 | + array( |
|
| 275 | + 'payment-confirm' => $this->id, |
|
| 276 | + 'invoice_key' => $invoice->get_key(), |
|
| 277 | + 'utm_nooverride' => 1 |
|
| 278 | + ), |
|
| 279 | + wpinv_get_success_page_uri() |
|
| 280 | + ); |
|
| 281 | + |
|
| 282 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Confirms payments when rendering the success page. |
|
| 287 | + * |
|
| 288 | + * @param string $content Success page content. |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + public function confirm_payment( $content ) { |
|
| 292 | + |
|
| 293 | + // Retrieve the invoice. |
|
| 294 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 295 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 296 | + |
|
| 297 | + // Ensure that it exists and that it is pending payment. |
|
| 298 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 299 | + return $content; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // Can the user view this invoice?? |
|
| 303 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 304 | + return $content; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // Show payment processing indicator. |
|
| 308 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Processes ipns and marks payments as complete. |
|
| 313 | + * |
|
| 314 | + * @return void |
|
| 315 | + */ |
|
| 316 | + public function verify_ipn() {} |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Processes invoice addons. |
|
| 320 | + * |
|
| 321 | + * @param WPInv_Invoice $invoice |
|
| 322 | + * @param GetPaid_Form_Item[] $items |
|
| 323 | + * @return WPInv_Invoice |
|
| 324 | + */ |
|
| 325 | + public function process_addons( $invoice, $items ) { |
|
| 326 | + |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 331 | + * |
|
| 332 | + * @param string $transaction_url transaction url. |
|
| 333 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 334 | + * @return string transaction URL, or empty string. |
|
| 335 | + */ |
|
| 336 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 337 | + |
|
| 338 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 339 | + |
|
| 340 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 341 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 342 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 343 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return $transaction_url; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 351 | + * |
|
| 352 | + * @param string $subscription_url transaction url. |
|
| 353 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 354 | + * @return string subscription URL, or empty string. |
|
| 355 | + */ |
|
| 356 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 171 | 357 | |
| 172 | - // Change the checkout button text. |
|
| 173 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 174 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // Check if a gateway is valid for a given currency. |
|
| 178 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 179 | - |
|
| 180 | - // Generate the transaction url. |
|
| 181 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 182 | - |
|
| 183 | - // Generate the subscription url. |
|
| 184 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 185 | - |
|
| 186 | - // Confirm payments. |
|
| 187 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 188 | - |
|
| 189 | - // Verify IPNs. |
|
| 190 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 191 | - |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Checks if this gateway is a given gateway. |
|
| 196 | - * |
|
| 197 | - * @since 1.0.19 |
|
| 198 | - * @return bool |
|
| 199 | - */ |
|
| 200 | - public function is( $gateway ) { |
|
| 201 | - return $gateway == $this->id; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns a users saved tokens for this gateway. |
|
| 206 | - * |
|
| 207 | - * @since 1.0.19 |
|
| 208 | - * @return array |
|
| 209 | - */ |
|
| 210 | - public function get_tokens( $sandbox = null ) { |
|
| 211 | - |
|
| 212 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 213 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 214 | - |
|
| 215 | - if ( is_array( $tokens ) ) { |
|
| 216 | - $this->tokens = $tokens; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if ( ! is_bool( $sandbox ) ) { |
|
| 222 | - return $this->tokens; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 226 | - return wp_list_filter( $this->tokens, $args ); |
|
| 227 | - |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Saves a token for this gateway. |
|
| 232 | - * |
|
| 233 | - * @since 1.0.19 |
|
| 234 | - */ |
|
| 235 | - public function save_token( $token ) { |
|
| 236 | - |
|
| 237 | - $tokens = $this->get_tokens(); |
|
| 238 | - $tokens[] = $token; |
|
| 239 | - |
|
| 240 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 241 | - |
|
| 242 | - $this->tokens = $tokens; |
|
| 243 | - |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Return the title for admin screens. |
|
| 248 | - * |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_method_title() { |
|
| 252 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Return the description for admin screens. |
|
| 257 | - * |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public function get_method_description() { |
|
| 261 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Get the success url. |
|
| 266 | - * |
|
| 267 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 268 | - * @return string |
|
| 269 | - */ |
|
| 270 | - public function get_return_url( $invoice ) { |
|
| 271 | - |
|
| 272 | - // Payment success url |
|
| 273 | - $return_url = add_query_arg( |
|
| 274 | - array( |
|
| 275 | - 'payment-confirm' => $this->id, |
|
| 276 | - 'invoice_key' => $invoice->get_key(), |
|
| 277 | - 'utm_nooverride' => 1 |
|
| 278 | - ), |
|
| 279 | - wpinv_get_success_page_uri() |
|
| 280 | - ); |
|
| 281 | - |
|
| 282 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Confirms payments when rendering the success page. |
|
| 287 | - * |
|
| 288 | - * @param string $content Success page content. |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - public function confirm_payment( $content ) { |
|
| 292 | - |
|
| 293 | - // Retrieve the invoice. |
|
| 294 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 295 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 296 | - |
|
| 297 | - // Ensure that it exists and that it is pending payment. |
|
| 298 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 299 | - return $content; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // Can the user view this invoice?? |
|
| 303 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 304 | - return $content; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // Show payment processing indicator. |
|
| 308 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Processes ipns and marks payments as complete. |
|
| 313 | - * |
|
| 314 | - * @return void |
|
| 315 | - */ |
|
| 316 | - public function verify_ipn() {} |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Processes invoice addons. |
|
| 320 | - * |
|
| 321 | - * @param WPInv_Invoice $invoice |
|
| 322 | - * @param GetPaid_Form_Item[] $items |
|
| 323 | - * @return WPInv_Invoice |
|
| 324 | - */ |
|
| 325 | - public function process_addons( $invoice, $items ) { |
|
| 326 | - |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 331 | - * |
|
| 332 | - * @param string $transaction_url transaction url. |
|
| 333 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 334 | - * @return string transaction URL, or empty string. |
|
| 335 | - */ |
|
| 336 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 337 | - |
|
| 338 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 339 | - |
|
| 340 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 341 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 342 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 343 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return $transaction_url; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 351 | - * |
|
| 352 | - * @param string $subscription_url transaction url. |
|
| 353 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 354 | - * @return string subscription URL, or empty string. |
|
| 355 | - */ |
|
| 356 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 357 | - |
|
| 358 | - $profile_id = $subscription->get_profile_id(); |
|
| 359 | - |
|
| 360 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 361 | - |
|
| 362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 363 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 364 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 365 | - |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $subscription_url; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Check if the gateway is available for use. |
|
| 373 | - * |
|
| 374 | - * @return bool |
|
| 375 | - */ |
|
| 376 | - public function is_available() { |
|
| 377 | - return ! empty( $this->enabled ); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Return the gateway's title. |
|
| 382 | - * |
|
| 383 | - * @return string |
|
| 384 | - */ |
|
| 385 | - public function get_title() { |
|
| 386 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Return the gateway's description. |
|
| 391 | - * |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - public function get_description() { |
|
| 395 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Process Payment. |
|
| 400 | - * |
|
| 401 | - * |
|
| 402 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 403 | - * @param array $submission_data Posted checkout fields. |
|
| 404 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 405 | - * @return void |
|
| 406 | - */ |
|
| 407 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 408 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 409 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Process refund. |
|
| 414 | - * |
|
| 415 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 416 | - * a passed in amount. |
|
| 417 | - * |
|
| 418 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 419 | - * @param float $amount Refund amount. |
|
| 420 | - * @param string $reason Refund reason. |
|
| 421 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 422 | - */ |
|
| 423 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 424 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * Displays the payment fields, credit cards etc. |
|
| 429 | - * |
|
| 430 | - * @param int $invoice_id 0 or invoice id. |
|
| 431 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 432 | - */ |
|
| 433 | - public function payment_fields( $invoice_id, $form ) { |
|
| 434 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Filters the gateway settings. |
|
| 439 | - * |
|
| 440 | - * @param array $admin_settings |
|
| 441 | - */ |
|
| 442 | - public function admin_settings( $admin_settings ) { |
|
| 443 | - return $admin_settings; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Retrieves the value of a gateway setting. |
|
| 448 | - * |
|
| 449 | - * @param string $option |
|
| 450 | - */ |
|
| 451 | - public function get_option( $option, $default = false ) { |
|
| 452 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Check if a gateway supports a given feature. |
|
| 457 | - * |
|
| 458 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 459 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 460 | - * |
|
| 461 | - * @param string $feature string The name of a feature to test support for. |
|
| 462 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - */ |
|
| 465 | - public function supports( $feature ) { |
|
| 466 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Returns the credit card form html. |
|
| 471 | - * |
|
| 472 | - * @param bool $save whether or not to display the save button. |
|
| 473 | - */ |
|
| 358 | + $profile_id = $subscription->get_profile_id(); |
|
| 359 | + |
|
| 360 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 361 | + |
|
| 362 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 363 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 364 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 365 | + |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $subscription_url; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Check if the gateway is available for use. |
|
| 373 | + * |
|
| 374 | + * @return bool |
|
| 375 | + */ |
|
| 376 | + public function is_available() { |
|
| 377 | + return ! empty( $this->enabled ); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Return the gateway's title. |
|
| 382 | + * |
|
| 383 | + * @return string |
|
| 384 | + */ |
|
| 385 | + public function get_title() { |
|
| 386 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Return the gateway's description. |
|
| 391 | + * |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + public function get_description() { |
|
| 395 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Process Payment. |
|
| 400 | + * |
|
| 401 | + * |
|
| 402 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 403 | + * @param array $submission_data Posted checkout fields. |
|
| 404 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 405 | + * @return void |
|
| 406 | + */ |
|
| 407 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 408 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 409 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Process refund. |
|
| 414 | + * |
|
| 415 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 416 | + * a passed in amount. |
|
| 417 | + * |
|
| 418 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 419 | + * @param float $amount Refund amount. |
|
| 420 | + * @param string $reason Refund reason. |
|
| 421 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 422 | + */ |
|
| 423 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 424 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * Displays the payment fields, credit cards etc. |
|
| 429 | + * |
|
| 430 | + * @param int $invoice_id 0 or invoice id. |
|
| 431 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 432 | + */ |
|
| 433 | + public function payment_fields( $invoice_id, $form ) { |
|
| 434 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Filters the gateway settings. |
|
| 439 | + * |
|
| 440 | + * @param array $admin_settings |
|
| 441 | + */ |
|
| 442 | + public function admin_settings( $admin_settings ) { |
|
| 443 | + return $admin_settings; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Retrieves the value of a gateway setting. |
|
| 448 | + * |
|
| 449 | + * @param string $option |
|
| 450 | + */ |
|
| 451 | + public function get_option( $option, $default = false ) { |
|
| 452 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Check if a gateway supports a given feature. |
|
| 457 | + * |
|
| 458 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 459 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 460 | + * |
|
| 461 | + * @param string $feature string The name of a feature to test support for. |
|
| 462 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + */ |
|
| 465 | + public function supports( $feature ) { |
|
| 466 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Returns the credit card form html. |
|
| 471 | + * |
|
| 472 | + * @param bool $save whether or not to display the save button. |
|
| 473 | + */ |
|
| 474 | 474 | public function get_cc_form( $save = false ) { |
| 475 | 475 | |
| 476 | - ob_start(); |
|
| 476 | + ob_start(); |
|
| 477 | 477 | |
| 478 | 478 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 479 | 479 | |
@@ -568,11 +568,11 @@ discard block |
||
| 568 | 568 | 'name' => $this->id . '[cc_cvv2]', |
| 569 | 569 | 'id' => "$id_prefix-cc-cvv2", |
| 570 | 570 | 'label' => __( 'CCV', 'invoicing' ), |
| 571 | - 'label_type' => 'vertical', |
|
| 572 | - 'class' => 'form-control-sm', |
|
| 573 | - 'extra_attributes' => array( |
|
| 574 | - 'autocomplete' => "cc-csc", |
|
| 575 | - ), |
|
| 571 | + 'label_type' => 'vertical', |
|
| 572 | + 'class' => 'form-control-sm', |
|
| 573 | + 'extra_attributes' => array( |
|
| 574 | + 'autocomplete' => "cc-csc", |
|
| 575 | + ), |
|
| 576 | 576 | ) |
| 577 | 577 | ); |
| 578 | 578 | ?> |
@@ -582,191 +582,191 @@ discard block |
||
| 582 | 582 | |
| 583 | 583 | <?php |
| 584 | 584 | |
| 585 | - if ( $save ) { |
|
| 586 | - echo $this->save_payment_method_checkbox(); |
|
| 587 | - } |
|
| 585 | + if ( $save ) { |
|
| 586 | + echo $this->save_payment_method_checkbox(); |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - ?> |
|
| 589 | + ?> |
|
| 590 | 590 | </div> |
| 591 | 591 | |
| 592 | 592 | </div> |
| 593 | 593 | <?php |
| 594 | 594 | |
| 595 | - return ob_get_clean(); |
|
| 595 | + return ob_get_clean(); |
|
| 596 | 596 | |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - /** |
|
| 600 | - * Displays a new payment method entry form. |
|
| 601 | - * |
|
| 602 | - * @since 1.0.19 |
|
| 603 | - */ |
|
| 604 | - public function new_payment_method_entry( $form ) { |
|
| 605 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Grab and display our saved payment methods. |
|
| 610 | - * |
|
| 611 | - * @since 1.0.19 |
|
| 612 | - */ |
|
| 613 | - public function saved_payment_methods() { |
|
| 614 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 615 | - |
|
| 616 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 617 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - $html .= $this->get_new_payment_method_option_html(); |
|
| 621 | - $html .= '</ul>'; |
|
| 622 | - |
|
| 623 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Gets saved payment method HTML from a token. |
|
| 628 | - * |
|
| 629 | - * @since 1.0.19 |
|
| 630 | - * @param array $token Payment Token. |
|
| 631 | - * @return string Generated payment method HTML |
|
| 632 | - */ |
|
| 633 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 634 | - |
|
| 635 | - return sprintf( |
|
| 636 | - '<li class="getpaid-payment-method form-group"> |
|
| 599 | + /** |
|
| 600 | + * Displays a new payment method entry form. |
|
| 601 | + * |
|
| 602 | + * @since 1.0.19 |
|
| 603 | + */ |
|
| 604 | + public function new_payment_method_entry( $form ) { |
|
| 605 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Grab and display our saved payment methods. |
|
| 610 | + * |
|
| 611 | + * @since 1.0.19 |
|
| 612 | + */ |
|
| 613 | + public function saved_payment_methods() { |
|
| 614 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 615 | + |
|
| 616 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 617 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + $html .= $this->get_new_payment_method_option_html(); |
|
| 621 | + $html .= '</ul>'; |
|
| 622 | + |
|
| 623 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Gets saved payment method HTML from a token. |
|
| 628 | + * |
|
| 629 | + * @since 1.0.19 |
|
| 630 | + * @param array $token Payment Token. |
|
| 631 | + * @return string Generated payment method HTML |
|
| 632 | + */ |
|
| 633 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 634 | + |
|
| 635 | + return sprintf( |
|
| 636 | + '<li class="getpaid-payment-method form-group"> |
|
| 637 | 637 | <label> |
| 638 | 638 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 639 | 639 | <span>%3$s</span> |
| 640 | 640 | </label> |
| 641 | 641 | </li>', |
| 642 | - esc_attr( $this->id ), |
|
| 643 | - esc_attr( $token['id'] ), |
|
| 644 | - esc_html( $token['name'] ), |
|
| 645 | - checked( empty( $token['default'] ), false, false ) |
|
| 646 | - ); |
|
| 642 | + esc_attr( $this->id ), |
|
| 643 | + esc_attr( $token['id'] ), |
|
| 644 | + esc_html( $token['name'] ), |
|
| 645 | + checked( empty( $token['default'] ), false, false ) |
|
| 646 | + ); |
|
| 647 | 647 | |
| 648 | - } |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - /** |
|
| 651 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 652 | - * |
|
| 653 | - * @since 1.0.19 |
|
| 654 | - */ |
|
| 655 | - public function get_new_payment_method_option_html() { |
|
| 650 | + /** |
|
| 651 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 652 | + * |
|
| 653 | + * @since 1.0.19 |
|
| 654 | + */ |
|
| 655 | + public function get_new_payment_method_option_html() { |
|
| 656 | 656 | |
| 657 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 657 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 658 | 658 | |
| 659 | - return sprintf( |
|
| 660 | - '<li class="getpaid-new-payment-method"> |
|
| 659 | + return sprintf( |
|
| 660 | + '<li class="getpaid-new-payment-method"> |
|
| 661 | 661 | <label> |
| 662 | 662 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
| 663 | 663 | <span>%2$s</span> |
| 664 | 664 | </label> |
| 665 | 665 | </li>', |
| 666 | - esc_attr( $this->id ), |
|
| 667 | - esc_html( $label ) |
|
| 668 | - ); |
|
| 669 | - |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 674 | - * |
|
| 675 | - * @since 1.0.19 |
|
| 676 | - */ |
|
| 677 | - public function save_payment_method_checkbox() { |
|
| 678 | - |
|
| 679 | - return aui()->input( |
|
| 680 | - array( |
|
| 681 | - 'type' => 'checkbox', |
|
| 682 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 683 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 684 | - 'required' => false, |
|
| 685 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 686 | - 'value' => 'true', |
|
| 687 | - 'checked' => true, |
|
| 688 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 689 | - ) |
|
| 690 | - ); |
|
| 691 | - |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Registers the gateway. |
|
| 696 | - * |
|
| 697 | - * @return array |
|
| 698 | - */ |
|
| 699 | - public function register_gateway( $gateways ) { |
|
| 700 | - |
|
| 701 | - $gateways[ $this->id ] = array( |
|
| 702 | - |
|
| 703 | - 'admin_label' => $this->method_title, |
|
| 666 | + esc_attr( $this->id ), |
|
| 667 | + esc_html( $label ) |
|
| 668 | + ); |
|
| 669 | + |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 674 | + * |
|
| 675 | + * @since 1.0.19 |
|
| 676 | + */ |
|
| 677 | + public function save_payment_method_checkbox() { |
|
| 678 | + |
|
| 679 | + return aui()->input( |
|
| 680 | + array( |
|
| 681 | + 'type' => 'checkbox', |
|
| 682 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 683 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 684 | + 'required' => false, |
|
| 685 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 686 | + 'value' => 'true', |
|
| 687 | + 'checked' => true, |
|
| 688 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 689 | + ) |
|
| 690 | + ); |
|
| 691 | + |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Registers the gateway. |
|
| 696 | + * |
|
| 697 | + * @return array |
|
| 698 | + */ |
|
| 699 | + public function register_gateway( $gateways ) { |
|
| 700 | + |
|
| 701 | + $gateways[ $this->id ] = array( |
|
| 702 | + |
|
| 703 | + 'admin_label' => $this->method_title, |
|
| 704 | 704 | 'checkout_label' => $this->title, |
| 705 | - 'ordering' => $this->order, |
|
| 705 | + 'ordering' => $this->order, |
|
| 706 | 706 | |
| 707 | - ); |
|
| 707 | + ); |
|
| 708 | 708 | |
| 709 | - return $gateways; |
|
| 709 | + return $gateways; |
|
| 710 | 710 | |
| 711 | - } |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - /** |
|
| 714 | - * Checks whether or not this is a sandbox request. |
|
| 715 | - * |
|
| 716 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 717 | - * @return bool |
|
| 718 | - */ |
|
| 719 | - public function is_sandbox( $invoice = null ) { |
|
| 713 | + /** |
|
| 714 | + * Checks whether or not this is a sandbox request. |
|
| 715 | + * |
|
| 716 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 717 | + * @return bool |
|
| 718 | + */ |
|
| 719 | + public function is_sandbox( $invoice = null ) { |
|
| 720 | 720 | |
| 721 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 722 | - return $invoice->get_mode() == 'test'; |
|
| 723 | - } |
|
| 721 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 722 | + return $invoice->get_mode() == 'test'; |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - return wpinv_is_test_mode( $this->id ); |
|
| 725 | + return wpinv_is_test_mode( $this->id ); |
|
| 726 | 726 | |
| 727 | - } |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | - /** |
|
| 730 | - * Renames the checkout button |
|
| 731 | - * |
|
| 732 | - * @return string |
|
| 733 | - */ |
|
| 734 | - public function rename_checkout_button() { |
|
| 735 | - return $this->checkout_button_text; |
|
| 736 | - } |
|
| 729 | + /** |
|
| 730 | + * Renames the checkout button |
|
| 731 | + * |
|
| 732 | + * @return string |
|
| 733 | + */ |
|
| 734 | + public function rename_checkout_button() { |
|
| 735 | + return $this->checkout_button_text; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - /** |
|
| 739 | - * Validate gateway currency |
|
| 740 | - * |
|
| 741 | - * @return bool |
|
| 742 | - */ |
|
| 743 | - public function validate_currency( $validation, $currency ) { |
|
| 738 | + /** |
|
| 739 | + * Validate gateway currency |
|
| 740 | + * |
|
| 741 | + * @return bool |
|
| 742 | + */ |
|
| 743 | + public function validate_currency( $validation, $currency ) { |
|
| 744 | 744 | |
| 745 | - // Required currencies. |
|
| 746 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 747 | - return false; |
|
| 748 | - } |
|
| 745 | + // Required currencies. |
|
| 746 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - // Excluded currencies. |
|
| 751 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 750 | + // Excluded currencies. |
|
| 751 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - return $validation; |
|
| 756 | - } |
|
| 755 | + return $validation; |
|
| 756 | + } |
|
| 757 | 757 | |
| 758 | - /** |
|
| 759 | - * Displays an error |
|
| 760 | - * |
|
| 761 | - */ |
|
| 762 | - public function show_error( $code, $message, $type ) { |
|
| 758 | + /** |
|
| 759 | + * Displays an error |
|
| 760 | + * |
|
| 761 | + */ |
|
| 762 | + public function show_error( $code, $message, $type ) { |
|
| 763 | 763 | |
| 764 | - if ( is_admin() ) { |
|
| 765 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 766 | - } |
|
| 764 | + if ( is_admin() ) { |
|
| 765 | + getpaid_admin()->{"show_$type"}( $message ); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - wpinv_set_error( $code, $message, $type ); |
|
| 768 | + wpinv_set_error( $code, $message, $type ); |
|
| 769 | 769 | |
| 770 | - } |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | 772 | } |