This commit is contained in:
Prospress Inc
2018-12-12 14:48:11 +01:00
committed by Remco Tolsma
parent 37367ac369
commit 721dda6e5c
340 changed files with 5114 additions and 2125 deletions

36
includes/api/class-wc-rest-subscriptions-controller.php Executable file → Normal file
View File

@@ -90,9 +90,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
$response->data['resubscribed_subscription'] = strval( reset( $resubscribed_subscriptions ) ); // Subscriptions can only be resubscribed to once so return the first and only element.
foreach ( array( 'start', 'trial_end', 'next_payment', 'end' ) as $date_type ) {
$date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type;
$date = $subscription->get_date( $date_type_key );
$date = $subscription->get_date( $date_type );
$response->data[ $date_type . '_date' ] = ( ! empty( $date ) ) ? wc_rest_prepare_date_response( $date ) : '';
}
@@ -296,6 +294,10 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
$payment_method_meta = apply_filters( 'woocommerce_subscription_payment_meta', array(), $subscription );
// Reload the subscription to update the meta values.
// In particular, the update_post_meta() called while _stripe_card_id is updated to _stripe_source_id
$subscription = wcs_get_subscription( $subscription->get_id() );
if ( isset( $payment_method_meta[ $payment_method ] ) ) {
$payment_method_meta = $payment_method_meta[ $payment_method ];
@@ -318,6 +320,9 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
$subscription->set_payment_method( $payment_method, $payment_method_meta );
// Save the subscription to reflect the new values
$subscription->save();
} catch ( Exception $e ) {
$subscription->set_payment_method();
$subscription->save();
@@ -346,14 +351,14 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
if ( ! is_null( $value ) ) {
switch ( $key ) {
case 'billing' :
case 'shipping' :
case 'billing':
case 'shipping':
$this->update_address( $subscription, $value, $key );
break;
case 'line_items' :
case 'shipping_lines' :
case 'fee_lines' :
case 'coupon_lines' :
case 'line_items':
case 'shipping_lines':
case 'fee_lines':
case 'coupon_lines':
if ( is_array( $value ) ) {
foreach ( $value as $item ) {
if ( is_array( $item ) ) {
@@ -366,14 +371,13 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
}
}
break;
case 'start_date' :
case 'trial_end_date' :
case 'next_payment_date' :
case 'end_date' :
$date_type_key = ( 'start_date' === $key ) ? 'date_created' : $key;
$dates_to_update[ $date_type_key ] = $value;
case 'start_date':
case 'trial_end_date':
case 'next_payment_date':
case 'end_date':
$dates_to_update[ $key ] = $value;
break;
default :
default:
if ( is_callable( array( $subscription, "set_{$key}" ) ) ) {
$subscription->{"set_{$key}"}( $value );
}