Code Duplication    Length = 38-38 lines in 2 locations

includes/compat/class-wc-stripe-compat.php 1 location

@@ 529-566 (lines=38) @@
526
	 * @param int $order_id
527
	 * @return array
528
	 */
529
	public function process_pre_order( $order_id, $retry, $force_save_source ) {
530
		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
531
			try {
532
				$order = wc_get_order( $order_id );
533
534
				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
535
					/* translators: minimum amount */
536
					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
537
				}
538
539
				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
540
541
				// We need a source on file to continue.
542
				if ( empty( $source->customer ) || empty( $source->source ) ) {
543
					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
544
				}
545
546
				$this->save_source_to_order( $order, $source );
547
548
				// Remove cart
549
				WC()->cart->empty_cart();
550
551
				// Is pre ordered!
552
				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
553
554
				// Return thank you page redirect
555
				return array(
556
					'result'   => 'success',
557
					'redirect' => $this->get_return_url( $order ),
558
				);
559
			} catch ( Exception $e ) {
560
				wc_add_notice( $e->getMessage(), 'error' );
561
				return;
562
			}
563
		} else {
564
			return parent::process_payment( $order_id, $retry, $force_save_source );
565
		}
566
	}
567
568
	/**
569
	 * Process a pre-order payment when the pre-order is released

includes/compat/class-wc-stripe-sepa-compat.php 1 location

@@ 434-471 (lines=38) @@
431
	 * @param int $order_id
432
	 * @return array
433
	 */
434
	public function process_pre_order( $order_id, $retry, $force_save_source ) {
435
		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
436
			try {
437
				$order = wc_get_order( $order_id );
438
439
				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
440
					/* translators: minimum amount */
441
					throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
442
				}
443
444
				$source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true );
445
446
				// We need a source on file to continue.
447
				if ( empty( $source->customer ) || empty( $source->source ) ) {
448
					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
449
				}
450
451
				$this->save_source_to_order( $order, $source );
452
453
				// Remove cart
454
				WC()->cart->empty_cart();
455
456
				// Is pre ordered!
457
				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
458
459
				// Return thank you page redirect
460
				return array(
461
					'result'   => 'success',
462
					'redirect' => $this->get_return_url( $order ),
463
				);
464
			} catch ( Exception $e ) {
465
				wc_add_notice( $e->getMessage(), 'error' );
466
				return;
467
			}
468
		} else {
469
			return parent::process_payment( $order_id, $retry, $force_save_source );
470
		}
471
	}
472
473
	/**
474
	 * Process a pre-order payment when the pre-order is released