Skip to content

Commit 57baa28

Browse files
committed
Merge release into alpha
2 parents f41a692 + f8b4acc commit 57baa28

File tree

6 files changed

+147
-30
lines changed

6 files changed

+147
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
# [1.115.0-alpha.1](https://github.com/Automattic/newspack-plugin/compare/v1.114.0...v1.115.0-alpha.1) (2023-05-08)
1+
## [1.114.1](https://github.com/Automattic/newspack-plugin/compare/v1.114.0...v1.114.1) (2023-05-10)
22

33

44
### Bug Fixes
55

6-
* add filter to prompt conflicts check ([#2421](https://github.com/Automattic/newspack-plugin/issues/2421)) ([8d1c1d3](https://github.com/Automattic/newspack-plugin/commit/8d1c1d3e17ae51f97a7d783b05c4fef4a2b6660e))
7-
* check for required plugins in RAS setup wizard ([#2442](https://github.com/Automattic/newspack-plugin/issues/2442)) ([0d5bb63](https://github.com/Automattic/newspack-plugin/commit/0d5bb63e028a13f47712150787f707593a68e969))
8-
* ensure .hooks is excluded from the dist ZIP ([#2420](https://github.com/Automattic/newspack-plugin/issues/2420)) ([75f8f36](https://github.com/Automattic/newspack-plugin/commit/75f8f3665bc19ee65333726906e42a1a8724ef25))
9-
* **newsletters:** only attempt token verification for Constant Contact ([#2407](https://github.com/Automattic/newspack-plugin/issues/2407)) ([c58f9a8](https://github.com/Automattic/newspack-plugin/commit/c58f9a8c8036d5c86987768a20117bf7d3c00d68))
10-
* **perfmatters:** exclude Jetpack and Newsletters css delay ([#2410](https://github.com/Automattic/newspack-plugin/issues/2410)) ([d2b167c](https://github.com/Automattic/newspack-plugin/commit/d2b167c19ecc851ef8a3a3a1d052d28c23a1ac83))
11-
* **ras-defaults:** feedback from QA ([#2437](https://github.com/Automattic/newspack-plugin/issues/2437)) ([1dd1f36](https://github.com/Automattic/newspack-plugin/commit/1dd1f369427c137f9c24a72a559370a264b77def))
12-
* **ras-defaults:** updates for design review feedback ([#2435](https://github.com/Automattic/newspack-plugin/issues/2435)) ([3aa6de7](https://github.com/Automattic/newspack-plugin/commit/3aa6de7e9a77d9640f3b42c2e9bf8182f3dc2d1b))
13-
14-
15-
### Features
16-
17-
* **auth:** support "register modal" hash url ([#2427](https://github.com/Automattic/newspack-plugin/issues/2427)) ([fcb1199](https://github.com/Automattic/newspack-plugin/commit/fcb119964dbe6e977efa0ce5d236b736a6af79b0))
18-
* memberships block patterns ([#2406](https://github.com/Automattic/newspack-plugin/issues/2406)) ([c96555a](https://github.com/Automattic/newspack-plugin/commit/c96555a7297b82644dfa67fb873692411890debc))
19-
* RAS setup UI and default Campaigns wizard ([#2426](https://github.com/Automattic/newspack-plugin/issues/2426)) ([a1d4eb7](https://github.com/Automattic/newspack-plugin/commit/a1d4eb7aad13449cb1d847fb25ee2414028fdb69)), closes [#2381](https://github.com/Automattic/newspack-plugin/issues/2381) [#2366](https://github.com/Automattic/newspack-plugin/issues/2366) [#2382](https://github.com/Automattic/newspack-plugin/issues/2382)
20-
* **sign-in:** body class when in modal and url hash ([#2414](https://github.com/Automattic/newspack-plugin/issues/2414)) ([aea4dc9](https://github.com/Automattic/newspack-plugin/commit/aea4dc949439f459465fa15c695639a65dcb26f8))
21-
* update NRH settings page and redirect behavior ([#2425](https://github.com/Automattic/newspack-plugin/issues/2425)) ([f7a6c6b](https://github.com/Automattic/newspack-plugin/commit/f7a6c6b5d9ef5876c1128407b541a6d8cd986a95))
6+
* ensure migrated Stripe subs have next_payment scheduled ([#2434](https://github.com/Automattic/newspack-plugin/issues/2434)) ([b3b32f0](https://github.com/Automattic/newspack-plugin/commit/b3b32f0bfc09a6cf296153f783778c146e3b8291))
227

238
# [1.114.0](https://github.com/Automattic/newspack-plugin/compare/v1.113.1...v1.114.0) (2023-05-08)
249

includes/reader-revenue/class-woocommerce-connection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ public static function add_wc_stripe_gateway_metadata( $order, $metadata ) {
482482
if ( isset( $metadata['stripe_intent_id'] ) ) {
483483
$order->add_meta_data( '_stripe_intent_id', $metadata['stripe_intent_id'] );
484484
}
485+
if ( isset( $metadata['stripe_next_payment_date'] ) ) {
486+
$order->add_meta_data( '_stripe_next_payment_date', $metadata['stripe_next_payment_date'] );
487+
}
485488
if ( 'completed' === $order->get_status() ) {
486489
$order->add_meta_data( '_stripe_charge_captured', 'yes' );
487490
}
@@ -701,6 +704,14 @@ public static function create_transaction( $order_data ) {
701704
update_post_meta( $subscription_id, self::SUBSCRIPTION_STRIPE_ID_META_KEY, $stripe_subscription_id );
702705
}
703706

707+
// Ensure the next payment is scheduled.
708+
$next_payment_date = isset( $order_data['stripe_next_payment_date'] ) ? self::convert_timestamp_to_date( $order_data['stripe_next_payment_date'] ) : $subscription->calculate_date( 'next_payment' );
709+
$subscription->update_dates(
710+
[
711+
'next_payment' => $next_payment_date,
712+
]
713+
);
714+
704715
$subscription->save();
705716

706717
Logger::log( 'Created WC subscription with id: ' . $subscription_id );

includes/reader-revenue/stripe/class-stripe-sync.php

Lines changed: 129 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,9 @@ public static function sync_stripe_connect_to_stripe( $args, $assoc_args ) {
423423
* @param array $assoc_args Associative args.
424424
*/
425425
public static function sync_stripe_subscriptions_to_wc( $args, $assoc_args ) {
426-
$is_dry_run = ! empty( $assoc_args['dry-run'] );
427-
$batch_size = ! empty( $assoc_args['batch-size'] ) ? intval( $assoc_args['batch-size'] ) : 10;
426+
$is_dry_run = ! empty( $assoc_args['dry-run'] );
427+
$force_override = ! empty( $assoc_args['force'] );
428+
$batch_size = ! empty( $assoc_args['batch-size'] ) ? intval( $assoc_args['batch-size'] ) : 10;
428429

429430
\WP_CLI::log(
430431
'
@@ -442,8 +443,9 @@ public static function sync_stripe_subscriptions_to_wc( $args, $assoc_args ) {
442443
self::process_stripe_subscriber(
443444
$customer,
444445
[
445-
'dry_run' => $is_dry_run,
446-
'migrate_to_wc' => true,
446+
'dry_run' => $is_dry_run,
447+
'force_subscription_override' => $force_override,
448+
'migrate_to_wc' => true,
447449
]
448450
);
449451

@@ -456,6 +458,75 @@ public static function sync_stripe_subscriptions_to_wc( $args, $assoc_args ) {
456458
\WP_CLI::success( 'Finished processing.' );
457459
}
458460

461+
/**
462+
* CLI command for finding previously migrated Stripe Subscriptions in Woo and ensuring they have a next payment date set.
463+
*
464+
* @param array $args Positional args.
465+
* @param array $assoc_args Associative args.
466+
*/
467+
public static function set_next_payment_dates_for_migrated_subscriptions( $args, $assoc_args ) {
468+
$is_dry_run = ! empty( $assoc_args['dry-run'] );
469+
$batch_size = ! empty( $assoc_args['batch-size'] ) ? intval( $assoc_args['batch-size'] ) : 10;
470+
471+
\WP_CLI::log(
472+
'
473+
474+
Running script to set next payment dates on migrated subscriptions...
475+
476+
'
477+
);
478+
479+
480+
$migrated_subscriptions = self::get_migrated_subscriptions( $batch_size );
481+
$offset = 0;
482+
$processed = 0;
483+
while ( $migrated_subscriptions ) {
484+
$subscription_id = array_shift( $migrated_subscriptions );
485+
486+
// Set next payment date.
487+
$subscription = \wcs_get_subscription( $subscription_id );
488+
if ( $subscription ) {
489+
\WP_CLI::log(
490+
sprintf(
491+
'Found subscription with ID %d and start date %s.',
492+
$subscription_id,
493+
$subscription->get_date( 'start' )
494+
)
495+
);
496+
497+
// Get the next payment date.
498+
$next_payment_date = $subscription->get_date( 'next_payment' );
499+
500+
// If there's no next payment, set it.
501+
if ( ! $next_payment_date ) {
502+
$next_payment_date = $subscription->calculate_date( 'next_payment' );
503+
\WP_CLI::log( sprintf( 'No next payment date set. Setting to %s.', $next_payment_date ) );
504+
505+
if ( ! $is_dry_run ) {
506+
$subscription->update_dates(
507+
[
508+
'next_payment' => $next_payment_date,
509+
]
510+
);
511+
512+
$subscription->save();
513+
}
514+
$processed ++;
515+
} else {
516+
\WP_CLI::log( sprintf( 'Next payment date already set to %s. Skipping.', $next_payment_date ) );
517+
}
518+
}
519+
520+
// Get the next batch.
521+
if ( empty( $migrated_subscriptions ) ) {
522+
$offset += $batch_size;
523+
$migrated_subscriptions = self::get_migrated_subscriptions( $batch_size, $offset );
524+
}
525+
}
526+
527+
\WP_CLI::success( sprintf( 'Finished processing %d subscriptions.', $processed ) );
528+
}
529+
459530
/**
460531
* Get a batch of customers for the Stripe-Connect-to-Stripe CLI tool.
461532
*
@@ -484,6 +555,29 @@ protected static function get_batch_of_customers_with_subscriptions( $limit, $la
484555
}
485556
}
486557

558+
/**
559+
* Get a batch of migrated subscriptions.
560+
*
561+
* @param int $batch_size Number of subscriptions to fetch.
562+
* @param int $offset Offset to start at.
563+
* @return array Array of WC Subscriptions.
564+
*/
565+
protected static function get_migrated_subscriptions( $batch_size = 0, $offset = 0 ) {
566+
$args = [
567+
'fields' => 'ids',
568+
'offset' => $offset,
569+
'post_status' => 'wc-active',
570+
'post_type' => 'shop_subscription',
571+
'posts_per_page' => $batch_size,
572+
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
573+
'key' => 'cancelled-newspack-stripe-subscription-id',
574+
'compare' => 'EXISTS',
575+
],
576+
];
577+
578+
return \get_posts( $args );
579+
}
580+
487581
/**
488582
* Process one customer's Stripe subscriptions and migrate them.
489583
*
@@ -514,7 +608,7 @@ protected static function process_stripe_subscriber( $customer, $args ) {
514608
continue;
515609
}
516610

517-
if ( 'active' !== $existing_subscription->status ) {
611+
if ( ! in_array( $existing_subscription->status, [ 'active', 'trialing' ], true ) ) {
518612
\WP_CLI::log( ' - Subscription is not active. Skipping.' );
519613
return;
520614
}
@@ -544,8 +638,9 @@ protected static function process_stripe_subscriber( $customer, $args ) {
544638
$source_id = $customer->invoice_settings->default_payment_method ?? $customer->default_source;
545639

546640
$stripe_metadata_base = [
547-
'stripe_customer_id' => $customer->id,
548-
'stripe_source_id' => $source_id,
641+
'stripe_customer_id' => $customer->id,
642+
'stripe_source_id' => $source_id,
643+
'stripe_next_payment_date' => $existing_subscription->current_period_end,
549644
];
550645

551646
// Check if this subscription is already synchronised (shadowed) in WooCommerce.
@@ -691,7 +786,33 @@ public static function wp_cli() {
691786
'newspack stripe sync-stripe-subscriptions-to-wc',
692787
[ __CLASS__, 'sync_stripe_subscriptions_to_wc' ],
693788
[
694-
'shortdesc' => __( 'Migrate subscribtions from Stripe to WC', 'newspack' ),
789+
'shortdesc' => __( 'Migrate subscriptions from Stripe to WC', 'newspack' ),
790+
'synopsis' => [
791+
[
792+
'type' => 'flag',
793+
'name' => 'dry-run',
794+
'optional' => true,
795+
],
796+
[
797+
'type' => 'flag',
798+
'name' => 'force',
799+
'optional' => true,
800+
],
801+
[
802+
'type' => 'flag',
803+
'name' => 'batch-size',
804+
'default' => 10,
805+
'optional' => true,
806+
],
807+
],
808+
]
809+
);
810+
811+
\WP_CLI::add_command(
812+
'newspack stripe set-next-payment-dates-for-migrated-subscriptions',
813+
[ __CLASS__, 'set_next_payment_dates_for_migrated_subscriptions' ],
814+
[
815+
'shortdesc' => __( 'Ensure that all migrated subscriptions have a next payment date.', 'newspack' ),
695816
'synopsis' => [
696817
[
697818
'type' => 'flag',

newspack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Newspack
44
* Description: An advanced open-source publishing and revenue-generating platform for news organizations.
5-
* Version: 1.115.0-alpha.1
5+
* Version: 1.114.1
66
* Author: Automattic
77
* Author URI: https://newspack.com/
88
* License: GPL2
@@ -14,7 +14,7 @@
1414

1515
defined( 'ABSPATH' ) || exit;
1616

17-
define( 'NEWSPACK_PLUGIN_VERSION', '1.115.0-alpha.1' );
17+
define( 'NEWSPACK_PLUGIN_VERSION', '1.114.1' );
1818

1919
// Load language files.
2020
load_plugin_textdomain( 'newspack-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "newspack",
3-
"version": "1.115.0-alpha.1",
3+
"version": "1.114.1",
44
"description": "The Newspack plugin. https://newspack.com",
55
"bugs": {
66
"url": "https://github.com/Automattic/newspack-plugin/issues"

0 commit comments

Comments
 (0)