Working on releaser.

This commit is contained in:
Remco Tolsma 2022-10-21 14:58:20 +02:00
parent 5ec8f4c223
commit 0f737972c1
2 changed files with 79 additions and 1 deletions

View File

@ -5,9 +5,11 @@
> **Note**
> WooCommerce Helper is part of WooCommerce as of version 3.1. Purchase, connect, download products, and activate keys in one place with ease. Read more at Managing WooCommerce.com subscriptions.
http://woodojo.s3.amazonaws.com/downloads/woothemes-updater/woothemes-updater.zip
- https://woocommerce.com/document/woocommerce-helper/
- http://woodojo.s3.amazonaws.com/downloads/woothemes-updater/woothemes-updater.zip
## WooCommerce API
- https://woocommerce.com/wc-api/product-key-api
- https://woocommerce.com/wc-api/product-key-api?request=check
- https://woocommerce.com/wp-json/helper/1.0

View File

@ -13,3 +13,79 @@ function run( $command, &$result_code = null ) {
return $last_line;
}
/**
* WooCommerce Helper API authentication.
*
* @link https://github.com/woocommerce/woocommerce/blob/ca91250b2e17e88c902e460135c0531b3f632d90/plugins/woocommerce/includes/admin/helper/class-wc-helper-api.php#L67-L118
*/
$access_token = getenv( 'WOOCOMMERCE_HELPER_ACCESS_TOKEN' );
$access_token_secret = getenv( 'WOOCOMMERCE_HELPER_ACCESS_TOKEN_SECRET' );
if ( empty( $access_token ) ) {
echo 'WooCommerce Helper API acces token not defined in `WOOCOMMERCE_HELPER_ACCESS_TOKEN` environment variable.';
exit( 1 );
}
if ( empty( $access_token_secret ) ) {
echo 'WooCommerce Helper API acces token secret not defined in `WOOCOMMERCE_HELPER_ACCESS_TOKEN_SECRET` environment variable.';
exit( 1 );
}
// Subscriptions.
$url = 'https://woocommerce.com/wp-json/helper/1.0/subscriptions';
$data = array(
'host' => parse_url( $url, PHP_URL_HOST ),
'request_uri' => parse_url( $url, PHP_URL_PATH ),
'method' => 'GET',
);
$signature = hash_hmac( 'sha256', json_encode( $data ), $access_token_secret );
$url .= '?' . http_build_query(
[
'token' => $access_token,
'signature' => $signature,
]
);
$command = "curl -X GET '$url' -H 'Authorization: Bearer $access_token' -H 'X-Woo-Signature: $signature';";
run( $command );
// Check
$payload = [
27147 => [
'product_id' => 27147,
'file_id' => '',
],
];
ksort( $payload );
$body = json_encode( array( 'products' => $payload ) );
$url = 'https://woocommerce.com/wp-json/helper/1.0/update-check';
$data = array(
'host' => parse_url( $url, PHP_URL_HOST ),
'request_uri' => parse_url( $url, PHP_URL_PATH ),
'method' => 'POST',
'body' => $body,
);
$signature = hash_hmac( 'sha256', json_encode( $data ), $access_token_secret );
$url .= '?' . http_build_query(
[
'token' => $access_token,
'signature' => $signature,
]
);
$command = "curl -d '$body' -X POST '$url' -H 'Authorization: Bearer $access_token' -H 'X-Woo-Signature: $signature';";
run( $command );