Skip to content

Commit

Permalink
Merge pull request #178 from ConvertKit/v4-api-oauth
Browse files Browse the repository at this point in the history
v4 API
  • Loading branch information
n7studios authored Jul 3, 2024
2 parents 3a7c26b + ce11073 commit 1b1728b
Show file tree
Hide file tree
Showing 54 changed files with 1,270 additions and 796 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php"
files: "vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php"

# Deploy to wordpress.org
- name: WordPress Plugin Deploy
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
CONVERTKIT_API_SECRET: ${{ secrets.CONVERTKIT_API_SECRET }} # ConvertKit API Secret, stored in the repository's Settings > Secrets
CONVERTKIT_API_KEY_NO_DATA: ${{ secrets.CONVERTKIT_API_KEY_NO_DATA }} # ConvertKit API Key for ConvertKit account with no data, stored in the repository's Settings > Secrets
CONVERTKIT_API_SECRET_NO_DATA: ${{ secrets.CONVERTKIT_API_SECRET_NO_DATA }} # ConvertKit API Secret for ConvertKit account with no data, stored in the repository's Settings > Secrets
CONVERTKIT_OAUTH_ACCESS_TOKEN: ${{ secrets.CONVERTKIT_OAUTH_ACCESS_TOKEN }}
CONVERTKIT_OAUTH_REFRESH_TOKEN: ${{ secrets.CONVERTKIT_OAUTH_REFRESH_TOKEN }}
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA: ${{ secrets.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA: ${{ secrets.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_CLIENT_ID: ${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }}
CONVERTKIT_OAUTH_REDIRECT_URI: ${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }}

# Defines the WordPress and PHP Versions matrix to run tests on
# WooCommerce 5.9.0 requires WordPress 5.6 or greater, so we do not test on earlier versions
Expand Down Expand Up @@ -174,6 +180,12 @@ jobs:
CONVERTKIT_API_SECRET=${{ env.CONVERTKIT_API_SECRET }}
CONVERTKIT_API_KEY_NO_DATA=${{ env.CONVERTKIT_API_KEY_NO_DATA }}
CONVERTKIT_API_SECRET_NO_DATA=${{ env.CONVERTKIT_API_SECRET_NO_DATA }}
CONVERTKIT_OAUTH_ACCESS_TOKEN=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN }}
CONVERTKIT_OAUTH_REFRESH_TOKEN=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN }}
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_CLIENT_ID=${{ env.CONVERTKIT_OAUTH_CLIENT_ID }}
CONVERTKIT_OAUTH_REDIRECT_URI=${{ env.CONVERTKIT_OAUTH_REDIRECT_URI }}
write-mode: append

# Installs wp-browser, Codeception, PHP CodeSniffer and anything else needed to run tests.
Expand Down
2 changes: 1 addition & 1 deletion admin/class-ckwc-admin-refresh-resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function enqueue_scripts( $hook ) {
// Get integration.
$integration = WP_CKWC_Integration();

// Bail if no API keys are defined.
// Bail if the integration is not authenticated with OAuth and not enabled.
if ( ! $integration->is_enabled() ) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "project",
"license": "GPLv3",
"require": {
"convertkit/convertkit-wordpress-libraries": "1.4.2"
"convertkit/convertkit-wordpress-libraries": "2.0.0"
},
"require-dev": {
"lucatume/wp-browser": "<3.5",
Expand Down
20 changes: 13 additions & 7 deletions includes/class-ckwc-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @package CKWC
* @author ConvertKit
*/
class CKWC_API extends ConvertKit_API {
class CKWC_API extends ConvertKit_API_V4 {

/**
* Holds the log class for writing to the log file
Expand All @@ -34,16 +34,22 @@ class CKWC_API extends ConvertKit_API {
*
* @since 1.4.2
*
* @param bool|string $api_key ConvertKit API Key.
* @param bool|string $api_secret ConvertKit API Secret.
* @param bool|object $debug Save data to log.
* @param string $client_id OAuth Client ID.
* @param string $redirect_uri OAuth Redirect URI.
* @param bool|string $access_token ConvertKit OAuth Access Token.
* @param bool|string $refresh_token ConvertKit OAuth Refresh Token.
* @param bool|object $debug Save data to log.
* @param bool|string $context Context of originating request.
*/
public function __construct( $api_key = false, $api_secret = false, $debug = false ) {
public function __construct( $client_id, $redirect_uri, $access_token = false, $refresh_token = false, $debug = false, $context = false ) {

// Set API credentials, debugging and logging class.
$this->api_key = $api_key;
$this->api_secret = $api_secret;
$this->client_id = $client_id;
$this->redirect_uri = $redirect_uri;
$this->access_token = $access_token;
$this->refresh_token = $refresh_token;
$this->debug = $debug;
$this->context = $context;
$this->plugin_name = ( defined( 'CKWC_PLUGIN_NAME' ) ? CKWC_PLUGIN_NAME : false );
$this->plugin_path = ( defined( 'CKWC_PLUGIN_PATH' ) ? CKWC_PLUGIN_PATH : false );
$this->plugin_url = ( defined( 'CKWC_PLUGIN_URL' ) ? CKWC_PLUGIN_URL : false );
Expand Down
2 changes: 1 addition & 1 deletion includes/class-ckwc-cli-sync-past-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __invoke( $args, $arguments ) {

// Bail if the integration isn't enabled.
if ( ! $this->integration->is_enabled() ) {
WP_CLI::error( __( 'Please enable the integration at WooCommerce > Settings > Integration > ConvertKit, entering an API Key and Secret.', 'woocommerce-convertkit' ) );
WP_CLI::error( __( 'Please connect your ConvertKit account and enable the integration at WooCommerce > Settings > Integration > ConvertKit.', 'woocommerce-convertkit' ) );
}

// Fetch all WooCommerce Orders not sent to ConvertKit.
Expand Down
Loading

0 comments on commit 1b1728b

Please sign in to comment.