Making WordPress.org

Changeset 2526


Ignore:
Timestamp:
02/18/2016 10:22:32 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Budgets Dashboard: Store the corresponding QBO ID for an invoice.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/sponsor-invoices-dashboard.php

    r2519 r2526  
    55defined( 'WPINC' ) or die();
    66
    7 const LATEST_DATABASE_VERSION = 1;
     7const LATEST_DATABASE_VERSION = 2;
    88
    99if ( defined( 'DOING_AJAX' ) ) {
     
    165165                        blog_id       int( 11 )        unsigned NOT NULL default '0',
    166166                        invoice_id    int( 11 )        unsigned NOT NULL default '0',
     167                        qbo_invoice_id int( 11 )        unsigned NOT NULL default '0',
    167168                        invoice_title varchar( 75 )             NOT NULL default '',
    168169                        status        varchar( 30 )             NOT NULL default '',
     
    214215        }
    215216
     217        switch_to_blog( $site_id );
     218
    216219        $quickbooks_result = send_invoice_to_quickbooks( $site_id, $invoice_id );
    217220
    218         if ( 'sent' === $quickbooks_result ) {
     221        if ( is_int( $quickbooks_result ) ) {
     222                update_post_meta( $invoice_id, '_wcbsi_qbo_invoice_id', absint( $quickbooks_result ) );
    219223                update_invoice_status(           $site_id, $invoice_id, 'approved' );
    220224                notify_organizer_status_changed( $site_id, $invoice_id, 'approved' );
    221                 wp_send_json_success( array( 'message' => 'The invoice has been approved.' ) );
     225
     226                $result = array( 'success' => 'The invoice has been approved and e-mailed to the sponsor.' );
    222227        } else {
    223                 wp_send_json_error( array( 'error' => $quickbooks_result ) );
     228                $result = array( 'error' => $quickbooks_result );
     229        }
     230
     231        restore_current_blog();
     232
     233        if ( isset( $result['success'] ) ) {
     234                wp_send_json_success( $result );
     235        } else {
     236                wp_send_json_error( $result );
    224237        }
    225238}
     
    231244 * @param int $invoice_id
    232245 *
    233  * @return string
     246 * @return int|string
    234247 */
    235248function send_invoice_to_quickbooks( $site_id, $invoice_id ) {
     
    262275
    263276        $sent = 'QuickBooks integration is not complete yet.';
    264         // todo return 'sent' (string) on success, or an error message string on failure
     277        // todo return QBO invoice ID on success, or an error message string on failure
    265278
    266279        restore_current_blog();
     
    420433                'blog_id'       => get_current_blog_id(),
    421434                'invoice_id'    => $invoice_id,
     435                'qbo_invoice_id' => get_post_meta( $invoice_id, '_wcbsi_qbo_invoice_id', true ),
    422436                'invoice_title' => $invoice->post_title,
    423437                'status'        => $invoice->post_status,
     
    430444        );
    431445
    432         $formats = array( '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%f' );
     446        $formats = array( '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%f' );
    433447
    434448        $wpdb->replace( get_index_table_name(), $index_row, $formats );
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/javascript/sponsor-invoices.js

    r2355 r2526  
    5050                                                        if ( response.hasOwnProperty( 'success' ) && true === response.success ) {
    5151                                                                statusMessage.addClass( 'notice notice-success' );
    52                                                                 statusMessage.html( _.escape( response.data.message ) );
     52                                                                statusMessage.html( _.escape( response.data.success ) );
    5353                                                        } else {
    5454                                                                statusMessage.addClass( 'notice notice-error' );
Note: See TracChangeset for help on using the changeset viewer.