2020-08-31 11:12:46 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The endpoint to create an PayPal order.
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
* @package WooCommerce\PayPalCommerce\Button\Endpoint
|
2020-08-31 11:12:46 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
2020-08-31 11:12:46 +03:00
|
|
|
|
2021-09-23 17:19:46 +03:00
|
|
|
use Exception;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2021-01-18 16:13:08 +01:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
2022-04-05 09:31:57 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Amount;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
2020-09-30 14:24:31 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentMethod;
|
2021-03-15 19:53:35 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
2021-03-15 19:53:35 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
2020-09-30 14:24:31 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
|
|
|
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
|
|
|
|
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
2022-04-05 09:31:57 +03:00
|
|
|
use WooCommerce\PayPalCommerce\Subscription\FreeTrialHandlerTrait;
|
2021-03-15 19:53:35 +02:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
2022-04-05 09:31:57 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
2022-04-25 15:24:37 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
2020-08-31 11:12:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CreateOrderEndpoint
|
|
|
|
*/
|
|
|
|
class CreateOrderEndpoint implements EndpointInterface {
|
|
|
|
|
2022-04-05 09:31:57 +03:00
|
|
|
use FreeTrialHandlerTrait;
|
|
|
|
|
2020-09-11 13:38:02 +03:00
|
|
|
const ENDPOINT = 'ppc-create-order';
|
2020-08-31 11:12:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The request data helper.
|
|
|
|
*
|
|
|
|
* @var RequestData
|
|
|
|
*/
|
|
|
|
private $request_data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The cart repository.
|
|
|
|
*
|
|
|
|
* @var CartRepository
|
|
|
|
*/
|
2020-09-30 14:24:31 +03:00
|
|
|
private $cart_repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The PurchaseUnit factory.
|
|
|
|
*
|
|
|
|
* @var PurchaseUnitFactory
|
|
|
|
*/
|
|
|
|
private $purchase_unit_factory;
|
2020-08-31 11:12:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The order endpoint.
|
|
|
|
*
|
|
|
|
* @var OrderEndpoint
|
|
|
|
*/
|
|
|
|
private $api_endpoint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The payer factory.
|
|
|
|
*
|
|
|
|
* @var PayerFactory
|
|
|
|
*/
|
|
|
|
private $payer_factory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The session handler.
|
|
|
|
*
|
|
|
|
* @var SessionHandler
|
|
|
|
*/
|
|
|
|
private $session_handler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The settings.
|
|
|
|
*
|
|
|
|
* @var Settings
|
|
|
|
*/
|
|
|
|
private $settings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The early order handler.
|
|
|
|
*
|
|
|
|
* @var EarlyOrderHandler
|
|
|
|
*/
|
|
|
|
private $early_order_handler;
|
|
|
|
|
2021-03-16 15:32:52 +02:00
|
|
|
/**
|
|
|
|
* Data from the request.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $parsed_request_data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The array of purchase units for order.
|
|
|
|
*
|
|
|
|
* @var PurchaseUnit[]
|
|
|
|
*/
|
|
|
|
private $purchase_units;
|
|
|
|
|
2021-10-20 10:13:27 +03:00
|
|
|
/**
|
|
|
|
* Whether a new user must be registered during checkout.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $registration_needed;
|
|
|
|
|
2021-09-23 17:19:46 +03:00
|
|
|
/**
|
|
|
|
* The logger.
|
|
|
|
*
|
|
|
|
* @var LoggerInterface
|
|
|
|
*/
|
|
|
|
protected $logger;
|
|
|
|
|
2020-08-31 11:12:46 +03:00
|
|
|
/**
|
|
|
|
* CreateOrderEndpoint constructor.
|
|
|
|
*
|
2020-09-30 14:24:31 +03:00
|
|
|
* @param RequestData $request_data The RequestData object.
|
|
|
|
* @param CartRepository $cart_repository The CartRepository object.
|
|
|
|
* @param PurchaseUnitFactory $purchase_unit_factory The Purchaseunit factory.
|
|
|
|
* @param OrderEndpoint $order_endpoint The OrderEndpoint object.
|
|
|
|
* @param PayerFactory $payer_factory The PayerFactory object.
|
|
|
|
* @param SessionHandler $session_handler The SessionHandler object.
|
|
|
|
* @param Settings $settings The Settings object.
|
|
|
|
* @param EarlyOrderHandler $early_order_handler The EarlyOrderHandler object.
|
2021-10-20 10:13:27 +03:00
|
|
|
* @param bool $registration_needed Whether a new user must be registered during checkout.
|
2021-09-23 17:19:46 +03:00
|
|
|
* @param LoggerInterface $logger The logger.
|
2020-08-31 11:12:46 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
RequestData $request_data,
|
2020-09-30 14:24:31 +03:00
|
|
|
CartRepository $cart_repository,
|
|
|
|
PurchaseUnitFactory $purchase_unit_factory,
|
2020-08-31 11:12:46 +03:00
|
|
|
OrderEndpoint $order_endpoint,
|
|
|
|
PayerFactory $payer_factory,
|
|
|
|
SessionHandler $session_handler,
|
|
|
|
Settings $settings,
|
2021-09-23 17:19:46 +03:00
|
|
|
EarlyOrderHandler $early_order_handler,
|
2021-10-20 10:13:27 +03:00
|
|
|
bool $registration_needed,
|
2021-09-23 17:19:46 +03:00
|
|
|
LoggerInterface $logger
|
2020-08-31 11:12:46 +03:00
|
|
|
) {
|
|
|
|
|
2020-09-30 14:24:31 +03:00
|
|
|
$this->request_data = $request_data;
|
|
|
|
$this->cart_repository = $cart_repository;
|
|
|
|
$this->purchase_unit_factory = $purchase_unit_factory;
|
|
|
|
$this->api_endpoint = $order_endpoint;
|
|
|
|
$this->payer_factory = $payer_factory;
|
|
|
|
$this->session_handler = $session_handler;
|
|
|
|
$this->settings = $settings;
|
|
|
|
$this->early_order_handler = $early_order_handler;
|
2021-10-20 10:13:27 +03:00
|
|
|
$this->registration_needed = $registration_needed;
|
2021-09-23 17:19:46 +03:00
|
|
|
$this->logger = $logger;
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nonce.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function nonce(): string {
|
|
|
|
return self::ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the request.
|
|
|
|
*
|
|
|
|
* @return bool
|
2021-10-27 15:33:57 +02:00
|
|
|
* @throws Exception On Error.
|
2020-08-31 11:12:46 +03:00
|
|
|
*/
|
|
|
|
public function handle_request(): bool {
|
|
|
|
try {
|
2021-03-17 13:59:18 +02:00
|
|
|
$data = $this->request_data->read_request( $this->nonce() );
|
2021-03-16 15:32:52 +02:00
|
|
|
$this->parsed_request_data = $data;
|
2022-04-05 09:31:57 +03:00
|
|
|
$payment_method = $data['payment_method'] ?? '';
|
2022-04-25 15:24:37 +03:00
|
|
|
$funding_source = $data['funding_source'] ?? '';
|
2021-03-17 13:59:18 +02:00
|
|
|
$wc_order = null;
|
2020-09-30 14:24:31 +03:00
|
|
|
if ( 'pay-now' === $data['context'] ) {
|
|
|
|
$wc_order = wc_get_order( (int) $data['order_id'] );
|
|
|
|
if ( ! is_a( $wc_order, \WC_Order::class ) ) {
|
|
|
|
wp_send_json_error(
|
|
|
|
array(
|
|
|
|
'name' => 'order-not-found',
|
2020-10-08 20:03:07 -03:00
|
|
|
'message' => __( 'Order not found', 'woocommerce-paypal-payments' ),
|
2020-09-30 14:24:31 +03:00
|
|
|
'code' => 0,
|
|
|
|
'details' => array(),
|
|
|
|
)
|
|
|
|
);
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|
2021-03-16 15:32:52 +02:00
|
|
|
$this->purchase_units = array( $this->purchase_unit_factory->from_wc_order( $wc_order ) );
|
2020-09-30 14:24:31 +03:00
|
|
|
} else {
|
2021-03-16 15:32:52 +02:00
|
|
|
$this->purchase_units = $this->cart_repository->all();
|
2022-04-05 09:31:57 +03:00
|
|
|
|
|
|
|
// The cart does not have any info about payment method, so we must handle free trial here.
|
2022-04-25 15:24:37 +03:00
|
|
|
if ( (
|
|
|
|
CreditCardGateway::ID === $payment_method
|
|
|
|
|| ( PayPalGateway::ID === $payment_method && 'card' === $funding_source )
|
|
|
|
)
|
|
|
|
&& $this->is_free_trial_cart()
|
|
|
|
) {
|
2022-04-05 09:31:57 +03:00
|
|
|
$this->purchase_units[0]->set_amount(
|
|
|
|
new Amount(
|
|
|
|
new Money( 1.0, $this->purchase_units[0]->amount()->currency_code() ),
|
|
|
|
$this->purchase_units[0]->amount()->breakdown()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|
2020-09-30 14:24:31 +03:00
|
|
|
|
|
|
|
$this->set_bn_code( $data );
|
2021-03-15 19:53:35 +02:00
|
|
|
|
2020-08-31 11:12:46 +03:00
|
|
|
if ( 'checkout' === $data['context'] ) {
|
2021-10-27 12:29:11 +02:00
|
|
|
try {
|
2021-10-27 15:22:24 +02:00
|
|
|
$order = $this->create_paypal_order( $wc_order );
|
2021-10-27 12:29:11 +02:00
|
|
|
} catch ( Exception $exception ) {
|
|
|
|
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
|
|
|
throw $exception;
|
2021-06-15 12:48:01 +02:00
|
|
|
}
|
2021-06-15 14:44:47 +02:00
|
|
|
|
2021-10-28 15:51:29 +02:00
|
|
|
if (
|
|
|
|
! $this->early_order_handler->should_create_early_order()
|
|
|
|
|| $this->registration_needed
|
|
|
|
|| isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) {
|
2021-10-27 12:29:11 +02:00
|
|
|
wp_send_json_success( $order->to_array() );
|
|
|
|
}
|
2021-10-27 15:22:24 +02:00
|
|
|
|
2021-10-27 12:29:11 +02:00
|
|
|
$this->early_order_handler->register_for_order( $order );
|
2020-09-30 14:24:31 +03:00
|
|
|
}
|
2021-10-27 15:22:24 +02:00
|
|
|
|
2021-01-07 12:37:16 +01:00
|
|
|
if ( 'pay-now' === $data['context'] && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) {
|
2020-09-30 14:24:31 +03:00
|
|
|
$this->validate_paynow_form( $data['form'] );
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|
2021-03-16 16:08:42 +02:00
|
|
|
|
2021-03-17 13:59:18 +02:00
|
|
|
$order = $this->create_paypal_order( $wc_order );
|
2020-09-01 09:00:45 +03:00
|
|
|
wp_send_json_success( $order->to_array() );
|
2020-08-31 11:12:46 +03:00
|
|
|
return true;
|
2021-10-27 15:22:24 +02:00
|
|
|
|
2020-08-31 11:12:46 +03:00
|
|
|
} catch ( \RuntimeException $error ) {
|
2021-09-23 17:19:46 +03:00
|
|
|
$this->logger->error( 'Order creation failed: ' . $error->getMessage() );
|
|
|
|
|
2020-08-31 11:12:46 +03:00
|
|
|
wp_send_json_error(
|
|
|
|
array(
|
|
|
|
'name' => is_a( $error, PayPalApiException::class ) ? $error->name() : '',
|
|
|
|
'message' => $error->getMessage(),
|
|
|
|
'code' => $error->getCode(),
|
|
|
|
'details' => is_a( $error, PayPalApiException::class ) ? $error->details() : array(),
|
|
|
|
)
|
|
|
|
);
|
2021-09-23 17:19:46 +03:00
|
|
|
} catch ( Exception $exception ) {
|
|
|
|
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
|
|
|
|
2021-03-17 13:59:18 +02:00
|
|
|
wc_add_notice( $exception->getMessage(), 'error' );
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|
2021-03-16 12:02:02 +02:00
|
|
|
|
|
|
|
return false;
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|
|
|
|
|
2021-06-15 14:44:47 +02:00
|
|
|
/**
|
|
|
|
* Once the checkout has been validated we execute this method.
|
|
|
|
*
|
|
|
|
* @param array $data The data.
|
|
|
|
* @param \WP_Error $errors The errors, which occurred.
|
|
|
|
*
|
|
|
|
* @return array
|
2021-09-23 17:19:46 +03:00
|
|
|
* @throws Exception On Error.
|
2021-06-15 14:44:47 +02:00
|
|
|
*/
|
|
|
|
public function after_checkout_validation( array $data, \WP_Error $errors ): array {
|
|
|
|
if ( ! $errors->errors ) {
|
2021-09-23 17:19:46 +03:00
|
|
|
try {
|
|
|
|
$order = $this->create_paypal_order();
|
|
|
|
} catch ( Exception $exception ) {
|
|
|
|
$this->logger->error( 'Order creation failed: ' . $exception->getMessage() );
|
|
|
|
throw $exception;
|
|
|
|
}
|
2021-06-15 14:44:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* In case we are onboarded and everything is fine with the \WC_Order
|
|
|
|
* we want this order to be created. We will intercept it and leave it
|
|
|
|
* in the "Pending payment" status though, which than later will change
|
|
|
|
* during the "onApprove"-JS callback or the webhook listener.
|
|
|
|
*/
|
|
|
|
if ( ! $this->early_order_handler->should_create_early_order() ) {
|
|
|
|
wp_send_json_success( $order->to_array() );
|
|
|
|
}
|
|
|
|
$this->early_order_handler->register_for_order( $order );
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2021-09-23 17:19:46 +03:00
|
|
|
$this->logger->error( 'Checkout validation failed: ' . $errors->get_error_message() );
|
|
|
|
|
2021-06-15 14:44:47 +02:00
|
|
|
wp_send_json_error(
|
|
|
|
array(
|
|
|
|
'name' => '',
|
|
|
|
'message' => $errors->get_error_message(),
|
|
|
|
'code' => (int) $errors->get_error_code(),
|
|
|
|
'details' => array(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2021-03-15 19:53:35 +02:00
|
|
|
/**
|
2021-03-17 14:01:13 +02:00
|
|
|
* Creates the order in the PayPal, uses data from WC order if provided.
|
2021-03-17 14:02:00 +02:00
|
|
|
*
|
2021-03-16 15:32:52 +02:00
|
|
|
* @param \WC_Order|null $wc_order WC order to get data from.
|
2021-03-15 19:53:35 +02:00
|
|
|
*
|
|
|
|
* @return Order Created PayPal order.
|
|
|
|
*
|
|
|
|
* @throws RuntimeException If create order request fails.
|
|
|
|
*/
|
2021-03-17 13:59:18 +02:00
|
|
|
private function create_paypal_order( \WC_Order $wc_order = null ): Order {
|
2021-11-03 10:20:39 +02:00
|
|
|
$needs_shipping = WC()->cart instanceof \WC_Cart && WC()->cart->needs_shipping();
|
2021-03-16 15:32:52 +02:00
|
|
|
$shipping_address_is_fix = $needs_shipping && 'checkout' === $this->parsed_request_data['context'];
|
2021-03-15 19:53:35 +02:00
|
|
|
|
|
|
|
return $this->api_endpoint->create(
|
2021-03-16 15:32:52 +02:00
|
|
|
$this->purchase_units,
|
|
|
|
$this->payer( $this->parsed_request_data, $wc_order ),
|
2021-03-15 19:53:35 +02:00
|
|
|
null,
|
|
|
|
$this->payment_method(),
|
|
|
|
'',
|
|
|
|
$shipping_address_is_fix
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-30 14:24:31 +03:00
|
|
|
/**
|
|
|
|
* Returns the Payer entity based on the request data.
|
|
|
|
*
|
2021-03-17 13:59:18 +02:00
|
|
|
* @param array $data The request data.
|
2021-03-16 16:08:42 +02:00
|
|
|
* @param \WC_Order|null $wc_order The order.
|
2020-09-30 14:24:31 +03:00
|
|
|
*
|
|
|
|
* @return Payer|null
|
|
|
|
*/
|
|
|
|
private function payer( array $data, \WC_Order $wc_order = null ) {
|
|
|
|
if ( 'pay-now' === $data['context'] ) {
|
|
|
|
$payer = $this->payer_factory->from_wc_order( $wc_order );
|
|
|
|
return $payer;
|
|
|
|
}
|
|
|
|
|
|
|
|
$payer = null;
|
|
|
|
if ( isset( $data['payer'] ) && $data['payer'] ) {
|
|
|
|
if ( isset( $data['payer']['phone']['phone_number']['national_number'] ) ) {
|
|
|
|
// make sure the phone number contains only numbers and is max 14. chars long.
|
|
|
|
$number = $data['payer']['phone']['phone_number']['national_number'];
|
|
|
|
$number = preg_replace( '/[^0-9]/', '', $number );
|
|
|
|
$number = substr( $number, 0, 14 );
|
|
|
|
$data['payer']['phone']['phone_number']['national_number'] = $number;
|
2021-01-19 09:50:07 +01:00
|
|
|
if ( empty( $data['payer']['phone']['phone_number']['national_number'] ) ) {
|
|
|
|
unset( $data['payer']['phone'] );
|
|
|
|
}
|
2020-09-30 14:24:31 +03:00
|
|
|
}
|
2021-01-18 16:13:08 +01:00
|
|
|
|
2020-09-30 14:24:31 +03:00
|
|
|
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
|
|
|
|
}
|
2022-02-04 17:11:40 +01:00
|
|
|
|
2022-02-07 16:25:29 +01:00
|
|
|
if ( ! $payer && isset( $data['form'] ) ) {
|
|
|
|
parse_str( $data['form'], $form_fields );
|
|
|
|
|
|
|
|
if ( isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
|
|
|
return $this->payer_factory->from_checkout_form( $form_fields );
|
|
|
|
}
|
2022-02-04 17:11:40 +01:00
|
|
|
}
|
|
|
|
|
2020-09-30 14:24:31 +03:00
|
|
|
return $payer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the BN Code for the following request.
|
|
|
|
*
|
|
|
|
* @param array $data The request data.
|
|
|
|
*/
|
|
|
|
private function set_bn_code( array $data ) {
|
|
|
|
$bn_code = isset( $data['bn_code'] ) ? (string) $data['bn_code'] : '';
|
|
|
|
if ( ! $bn_code ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->session_handler->replace_bn_code( $bn_code );
|
|
|
|
$this->api_endpoint->with_bn_code( $bn_code );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the PaymentMethod object for the order.
|
|
|
|
*
|
|
|
|
* @return PaymentMethod
|
|
|
|
*/
|
|
|
|
private function payment_method() : PaymentMethod {
|
2021-03-15 19:49:10 +02:00
|
|
|
try {
|
|
|
|
$payee_preferred = $this->settings->has( 'payee_preferred' ) && $this->settings->get( 'payee_preferred' ) ?
|
|
|
|
PaymentMethod::PAYEE_PREFERRED_IMMEDIATE_PAYMENT_REQUIRED
|
|
|
|
: PaymentMethod::PAYEE_PREFERRED_UNRESTRICTED;
|
2021-03-17 13:59:18 +02:00
|
|
|
} catch ( NotFoundException $exception ) {
|
2021-03-15 19:49:10 +02:00
|
|
|
$payee_preferred = PaymentMethod::PAYEE_PREFERRED_UNRESTRICTED;
|
|
|
|
}
|
2021-03-17 13:59:18 +02:00
|
|
|
|
|
|
|
$payment_method = new PaymentMethod( $payee_preferred );
|
2020-09-30 14:24:31 +03:00
|
|
|
return $payment_method;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the terms input field is checked.
|
|
|
|
*
|
|
|
|
* @param string $form_values The form values.
|
|
|
|
* @throws \RuntimeException When field is not checked.
|
|
|
|
*/
|
|
|
|
private function validate_paynow_form( string $form_values ) {
|
|
|
|
$parsed_values = wp_parse_args( $form_values );
|
2021-11-08 15:09:22 +01:00
|
|
|
if ( isset( $parsed_values['terms-field'] ) && ! isset( $parsed_values['terms'] ) ) {
|
2020-09-30 14:24:31 +03:00
|
|
|
throw new \RuntimeException(
|
2020-10-08 20:03:07 -03:00
|
|
|
__( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce-paypal-payments' )
|
2020-09-30 14:24:31 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 11:12:46 +03:00
|
|
|
}
|