Code Duplication    Length = 14-15 lines in 2 locations

includes/api/class-wc-api-orders.php 1 location

@@ 484-498 (lines=15) @@
481
			$order->calculate_totals();
482
483
			// payment method (and payment_complete() if `paid` == true)
484
			if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) {
485
486
				// method ID & title are required
487
				if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) {
488
					throw new WC_API_Exception( 'woocommerce_invalid_payment_details', __( 'Payment method ID and title are required', 'woocommerce' ), 400 );
489
				}
490
491
				update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
492
				update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
493
494
				// mark as paid if set
495
				if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) {
496
					$order->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : '' );
497
				}
498
			}
499
500
			// set order currency
501
			if ( isset( $data['currency'] ) ) {

includes/cli/class-wc-cli-order.php 1 location

@@ 148-161 (lines=14) @@
145
			$order->calculate_totals();
146
147
			// payment method (and payment_complete() if `paid` == true)
148
			if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) {
149
				// method ID & title are required
150
				if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) {
151
					throw new WC_CLI_Exception( 'woocommerce_invalid_payment_details', __( 'Payment method ID and title are required', 'woocommerce' ) );
152
				}
153
154
				update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
155
				update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
156
157
				// Mark as paid if set.
158
				if ( isset( $data['payment_details']['paid'] ) && $this->is_true( $data['payment_details']['paid'] ) ) {
159
					$order->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : '' );
160
				}
161
			}
162
163
			// Set order currency.
164
			if ( isset( $data['currency'] ) ) {