| @@ 561-599 (lines=39) @@ | ||
| 558 | * @param int $order_id |
|
| 559 | * @return array |
|
| 560 | */ |
|
| 561 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 562 | if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 563 | try { |
|
| 564 | $order = wc_get_order( $order_id ); |
|
| 565 | ||
| 566 | if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 567 | /* translators: minimum amount */ |
|
| 568 | 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 ) ) ); |
|
| 569 | } |
|
| 570 | ||
| 571 | $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
| 572 | ||
| 573 | // We need a source on file to continue. |
|
| 574 | if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 575 | throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 576 | } |
|
| 577 | ||
| 578 | // Store source to order meta |
|
| 579 | $this->save_source( $order, $source ); |
|
| 580 | ||
| 581 | // Remove cart |
|
| 582 | WC()->cart->empty_cart(); |
|
| 583 | ||
| 584 | // Is pre ordered! |
|
| 585 | WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 586 | ||
| 587 | // Return thank you page redirect |
|
| 588 | return array( |
|
| 589 | 'result' => 'success', |
|
| 590 | 'redirect' => $this->get_return_url( $order ), |
|
| 591 | ); |
|
| 592 | } catch ( Exception $e ) { |
|
| 593 | wc_add_notice( $e->getMessage(), 'error' ); |
|
| 594 | return; |
|
| 595 | } |
|
| 596 | } else { |
|
| 597 | return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 598 | } |
|
| 599 | } |
|
| 600 | ||
| 601 | /** |
|
| 602 | * Process a pre-order payment when the pre-order is released |
|
| @@ 465-503 (lines=39) @@ | ||
| 462 | * @param int $order_id |
|
| 463 | * @return array |
|
| 464 | */ |
|
| 465 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 466 | if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 467 | try { |
|
| 468 | $order = wc_get_order( $order_id ); |
|
| 469 | ||
| 470 | if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 471 | /* translators: minimum amount */ |
|
| 472 | 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 ) ) ); |
|
| 473 | } |
|
| 474 | ||
| 475 | $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
| 476 | ||
| 477 | // We need a source on file to continue. |
|
| 478 | if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 479 | throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 480 | } |
|
| 481 | ||
| 482 | // Store source to order meta |
|
| 483 | $this->save_source( $order, $source ); |
|
| 484 | ||
| 485 | // Remove cart |
|
| 486 | WC()->cart->empty_cart(); |
|
| 487 | ||
| 488 | // Is pre ordered! |
|
| 489 | WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 490 | ||
| 491 | // Return thank you page redirect |
|
| 492 | return array( |
|
| 493 | 'result' => 'success', |
|
| 494 | 'redirect' => $this->get_return_url( $order ), |
|
| 495 | ); |
|
| 496 | } catch ( Exception $e ) { |
|
| 497 | wc_add_notice( $e->getMessage(), 'error' ); |
|
| 498 | return; |
|
| 499 | } |
|
| 500 | } else { |
|
| 501 | return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 502 | } |
|
| 503 | } |
|
| 504 | ||
| 505 | /** |
|
| 506 | * Process a pre-order payment when the pre-order is released |
|