@@ 511-549 (lines=39) @@ | ||
508 | * @param int $order_id |
|
509 | * @return array |
|
510 | */ |
|
511 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
512 | if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
513 | try { |
|
514 | $order = wc_get_order( $order_id ); |
|
515 | ||
516 | if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
517 | /* translators: minimum amount */ |
|
518 | 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 ) ) ); |
|
519 | } |
|
520 | ||
521 | $source_id = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
522 | $source = $this->prepare_source( $this->get_source_object( $source_id ), get_current_user_id(), true ); |
|
523 | ||
524 | // We need a source on file to continue. |
|
525 | if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
526 | throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
527 | } |
|
528 | ||
529 | $this->save_source_to_order( $order, $source ); |
|
530 | ||
531 | // Remove cart |
|
532 | WC()->cart->empty_cart(); |
|
533 | ||
534 | // Is pre ordered! |
|
535 | WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
536 | ||
537 | // Return thank you page redirect |
|
538 | return array( |
|
539 | 'result' => 'success', |
|
540 | 'redirect' => $this->get_return_url( $order ), |
|
541 | ); |
|
542 | } catch ( Exception $e ) { |
|
543 | wc_add_notice( $e->getMessage(), 'error' ); |
|
544 | return; |
|
545 | } |
|
546 | } else { |
|
547 | return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
548 | } |
|
549 | } |
|
550 | ||
551 | /** |
|
552 | * Process a pre-order payment when the pre-order is released |
@@ 439-477 (lines=39) @@ | ||
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 | $source_id = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
450 | $source = $this->prepare_source( $this->get_source_object( $source_id ), get_current_user_id(), true ); |
|
451 | ||
452 | // We need a source on file to continue. |
|
453 | if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
454 | throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
455 | } |
|
456 | ||
457 | $this->save_source_to_order( $order, $source ); |
|
458 | ||
459 | // Remove cart |
|
460 | WC()->cart->empty_cart(); |
|
461 | ||
462 | // Is pre ordered! |
|
463 | WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
464 | ||
465 | // Return thank you page redirect |
|
466 | return array( |
|
467 | 'result' => 'success', |
|
468 | 'redirect' => $this->get_return_url( $order ), |
|
469 | ); |
|
470 | } catch ( Exception $e ) { |
|
471 | wc_add_notice( $e->getMessage(), 'error' ); |
|
472 | return; |
|
473 | } |
|
474 | } else { |
|
475 | return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
476 | } |
|
477 | } |
|
478 | ||
479 | /** |
|
480 | * Process a pre-order payment when the pre-order is released |