<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[6834] sites/trunk/wordcamp.org/public_html/wp-content/plugins: WordCamp QBO: Apply coding standards.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/6834">6834</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/6834","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iandunn</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-03-07 01:45:42 +0000 (Wed, 07 Mar 2018)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordCamp QBO: Apply coding standards.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampqboclasswordcampqbooauthclientphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/class-wordcamp-qbo-oauth-client.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampqbowordcampqbophp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampqboclientwordcampqboclientphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo-client/wordcamp-qbo-client.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampqboclasswordcampqbooauthclientphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/class-wordcamp-qbo-oauth-client.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/class-wordcamp-qbo-oauth-client.php 2018-03-07 01:45:38 UTC (rev 6833)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/class-wordcamp-qbo-oauth-client.php 2018-03-07 01:45:42 UTC (rev 6834)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,168 +2,179 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * WordCamp QBO Oauth Client
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Note: This is NOT a general-purpose OAuth client, it is only suitable
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * SECURITY WARNING: This is NOT a general-purpose OAuth client, it is only suitable
</ins><span class="cx" style="display: block; padding: 0 10px"> * for the WordCamp QBO plugin.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class WordCamp_QBO_OAuth_Client {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private $consumer_key;
- private $consumer_secret;
- private $oauth_token;
- private $oauth_token_secret;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private $consumer_key;
+ private $consumer_secret;
+ private $oauth_token;
+ private $oauth_token_secret;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * @param string $consumer_key The OAuth consumer key
- * @param string $consumer_secret The secret
- */
- public function __construct( $consumer_key, $consumer_secret ) {
- $this->consumer_key = $consumer_key;
- $this->consumer_secret = $consumer_secret;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * @param string $consumer_key The OAuth consumer key
+ * @param string $consumer_secret The secret
+ */
+ public function __construct( $consumer_key, $consumer_secret ) {
+ $this->consumer_key = $consumer_key;
+ $this->consumer_secret = $consumer_secret;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Set current OAuth token
- *
- * @param string $oauth_token An OAuth token.
- * @param string $oauth_token_secret The OAuth token secret.
- */
- public function set_token( $oauth_token, $oauth_token_secret ) {
- $this->oauth_token = $oauth_token;
- $this->oauth_token_secret = $oauth_token_secret;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Set current OAuth token
+ *
+ * @param string $oauth_token An OAuth token.
+ * @param string $oauth_token_secret The OAuth token secret.
+ */
+ public function set_token( $oauth_token, $oauth_token_secret ) {
+ $this->oauth_token = $oauth_token;
+ $this->oauth_token_secret = $oauth_token_secret;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Get a request token.
- *
- * @param string $callback_url The URL to which a successful authentication will return.
- *
- * @return array An array with the tokens.
- */
- public function get_request_token( $request_url, $callback_url ) {
- $args = array_merge( $this->_get_default_args(), array(
- 'oauth_callback' => $callback_url,
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Get a request token.
+ *
+ * @param string $callback_url The URL to which a successful authentication will return.
+ *
+ * @return array|WP_Error An array with the tokens.
+ */
+ public function get_request_token( $request_url, $callback_url ) {
+ $args = array_merge( $this->_get_default_args(), array(
+ 'oauth_callback' => $callback_url,
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $args['oauth_signature'] = $this->_get_signature( 'POST', $request_url, $args );
- $args = array_map( 'rawurlencode', $args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args['oauth_signature'] = $this->_get_signature( 'POST', $request_url, $args );
+ $args = array_map( 'rawurlencode', $args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_post( add_query_arg( $args, $request_url ) );
- if ( is_wp_error( $response ) )
- return $response;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_post( add_query_arg( $args, $request_url ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( wp_remote_retrieve_response_code( $response ) != 200 )
- return new WP_Error( 'error', 'Could not get OAuth request token.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $response ) ) {
+ return $response;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = wp_parse_args( wp_remote_retrieve_body( $response ), array(
- 'oauth_token' => '',
- 'oauth_token_secret' => '',
- 'oauth_callback_confirmed' => '',
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( wp_remote_retrieve_response_code( $response ) != 200 ) {
+ return new WP_Error( 'error', 'Could not get OAuth request token.' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $result;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = wp_parse_args( wp_remote_retrieve_body( $response ), array(
+ 'oauth_token' => '',
+ 'oauth_token_secret' => '',
+ 'oauth_callback_confirmed' => '',
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Get an OAuth access token.
- *
- * @param string $verifier A verifier token from the authentication flow.
- *
- * @return array The access token.
- */
- public function get_access_token( $request_url, $verifier ) {
- $args = array_merge( $this->_get_default_args(), array(
- 'oauth_verifier' => $verifier,
- 'oauth_token' => $this->oauth_token,
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $result;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $args['oauth_signature'] = $this->_get_signature( 'POST', $request_url, $args );
- $args = array_map( 'rawurlencode', $args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Get an OAuth access token.
+ *
+ * @param string $verifier A verifier token from the authentication flow.
+ *
+ * @return array|WP_Error The access token.
+ */
+ public function get_access_token( $request_url, $verifier ) {
+ $args = array_merge( $this->_get_default_args(), array(
+ 'oauth_verifier' => $verifier,
+ 'oauth_token' => $this->oauth_token,
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_post( add_query_arg( $args, $request_url ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args['oauth_signature'] = $this->_get_signature( 'POST', $request_url, $args );
+ $args = array_map( 'rawurlencode', $args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_wp_error( $response ) )
- return $response;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_post( add_query_arg( $args, $request_url ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( wp_remote_retrieve_response_code( $response ) != 200 )
- return new WP_Error( 'error', 'Could not get OAuth access token.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $response ) ) {
+ return $response;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = wp_parse_args( wp_remote_retrieve_body( $response ), array(
- 'oauth_token' => '',
- 'oauth_token_secret' => '',
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( wp_remote_retrieve_response_code( $response ) != 200 ) {
+ return new WP_Error( 'error', 'Could not get OAuth access token.' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $result;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = wp_parse_args( wp_remote_retrieve_body( $response ), array(
+ 'oauth_token' => '',
+ 'oauth_token_secret' => '',
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Get a string suitable for the Authorization header.
- *
- * @see http://oauth.net/core/1.0a/#auth_header
- *
- * @param string $method The request method.
- * @param string $request_url The request URL (without query)
- * @param array|string $request_args Any additional query/body args.
- *
- * @return string An OAuth string ready for the Authorization header.
- */
- public function get_oauth_header( $method, $request_url, $request_args = array() ) {
- $oauth_args = array_merge( $this->_get_default_args(), array(
- 'oauth_token' => $this->oauth_token,
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $result;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $all_args = $oauth_args;
- if ( is_array( $request_args ) && ! empty( $request_args ) )
- $all_args = array_merge( $oauth_args, $request_args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Get a string suitable for the Authorization header.
+ *
+ * @see http://oauth.net/core/1.0a/#auth_header
+ *
+ * @param string $method The request method.
+ * @param string $request_url The request URL (without query)
+ * @param array|string $request_args Any additional query/body args.
+ *
+ * @return string An OAuth string ready for the Authorization header.
+ */
+ public function get_oauth_header( $method, $request_url, $request_args = array() ) {
+ $oauth_args = array_merge( $this->_get_default_args(), array(
+ 'oauth_token' => $this->oauth_token,
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $oauth_args['oauth_signature'] = $this->_get_signature( $method, $request_url, $all_args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $all_args = $oauth_args;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $header_parts = array();
- foreach ( $oauth_args as $key => $value )
- $header_parts[] = sprintf( '%s="%s"', rawurlencode( $key ), rawurlencode( $value ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $request_args ) && ! empty( $request_args ) ) {
+ $all_args = array_merge( $oauth_args, $request_args );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $header = 'OAuth ' . implode( ',', $header_parts );
- return $header;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $oauth_args['oauth_signature'] = $this->_get_signature( $method, $request_url, $all_args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Get a default set of OAuth arguments.
- *
- * @return array Default OAuth arguments.
- */
- private function _get_default_args() {
- return array(
- 'oauth_nonce' => md5( wp_generate_password( 12 ) ),
- 'oauth_consumer_key' => $this->consumer_key,
- 'oauth_signature_method' => 'HMAC-SHA1',
- 'oauth_timestamp' => time(),
- 'oauth_version' => '1.0',
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $header_parts = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Get an OAuth signature.
- *
- * @see http://oauth.net/core/1.0a/#signing_process
- *
- * @param string $method The request method, GET, POST, etc.
- * @param string $url The request URL (without any query)
- * @param array $args An optional array of query or body args.
- *
- * @return string A base64-encoded hmac-sha1 signature.
- */
- private function _get_signature( $method, $url, $args ) {
- ksort( $args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $oauth_args as $key => $value ) {
+ $header_parts[] = sprintf( '%s="%s"', rawurlencode( $key ), rawurlencode( $value ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Don't sign a signature.
- unset( $args['oauth_signature'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $header = 'OAuth ' . implode( ',', $header_parts );
+ return $header;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $parameter_string = '';
- foreach ( $args as $key => $value )
- $parameter_string .= sprintf( '&%s=%s', rawurlencode( $key ), rawurlencode( $value ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Get a default set of OAuth arguments.
+ *
+ * @return array Default OAuth arguments.
+ */
+ private function _get_default_args() {
+ return array(
+ 'oauth_nonce' => md5( wp_generate_password( 12 ) ),
+ 'oauth_consumer_key' => $this->consumer_key,
+ 'oauth_signature_method' => 'HMAC-SHA1',
+ 'oauth_timestamp' => time(),
+ 'oauth_version' => '1.0',
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $parameter_string = trim( $parameter_string, '&' );
- $signature_base = strtoupper( $method ) . '&' . rawurlencode( $url ) . '&' . rawurlencode( $parameter_string );
- $signing_key = rawurlencode( $this->consumer_secret ) . '&' . rawurlencode( $this->oauth_token_secret );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Get an OAuth signature.
+ *
+ * @see http://oauth.net/core/1.0a/#signing_process
+ *
+ * @param string $method The request method, GET, POST, etc.
+ * @param string $url The request URL (without any query)
+ * @param array $args An optional array of query or body args.
+ *
+ * @return string A base64-encoded hmac-sha1 signature.
+ */
+ private function _get_signature( $method, $url, $args ) {
+ ksort( $args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return base64_encode( hash_hmac( 'sha1', $signature_base, $signing_key, true ) );
- }
-}
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Don't sign a signature.
+ unset( $args['oauth_signature'] );
+
+ $parameter_string = '';
+
+ foreach ( $args as $key => $value ) {
+ $parameter_string .= sprintf( '&%s=%s', rawurlencode( $key ), rawurlencode( $value ) );
+ }
+
+ $parameter_string = trim( $parameter_string, '&' );
+ $signature_base = strtoupper( $method ) . '&' . rawurlencode( $url ) . '&' . rawurlencode( $parameter_string );
+ $signing_key = rawurlencode( $this->consumer_secret ) . '&' . rawurlencode( $this->oauth_token_secret );
+
+ return base64_encode( hash_hmac( 'sha1', $signature_base, $signing_key, true ) );
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampqbowordcampqbophp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php 2018-03-07 01:45:38 UTC (rev 6833)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php 2018-03-07 01:45:42 UTC (rev 6834)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -22,8 +22,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private static $categories_map;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public static function load_options() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( isset( self::$options ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( self::$options ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return self::$options;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$options = wp_parse_args( get_option( 'wordcamp-qbo', array() ), array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'auth' => array(),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -49,20 +50,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> self::$sandbox_mode = WORDCAMP_ENVIRONMENT !== 'production';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $init_options = wp_parse_args( apply_filters( 'wordcamp_qbo_options', array() ), array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'app_token' => '',
- 'consumer_key' => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'app_token' => '',
+ 'consumer_key' => '',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'consumer_secret' => '',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'hmac_key' => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'hmac_key' => '',
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'categories_map' => array(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'categories_map' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $init_options as $key => $value )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $init_options as $key => $value ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> self::$$key = $value;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // There's no point in doing anything if we don't have the secrets.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( self::$consumer_key ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( self::$consumer_key ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$api_base_url = sprintf(
</span><span class="cx" style="display: block; padding: 0 10px"> 'https://%squickbooks.api.intuit.com',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,22 +89,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function rest_api_init() {
</span><span class="cx" style="display: block; padding: 0 10px"> register_rest_route( 'wordcamp-qbo/v1', '/expense', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'methods' => 'GET, POST',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'methods' => 'GET, POST',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'callback' => array( __CLASS__, 'rest_callback_expense' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> register_rest_route( 'wordcamp-qbo/v1', '/invoice', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'methods' => 'GET, POST',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'methods' => 'GET, POST',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'callback' => array( __CLASS__, 'rest_callback_invoice' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> register_rest_route( 'wordcamp-qbo/v1', '/invoice_pdf', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'methods' => 'GET',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'methods' => 'GET',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'callback' => array( __CLASS__, 'rest_callback_invoice_pdf' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> register_rest_route( 'wordcamp-qbo/v1', '/paid_invoices', array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'methods' => 'GET',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'methods' => 'GET',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'callback' => array( __CLASS__, 'rest_callback_paid_invoices' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,56 +115,63 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_Request $request
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function rest_callback_expense( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! self::_is_valid_request( $request ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! self::_is_valid_request( $request ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'unauthorized', 'Unauthorized', array( 'status' => 401 ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::load_options();
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth = self::_get_oauth();
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth->set_token( self::$options['auth']['oauth_token'], self::$options['auth']['oauth_token_secret'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $amount = floatval( $request->get_param( 'amount' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $amount )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $amount ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'An amount was not given.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $description = $request->get_param( 'description' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $description ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $description ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'The expense description can not be empty.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $category = $request->get_param( 'category' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $category ) || ! array_key_exists( $category, self::$categories_map ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $category ) || ! array_key_exists( $category, self::$categories_map ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'The category you have picked is invalid.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $date = $request->get_param( 'date' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $date ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $date ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'The expense date can not be empty.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $date = absint( $date );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $class = $request->get_param( 'class' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $class ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $class ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'You need to set a class.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $classes = self::_get_classes();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! array_key_exists( $class, $classes ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! array_key_exists( $class, $classes ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'Unknown class.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $class = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'value' => $class,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'name' => $classes[ $class ],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'name' => $classes[ $class ],
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $payload = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'AccountRef' => self::$account,
- 'TxnDate' => gmdate( 'Y-m-d', $date ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'AccountRef' => self::$account,
+ 'TxnDate' => gmdate( 'Y-m-d', $date ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'PaymentType' => 'Cash',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Line' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Line' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Id' => 1,
- 'Description' => $description,
- 'Amount' => $amount,
- 'DetailType' => 'AccountBasedExpenseLineDetail',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Id' => 1,
+ 'Description' => $description,
+ 'Amount' => $amount,
+ 'DetailType' => 'AccountBasedExpenseLineDetail',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'AccountBasedExpenseLineDetail' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'ClassRef' => $class,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'ClassRef' => $class,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'AccountRef' => self::$categories_map[ $category ],
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -175,48 +185,52 @@
</span><span class="cx" style="display: block; padding: 0 10px"> self::$api_base_url, self::$options['auth']['realmId'], $payload['Id'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth_header = $oauth->get_oauth_header( 'GET', $request_url );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_get( $request_url, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_get( $request_url, array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => self::REMOTE_REQUEST_TIMEOUT,
</span><span class="cx" style="display: block; padding: 0 10px"> 'headers' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Authorization' => $oauth_header,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Accept' => 'application/json',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Accept' => 'application/json',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> Logger\log( 'remote_request_sync_token', compact( 'response' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'Could not find purchase to update.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $body = json_decode( wp_remote_retrieve_body( $response ), true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! isset( $body['Purchase']['SyncToken'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $body['Purchase']['SyncToken'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'Could not decode purchase for update.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $payload['SyncToken'] = $body['Purchase']['SyncToken'];
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $response );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $payload = json_encode( $payload );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $payload = json_encode( $payload );
</ins><span class="cx" style="display: block; padding: 0 10px"> $request_url = esc_url_raw( sprintf( '%s/v3/company/%d/purchase',
</span><span class="cx" style="display: block; padding: 0 10px"> self::$api_base_url, self::$options['auth']['realmId'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth_header = $oauth->get_oauth_header( 'POST', $request_url, $payload );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_post( $request_url, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_post( $request_url, array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => self::REMOTE_REQUEST_TIMEOUT,
</span><span class="cx" style="display: block; padding: 0 10px"> 'headers' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Authorization' => $oauth_header,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Accept' => 'application/json',
- 'Content-Type' => 'application/json',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Accept' => 'application/json',
+ 'Content-Type' => 'application/json',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => $payload,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => $payload,
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> Logger\log( 'remote_request_create_expense', compact( 'payload', 'response' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'Could not create purchase.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $body = json_decode( wp_remote_retrieve_body( $response ), true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $body ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $body ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'error', 'Could not decode create purchase result.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'transaction_id' => intval( $body['Purchase']['Id'] ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -247,7 +261,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth->set_token( self::$options['auth']['oauth_token'], self::$options['auth']['oauth_token_secret'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'query' => 'SELECT * FROM Class MAXRESULTS 1000',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'query' => 'SELECT * FROM Class MAXRESULTS 1000',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'minorversion' => 4,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -255,14 +269,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> self::$api_base_url, self::$options['auth']['realmId'] ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth_header = $oauth->get_oauth_header( 'GET', $request_url, $args );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_get(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_get(
</ins><span class="cx" style="display: block; padding: 0 10px"> esc_url_raw( add_query_arg( $args, $request_url ) ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => self::REMOTE_REQUEST_TIMEOUT,
</span><span class="cx" style="display: block; padding: 0 10px"> 'headers' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Authorization' => $oauth_header,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Accept' => 'application/json',
- )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Accept' => 'application/json',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> Logger\log( 'remote_request', compact( 'args', 'response' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -474,7 +488,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * sacrificed to make room for the complete instructions.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $description_limit = abs( 995 - strlen( $payment_instructions ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $customer_memo = sprintf(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $customer_memo = sprintf(
</ins><span class="cx" style="display: block; padding: 0 10px"> "%s\n\n%s",
</span><span class="cx" style="display: block; padding: 0 10px"> substr( $description, 0, $description_limit ),
</span><span class="cx" style="display: block; padding: 0 10px"> $payment_instructions
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -501,26 +515,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'Line' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Amount' => $amount,
- 'Description' => $line_description,
- 'DetailType' => 'SalesItemLineDetail',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Amount' => $amount,
+ 'Description' => $line_description,
+ 'DetailType' => 'SalesItemLineDetail',
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'SalesItemLineDetail' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'ItemRef' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'ItemRef' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'value' => '20', // Sponsorship
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'ClassRef' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'ClassRef' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'value' => $class_id,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'UnitPrice' => $amount,
</span><span class="cx" style="display: block; padding: 0 10px"> 'Qty' => 1,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- )
- )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'CustomerRef' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'CustomerRef' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'value' => $customer_id,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -532,7 +546,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'value' => 1, // Due on receipt
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'BillEmail' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'BillEmail' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'Address' => $customer_email,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -565,12 +579,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'Accept' => 'application/json',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Content-Type' => 'application/json',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => $payload,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => $payload,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'url' => $request_url,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'args' => $args
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'args' => $args,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -629,7 +643,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'Accept' => 'application/json',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Content-Type' => 'application/octet-stream',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => '',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -716,7 +730,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'Accept' => 'application/pdf',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Content-Type' => 'application/pdf',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => '',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -945,22 +959,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'CurrencyRef' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'value' => $currency_code
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'value' => $currency_code,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'PreferredDeliveryMethod' =>'Email',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'PreferredDeliveryMethod' => 'Email',
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'GivenName' => $sponsor['first-name'],
- 'FamilyName' => $sponsor['last-name'],
- 'CompanyName' => $sponsor['company-name'],
- 'DisplayName' => sprintf( '%s - %s', $sponsor['company-name'], $currency_code ),
- 'PrintOnCheckName' => $sponsor['company-name'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'GivenName' => $sponsor['first-name'],
+ 'FamilyName' => $sponsor['last-name'],
+ 'CompanyName' => $sponsor['company-name'],
+ 'DisplayName' => sprintf( '%s - %s', $sponsor['company-name'], $currency_code ),
+ 'PrintOnCheckName' => $sponsor['company-name'],
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'PrimaryPhone' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'PrimaryPhone' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'FreeFormNumber' => $sponsor['phone-number'],
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'PrimaryEmailAddr' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'PrimaryEmailAddr' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'Address' => $sponsor['email-address'],
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -984,7 +998,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'Accept' => 'application/json',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Content-Type' => 'application/json',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => $payload,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => $payload,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1101,16 +1115,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True if valid, false if invalid.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private static function _is_valid_request( $request ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $request->get_header( 'authorization' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $request->get_header( 'authorization' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! preg_match( '#^wordcamp-qbo-hmac (.+)$#', $request->get_header( 'authorization' ), $matches ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! preg_match( '#^wordcamp-qbo-hmac (.+)$#', $request->get_header( 'authorization' ), $matches ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $given_hmac = $matches[1];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $given_hmac = $matches[1];
</ins><span class="cx" style="display: block; padding: 0 10px"> $request_url = esc_url_raw( home_url( parse_url( home_url( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $payload = json_encode( array( strtolower( $request->get_method() ), strtolower( $request_url ),
- $request->get_body(), $request->get_query_params() ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $payload = json_encode( array(
+ strtolower( $request->get_method() ),
+ strtolower( $request_url ),
+ $request->get_body(),
+ $request->get_query_params(),
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return hash_equals( hash_hmac( 'sha256', $payload, self::$hmac_key ), $given_hmac );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1127,11 +1147,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Catch an OAuth authentication flow if it is one.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function maybe_oauth_request() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_GET['wordcamp-qbo-oauth-request'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $_GET['wordcamp-qbo-oauth-request'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_GET['wordcamp-qbo-oauth-nonce'] ) || ! wp_verify_nonce( $_GET['wordcamp-qbo-oauth-nonce'], 'oauth-request' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $_GET['wordcamp-qbo-oauth-nonce'] ) || ! wp_verify_nonce( $_GET['wordcamp-qbo-oauth-nonce'], 'oauth-request' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'Could not verify nonce.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::load_options();
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth = self::_get_oauth();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1139,15 +1161,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $_GET['oauth_token'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // We don't have an access token yet.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $request_url = 'https://oauth.intuit.com/oauth/v1/get_request_token';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_url = 'https://oauth.intuit.com/oauth/v1/get_request_token';
</ins><span class="cx" style="display: block; padding: 0 10px"> $callback_url = esc_url_raw( add_query_arg( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wordcamp-qbo-oauth-request' => 1,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wordcamp-qbo-oauth-nonce' => wp_create_nonce( 'oauth-request' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wordcamp-qbo-oauth-nonce' => wp_create_nonce( 'oauth-request' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ), admin_url() ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $request_token = $oauth->get_request_token( $request_url, $callback_url );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_wp_error( $request_token ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $request_token ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( $request_token->get_error_message() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> update_user_meta( get_current_user_id(), 'wordcamp-qbo-oauth', $request_token );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1160,40 +1183,48 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // We have a token.
</span><span class="cx" style="display: block; padding: 0 10px"> $request_token = get_user_meta( get_current_user_id(), 'wordcamp-qbo-oauth', true );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $request_token['oauth_token'] != $_GET['oauth_token'] )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $request_token['oauth_token'] != $_GET['oauth_token'] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'Could not verify OAuth token.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_GET['oauth_verifier'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $_GET['oauth_verifier'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'Could not obtain OAuth verifier.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth->set_token( $request_token['oauth_token'], $request_token['oauth_token_secret'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $request_url = 'https://oauth.intuit.com/oauth/v1/get_access_token';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $access_token = $oauth->get_access_token( $request_url, $_GET['oauth_verifier'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_wp_error( $access_token ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $access_token ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'Could not obtain an access token.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // We have an access token.
</span><span class="cx" style="display: block; padding: 0 10px"> $data = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'oauth_token' => $access_token['oauth_token'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'oauth_token' => $access_token['oauth_token'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'oauth_token_secret' => $access_token['oauth_token_secret'],
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'realmId' => $_GET['realmId'],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'realmId' => $_GET['realmId'],
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$options['auth'] = $data;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth->set_token( self::$options['auth']['oauth_token'], self::$options['auth']['oauth_token_secret'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $request_url = sprintf( '%s/v3/company/%d/companyinfo/%d',
- self::$api_base_url, self::$options['auth']['realmId'], self::$options['auth']['realmId'] );
</del><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_url = sprintf(
+ '%s/v3/company/%d/companyinfo/%d',
+ self::$api_base_url,
+ self::$options['auth']['realmId'],
+ self::$options['auth']['realmId']
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $oauth_header = $oauth->get_oauth_header( 'GET', $request_url );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_get( $request_url, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_get( $request_url, array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => self::REMOTE_REQUEST_TIMEOUT,
</span><span class="cx" style="display: block; padding: 0 10px"> 'headers' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Authorization' => $oauth_header,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Accept' => 'application/json',
- )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Accept' => 'application/json',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> Logger\log( 'remote_request', compact( 'response' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1207,7 +1238,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $company_name = $body['CompanyInfo']['CompanyName'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$options['auth']['name'] = $company_name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self::$options['auth']['name'] = $company_name;
</ins><span class="cx" style="display: block; padding: 0 10px"> self::$options['auth']['timestamp'] = time();
</span><span class="cx" style="display: block; padding: 0 10px"> self::update_options();
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampqboclientwordcampqboclientphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo-client/wordcamp-qbo-client.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo-client/wordcamp-qbo-client.php 2018-03-07 01:45:38 UTC (rev 6833)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-qbo-client/wordcamp-qbo-client.php 2018-03-07 01:45:42 UTC (rev 6834)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,8 +15,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> private static $options;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public static function load_options() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( isset( self::$options ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( self::$options ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return self::$options;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$options = wp_parse_args( get_option( 'wordcamp-qbo-client', array() ), array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'default-class' => '',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -33,11 +34,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'api_base' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $init_options as $key => $value )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $init_options as $key => $value ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> self::$$key = $value;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( self::$hmac_key ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( self::$hmac_key ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_init', array( __CLASS__, 'admin_init' ), 20 );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -45,11 +48,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function admin_init() {
</span><span class="cx" style="display: block; padding: 0 10px"> $cap = is_multisite() ? 'manage_network' : 'manage_options';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! current_user_can( $cap ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! current_user_can( $cap ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! class_exists( 'WCP_Payment_Request' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! class_exists( 'WCP_Payment_Request' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -58,16 +63,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public static function admin_notices() {
</span><span class="cx" style="display: block; padding: 0 10px"> $screen = get_current_screen();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $screen->id != 'wcp_payment_request' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $screen->id != 'wcp_payment_request' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post = get_post();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post->post_status == 'auto-draft' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post->post_status == 'auto-draft' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $data = get_post_meta( $post->ID, '_wordcamp-qbo-client-data', true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $data['last_error'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $data['last_error'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> printf( '<div class="notice error is-dismissible"><p>QBO Sync Error: %s</p></div>', esc_html( $data['last_error'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -96,13 +104,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function metabox_quickbooks() {
</span><span class="cx" style="display: block; padding: 0 10px"> self::load_options();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post = get_post();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = get_post();
</ins><span class="cx" style="display: block; padding: 0 10px"> $classes = self::get_classes();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = get_post_meta( $post->ID, '_wordcamp-qbo-client-data', true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = get_post_meta( $post->ID, '_wordcamp-qbo-client-data', true );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $selected_class = self::$options['default-class'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $data['class'] ) && array_key_exists( $data['class'], $classes ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $data['class'] ) && array_key_exists( $data['class'], $classes ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $selected_class = $data['class'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,7 +121,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php if ( empty( $data['transaction_id'] ) ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <p>This request has not been synced with QuickBooks yet.</p>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php else: ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php else : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <pre><?php echo esc_html( print_r( $data, true ) ); ?></pre>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -151,82 +160,97 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public static function save_post( $post_id, $post ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post->post_type !== WCP_Payment_Request::POST_TYPE )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post->post_type !== WCP_Payment_Request::POST_TYPE ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_POST['wordcamp-qbo-client-nonce'] ) || empty( $_POST['wordcamp-qbo-client-post'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $_POST['wordcamp-qbo-client-nonce'] ) || empty( $_POST['wordcamp-qbo-client-post'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( intval( $_POST['wordcamp-qbo-client-post'] ) !== $post->ID )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( intval( $_POST['wordcamp-qbo-client-post'] ) !== $post->ID ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! wp_verify_nonce( $_POST['wordcamp-qbo-client-nonce'], 'wordcamp-qbo-client-push-' . $post->ID ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! wp_verify_nonce( $_POST['wordcamp-qbo-client-nonce'], 'wordcamp-qbo-client-push-' . $post->ID ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'Could not verify QBO nonce. Please go back, refresh the page and try again.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // No need to push.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_POST['wordcamp-qbo-client-push'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $_POST['wordcamp-qbo-client-push'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post->post_status != 'paid' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $post->post_status != 'paid' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'A request has to be marked as paid before it could be synced to QuickBooks.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_POST['wordcamp-qbo-client-class'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $_POST['wordcamp-qbo-client-class'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'You need to set a QuickBooks class before you can sync this payment request.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $class = $_POST['wordcamp-qbo-client-class'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! array_key_exists( $class, self::get_classes() ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! array_key_exists( $class, self::get_classes() ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'The class you have picked does not exist.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = get_post_meta( $post->ID, '_wordcamp-qbo-client-data', true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = get_post_meta( $post->ID, '_wordcamp-qbo-client-data', true );
</ins><span class="cx" style="display: block; padding: 0 10px"> $txn_id = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_array( $data ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_array( $data ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = array();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // This request has not been synced before.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $data['transaction_id'] ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $data['transaction_id'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $txn_id = $data['transaction_id'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $amount = get_post_meta( $post->ID, '_camppayments_payment_amount', true );
</span><span class="cx" style="display: block; padding: 0 10px"> $amount = preg_replace( '#[^\d.-]+#', '', $amount );
</span><span class="cx" style="display: block; padding: 0 10px"> $amount = floatval( $amount );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $currency = get_post_meta( $post->ID, '_camppayments_currency', true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( strtoupper( $currency ) != 'USD' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( strtoupper( $currency ) != 'USD' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( 'Non-USD payments sync to QuickBooks is not available yet.' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $description_chunks = array( $post->post_title );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $description = get_post_meta( $post->ID, '_camppayments_description', true );
- if ( ! empty( $description ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $description = get_post_meta( $post->ID, '_camppayments_description', true );
+
+ if ( ! empty( $description ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $description_chunks[] = $description;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $description_chunks[] = esc_url_raw( get_edit_post_link( $post->ID, 'raw' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $description = implode( "\n", $description_chunks );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $description = implode( "\n", $description_chunks );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> unset( $description_chunks );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $category = get_post_meta( $post->ID, '_camppayments_payment_category', true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $date = absint( get_post_meta( $post->ID, '_camppayments_date_vendor_paid', true ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $date = absint( get_post_meta( $post->ID, '_camppayments_date_vendor_paid', true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $body = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'id' => $txn_id,
- 'date' => $date,
- 'amount' => $amount,
- 'category' => $category,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'id' => $txn_id,
+ 'date' => $date,
+ 'amount' => $amount,
+ 'category' => $category,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => $description,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'class' => $class,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'class' => $class,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body = json_encode( $body );
- $request_url = esc_url_raw( self::$api_base . '/expense/' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body = json_encode( $body );
+ $request_url = esc_url_raw( self::$api_base . '/expense/' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $request_args = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => self::REMOTE_REQUEST_TIMEOUT,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => $body,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => $body,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'headers' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Content-Type' => 'application/json',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Content-Type' => 'application/json',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'Authorization' => self::_get_auth_header( 'post', $request_url, $body ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response = wp_remote_post( $request_url, $request_args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response = wp_remote_post( $request_url, $request_args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> Logger\log( 'remote_request', compact( 'request_url', 'request_args', 'response' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -241,8 +265,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $data['last_error'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $data['transaction_id'] = $body['transaction_id'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data['timestamp'] = time();
- $data['class'] = $class;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data['timestamp'] = time();
+ $data['class'] = $class;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Remember this class for future reference.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( self::$options['default-class'] != $class ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,7 +330,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'amount' => floatval( $invoice_meta['_wcbsi_amount' ][0] ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => sanitize_text_field( $invoice_meta['_wcbsi_description' ][0] ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'statement_memo' => sprintf(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'statement_memo' => sprintf(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'WordCamp.org Invoice: %s',
</span><span class="cx" style="display: block; padding: 0 10px"> esc_url_raw( admin_url( sprintf( 'post.php?post=%s&action=edit', $invoice_id ) ) )
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,12 +363,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $oauth_header = self::_get_auth_header( 'post', $request_url, $body );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'body' => $body,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'timeout' => self::REMOTE_REQUEST_TIMEOUT,
</span><span class="cx" style="display: block; padding: 0 10px"> 'headers' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Authorization' => $oauth_header,
</span><span class="cx" style="display: block; padding: 0 10px"> 'Content-Type' => 'application/json',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'body' => $body,
</del><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -497,16 +521,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $method The request method: GET, POST, etc.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $request_url The clean request URI, without any query arguments.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $body The payload body.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $args The query arguments.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $args The query arguments.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string A sha256 HMAC signature.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private static function _get_auth_header( $method, $request_url, $body = '', $args = array() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $signature = hash_hmac( 'sha256', json_encode( array( strtolower( $method ),
- strtolower( $request_url ), $body, $args ) ), self::$hmac_key );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $signature = hash_hmac( 'sha256', json_encode( array(
+ strtolower( $method ),
+ strtolower( $request_url ),
+ $body,
+ $args,
+ ) ), self::$hmac_key );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return 'wordcamp-qbo-hmac ' . $signature;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-WordCamp_QBO_Client::load();
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+WordCamp_QBO_Client::load();
</ins></span></pre>
</div>
</div>
</body>
</html>