abstracts
3 months ago
admin
3 months ago
frontend
1 month ago
integrations
1 month ago
v3
3 months ago
vendor
6 days ago
views
8 months ago
class-simplesalestax.php
6 days ago
class-sst-addresses.php
1 month ago
class-sst-ajax.php
3 months ago
class-sst-assets.php
6 months ago
class-sst-blocks-integration.php
1 month ago
class-sst-blocks.php
1 year ago
class-sst-certificates.php
6 days ago
class-sst-install.php
6 months ago
class-sst-logger.php
5 months ago
class-sst-marketplaces.php
6 months ago
class-sst-order-controller.php
3 months ago
class-sst-order.php
1 month ago
class-sst-origin-address.php
8 months ago
class-sst-product.php
3 months ago
class-sst-rate-limit.php
5 months ago
class-sst-settings.php
3 months ago
class-sst-shipping.php
3 years ago
class-sst-taxcloud-v3-api.php
3 months ago
class-sst-taxcloud-v3.php
3 months ago
class-sst-tic.php
2 years ago
class-sst-updater.php
3 years ago
sst-compatibility-functions.php
4 months ago
sst-functions.php
6 days ago
sst-message-functions.php
3 years ago
sst-update-functions.php
11 months ago
class-sst-blocks.php
166 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Blocks. |
| 4 | * |
| 5 | * Registers Simple Sales Tax blocks. |
| 6 | * |
| 7 | * @package simple-sales-tax |
| 8 | */ |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; |
| 12 | } |
| 13 | |
| 14 | use \Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema; |
| 15 | |
| 16 | /** |
| 17 | * Class SST_Blocks. |
| 18 | * |
| 19 | * @package simple-sales-tax |
| 20 | * @since 8.1 |
| 21 | */ |
| 22 | class SST_Blocks { |
| 23 | |
| 24 | /** |
| 25 | * Singleton instance. |
| 26 | * |
| 27 | * @var SST_Blocks |
| 28 | */ |
| 29 | protected static $_instance = null; |
| 30 | |
| 31 | /** |
| 32 | * Singleton instance accessor. |
| 33 | * |
| 34 | * @return SST_Blocks |
| 35 | */ |
| 36 | public static function instance() { |
| 37 | if ( is_null( self::$_instance ) ) { |
| 38 | self::$_instance = new self(); |
| 39 | } |
| 40 | |
| 41 | return self::$_instance; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * SST_Blocks constructor. |
| 46 | */ |
| 47 | protected function __construct() { |
| 48 | add_action( |
| 49 | 'woocommerce_blocks_loaded', |
| 50 | array( $this, 'register_blocks' ) |
| 51 | ); |
| 52 | add_action( |
| 53 | 'woocommerce_blocks_loaded', |
| 54 | array( $this, 'register_update_callback' ) |
| 55 | ); |
| 56 | add_action( |
| 57 | 'woocommerce_blocks_loaded', |
| 58 | array( $this, 'register_checkout_endpoint_data' ) |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Registers all SST blocks. |
| 64 | */ |
| 65 | public function register_blocks() { |
| 66 | require_once __DIR__ . '/class-sst-blocks-integration.php'; |
| 67 | |
| 68 | add_action( |
| 69 | 'woocommerce_blocks_checkout_block_registration', |
| 70 | function( $integration_registry ) { |
| 71 | $integration_registry->register( new SST_Blocks_Integration() ); |
| 72 | } |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Register Store API update callback. |
| 78 | */ |
| 79 | public function register_update_callback() { |
| 80 | woocommerce_store_api_register_update_callback( |
| 81 | array( |
| 82 | 'namespace' => 'simple-sales-tax', |
| 83 | 'callback' => array( $this, 'handle_cart_update' ), |
| 84 | ) |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Handle cart updates triggered by `extensionCartUpdate`. |
| 90 | * |
| 91 | * @param array $data Data payload from `extensionCartUpdate` |
| 92 | */ |
| 93 | public function handle_cart_update( $data ) { |
| 94 | $action = $data['action'] ?? ''; |
| 95 | |
| 96 | switch ( $action ) { |
| 97 | case 'set_certificate_id': |
| 98 | WC()->session->set( |
| 99 | 'sst_certificate_id', |
| 100 | $data['certificate_id'] |
| 101 | ); |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Get schema for checkout endpoint extension data |
| 108 | * |
| 109 | * @return array |
| 110 | */ |
| 111 | public function get_checkout_schema() { |
| 112 | return array( |
| 113 | 'certificate_id' => array( |
| 114 | 'type' => 'string', |
| 115 | ), |
| 116 | 'certificate' => array( |
| 117 | 'SinglePurchase' => array( |
| 118 | 'type' => 'boolean', |
| 119 | ), |
| 120 | 'ExemptState' => array( |
| 121 | 'type' => 'string', |
| 122 | ), |
| 123 | 'TaxType' => array( |
| 124 | 'type' => 'string', |
| 125 | ), |
| 126 | 'StateOfIssue' => array( |
| 127 | 'type' => 'string', |
| 128 | ), |
| 129 | 'IDNumber' => array( |
| 130 | 'type' => 'string', |
| 131 | ), |
| 132 | 'PurchaserBusinessType' => array( |
| 133 | 'type' => 'string', |
| 134 | ), |
| 135 | 'PurchaserBusinessTypeOtherValue' => array( |
| 136 | 'type' => 'string', |
| 137 | ), |
| 138 | 'PurchaserExemptionReason' => array( |
| 139 | 'type' => 'string', |
| 140 | ), |
| 141 | 'PurchaserExemptionReasonOtherValue' => array( |
| 142 | 'type' => 'string', |
| 143 | ), |
| 144 | ), |
| 145 | ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Register custom extension data for checkout endpoint. |
| 150 | */ |
| 151 | public function register_checkout_endpoint_data() { |
| 152 | woocommerce_store_api_register_endpoint_data( |
| 153 | array( |
| 154 | 'endpoint' => CheckoutSchema::IDENTIFIER, |
| 155 | 'namespace' => 'simple-sales-tax', |
| 156 | 'data_callback' => null, |
| 157 | 'schema_callback' => array( $this, 'get_checkout_schema' ), |
| 158 | 'schema_type' => ARRAY_A, |
| 159 | ) |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | |
| 165 | SST_Blocks::instance(); |
| 166 |