Code Duplication    Length = 38-38 lines in 2 locations

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

@@ 508-545 (lines=38) @@
505
	 * @param int $order_id
506
	 * @return array
507
	 */
508
	public function process_pre_order( $order_id, $retry, $force_save_source ) {
509
		if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) {
510
			try {
511
				$order = wc_get_order( $order_id );
512
513
				if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
514
					/* translators: minimum amount */
515
					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 ) ) );
516
				}
517
518
				$prepared_source = $this->prepare_source( get_current_user_id(), true );
519
520
				// We need a source on file to continue.
521
				if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) {
522
					throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) );
523
				}
524
525
				$this->save_source_to_order( $order, $prepared_source );
526
527
				// Remove cart
528
				WC()->cart->empty_cart();
529
530
				// Is pre ordered!
531
				WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order );
532
533
				// Return thank you page redirect
534
				return array(
535
					'result'   => 'success',
536
					'redirect' => $this->get_return_url( $order ),
537
				);
538
			} catch ( Exception $e ) {
539
				wc_add_notice( $e->getMessage(), 'error' );
540
				return;
541
			}
542
		} else {
543
			return parent::process_payment( $order_id, $retry, $force_save_source );
544
		}
545
	}
546
547
	/**
548
	 * Process a pre-order payment when the pre-order is released

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

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