Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Updating subscription via API sets start_date to now #542

Closed snnx closed 7 months ago

snnx commented 7 months ago

Describe the bug

If I push an update to a subscription via the API, it changes start_date to the current time.

To Reproduce

With an existing subscription

Run cURL command (as per https://woocommerce.github.io/subscriptions-rest-api-docs/#update-a-subscription)

curl -X PUT https://example.om/wp-json/wc/v3/subscriptions/123456 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "next_payment_date": "2023-12-06 12:47:01"
}'

Check out subscription in admin and start_date has changed:

CleanShot 2023-11-14 at 15 42 55

Expected behavior

Shouldn't change start_date if you are just editing a subscription

Actual behavior

Updates start_date to current time

Product impact

Additional context

Possible solution is to add $creating as below to start_date if statement within method prepare_object_for_database in class-wc-rest-subscriptions-controller.php, as when not creating and not setting the start_date in cURL json above, then the start_date is reset to now.

if ( $creating && ! isset( $request['start_date'] ) ) {
    $request['start_date'] = gmdate( 'Y-m-d H:i:s' );
}
bryceadams commented 7 months ago

+1 Confirmed this bug on 5.7.0.