CardIcons
1 year ago
CouponsController.php
7 months ago
IppFunctions.php
1 year ago
MobileMessagingHandler.php
2 years ago
OrderActionsRestController.php
3 months ago
OrderAttributionBlocksController.php
1 year ago
OrderAttributionController.php
5 months ago
OrderNoteGroup.php
3 months ago
OrderStatusRestController.php
5 months ago
PaymentInfo.php
10 months ago
PointOfSaleEmailHandler.php
3 months ago
PointOfSaleOrderUtil.php
4 weeks ago
TaxesController.php
3 years ago
IppFunctions.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Internal\Orders; |
| 4 | |
| 5 | use WC_Order; |
| 6 | use WC_Gateway_COD; |
| 7 | |
| 8 | /** |
| 9 | * Class with methods for handling order In-Person Payments. |
| 10 | */ |
| 11 | class IppFunctions { |
| 12 | |
| 13 | /** |
| 14 | * Returns if order is eligible to accept In-Person Payments. |
| 15 | * |
| 16 | * @param WC_Order $order order that the conditions are checked for. |
| 17 | * |
| 18 | * @return bool true if order is eligible, false otherwise |
| 19 | */ |
| 20 | public static function is_order_in_person_payment_eligible( WC_Order $order ): bool { |
| 21 | $has_status = in_array( $order->get_status(), array( 'pending', 'on-hold', 'processing' ), true ); |
| 22 | $has_payment_method = in_array( $order->get_payment_method(), array( WC_Gateway_COD::ID, 'woocommerce_payments', 'none' ), true ); |
| 23 | $order_is_not_paid = null === $order->get_date_paid(); |
| 24 | $order_is_not_refunded = empty( $order->get_refunds() ); |
| 25 | |
| 26 | $order_has_no_subscription_products = true; |
| 27 | foreach ( $order->get_items() as $item ) { |
| 28 | $product = $item->get_product(); |
| 29 | |
| 30 | if ( is_object( $product ) && $product->is_type( 'subscription' ) ) { |
| 31 | $order_has_no_subscription_products = false; |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | return $has_status && $has_payment_method && $order_is_not_paid && $order_is_not_refunded && $order_has_no_subscription_products; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns if store is eligible to accept In-Person Payments. |
| 41 | * |
| 42 | * @return bool true if store is eligible, false otherwise |
| 43 | */ |
| 44 | public static function is_store_in_person_payment_eligible(): bool { |
| 45 | $is_store_usa_based = self::has_store_specified_country_currency( 'US', 'USD' ); |
| 46 | $is_store_canada_based = self::has_store_specified_country_currency( 'CA', 'CAD' ); |
| 47 | |
| 48 | return $is_store_usa_based || $is_store_canada_based; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Checks if the store has specified country location and currency used. |
| 53 | * |
| 54 | * @param string $country country to compare store's country with. |
| 55 | * @param string $currency currency to compare store's currency with. |
| 56 | * |
| 57 | * @return bool true if specified country and currency match the store's ones. false otherwise |
| 58 | */ |
| 59 | public static function has_store_specified_country_currency( string $country, string $currency ): bool { |
| 60 | return ( WC()->countries->get_base_country() === $country && get_woocommerce_currency() === $currency ); |
| 61 | } |
| 62 | } |
| 63 |