Making WordPress.org

Changeset 2471


Ignore:
Timestamp:
02/05/2016 12:04:01 AM (8 years ago)
Author:
iandunn
Message:

WordCamp QBO: Add filter for switching between sandbox and production API URLs.

Without something like this, we'd have to manually switch all the calls to the sandbox URL during development, then back to the production URL before committing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php

    r2470 r2471  
    1010    private static $hmac_key;
    1111
     12    private static $api_base_url;
    1213    private static $options;
    1314    private static $categories_map;
     
    4950        if ( empty( self::$consumer_key ) )
    5051            return;
     52
     53        self::$api_base_url = sprintf(
     54            'https://%squickbooks.api.intuit.com',
     55            apply_filters( 'wordcamp_qbo_sandbox_mode', false ) ? 'sandbox-' : ''
     56        );
    5157
    5258        add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
     
    140146            $payload['Id'] = absint( $request->get_param('id') );
    141147
    142             $request_url = esc_url_raw( sprintf( 'https://quickbooks.api.intuit.com/v3/company/%d/purchase/%d',
    143                 self::$options['auth']['realmId'], $payload['Id'] ) );
     148            $request_url = esc_url_raw( sprintf( '%s/v3/company/%d/purchase/%d',
     149                self::$api_base_url, self::$options['auth']['realmId'], $payload['Id'] ) );
     150
    144151            $oauth_header = $oauth->get_oauth_header( 'GET', $request_url );
    145152            $response = wp_remote_get( $request_url, array(
     
    162169
    163170        $payload = json_encode( $payload );
    164         $request_url = esc_url_raw( sprintf( 'https://quickbooks.api.intuit.com/v3/company/%d/purchase',
    165             self::$options['auth']['realmId'] ) );
     171        $request_url = esc_url_raw( sprintf( '%s/v3/company/%d/purchase',
     172            self::$api_base_url, self::$options['auth']['realmId'] ) );
    166173
    167174        $oauth_header = $oauth->get_oauth_header( 'POST', $request_url, $payload );
     
    222229        );
    223230
    224         $request_url = esc_url_raw( sprintf( 'https://quickbooks.api.intuit.com/v3/company/%d/query',
    225             self::$options['auth']['realmId'] ) );
     231        $request_url = esc_url_raw( sprintf( '%s/v3/company/%d/query',
     232            self::$api_base_url, self::$options['auth']['realmId'] ) );
    226233
    227234        $oauth_header = $oauth->get_oauth_header( 'GET', $request_url, $args );
     
    342349
    343350            $oauth->set_token( self::$options['auth']['oauth_token'], self::$options['auth']['oauth_token_secret'] );
    344             $request_url = sprintf( 'https://quickbooks.api.intuit.com/v3/company/%d/companyinfo/%d',
    345                 self::$options['auth']['realmId'], self::$options['auth']['realmId'] );
     351            $request_url = sprintf( '%s/v3/company/%d/companyinfo/%d',
     352                self::$api_base_url, self::$options['auth']['realmId'], self::$options['auth']['realmId'] );
    346353
    347354            $oauth_header = $oauth->get_oauth_header( 'GET', $request_url );
Note: See TracChangeset for help on using the changeset viewer.