Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 134 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| IntegrationsController | |
0.00% |
0 / 134 |
|
0.00% |
0 / 7 |
306 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_routes | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
2 | |||
| get_plugin_details | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| get_paypal_status | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 | |||
| get_shippo_status | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
| get_razorpay_status | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
30 | |||
| get_stripe_status | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\ECommerce\RestApi; |
| 4 | |
| 5 | use NewfoldLabs\WP\Module\ECommerce\Data\Plugins; |
| 6 | use NewfoldLabs\WP\Module\ECommerce\Permissions; |
| 7 | use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller; |
| 8 | use NewfoldLabs\WP\ModuleLoader\Container; |
| 9 | |
| 10 | class IntegrationsController { |
| 11 | |
| 12 | protected $namespace = 'newfold-ecommerce/v1'; |
| 13 | |
| 14 | protected $rest_base = '/integrations'; |
| 15 | |
| 16 | protected $container; |
| 17 | |
| 18 | public function __construct( Container $container ) { |
| 19 | $this->container = $container; |
| 20 | } |
| 21 | |
| 22 | public function register_routes() { |
| 23 | \register_rest_route( |
| 24 | $this->namespace, |
| 25 | $this->rest_base . '/paypal', |
| 26 | array( |
| 27 | array( |
| 28 | 'methods' => \WP_REST_Server::READABLE, |
| 29 | 'callback' => array( $this, 'get_paypal_status' ), |
| 30 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
| 31 | ), |
| 32 | ) |
| 33 | ); |
| 34 | \register_rest_route( |
| 35 | $this->namespace, |
| 36 | $this->rest_base . '/shippo', |
| 37 | array( |
| 38 | array( |
| 39 | 'methods' => \WP_REST_Server::READABLE, |
| 40 | 'callback' => array( $this, 'get_shippo_status' ), |
| 41 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
| 42 | ), |
| 43 | ) |
| 44 | ); |
| 45 | \register_rest_route( |
| 46 | $this->namespace, |
| 47 | $this->rest_base . '/stripe', |
| 48 | array( |
| 49 | array( |
| 50 | 'methods' => \WP_REST_Server::READABLE, |
| 51 | 'callback' => array( $this, 'get_stripe_status' ), |
| 52 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
| 53 | ), |
| 54 | ) |
| 55 | ); |
| 56 | \register_rest_route( |
| 57 | $this->namespace, |
| 58 | $this->rest_base . '/razorpay', |
| 59 | array( |
| 60 | array( |
| 61 | 'methods' => \WP_REST_Server::READABLE, |
| 62 | 'callback' => array( $this, 'get_razorpay_status' ), |
| 63 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
| 64 | ), |
| 65 | ) |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | private function get_plugin_details( $plugin ) { |
| 70 | return array( |
| 71 | 'url' => \admin_url( Plugins::$supported_plugins[ $plugin ][ 'url' ] ), |
| 72 | 'status' => PluginInstaller::exists( $plugin, true ), |
| 73 | 'slug' => $plugin |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | public function get_paypal_status() { |
| 78 | $details = null; |
| 79 | $integration = array( |
| 80 | 'captive' => \admin_url( 'admin.php?page=nfd-ecommerce-captive-flow-paypal' ), |
| 81 | 'plugin' => $this->get_plugin_details( 'nfd_slug_yith_paypal_payments_for_woocommerce' ), |
| 82 | ); |
| 83 | $is_captive_flow_complete = \get_option( 'nfd-ecommerce-captive-flow-paypal', 'false' ); |
| 84 | if ($is_captive_flow_complete === 'true') { |
| 85 | $ppwc_options = \get_option( 'yith_ppwc_gateway_options', array() ); |
| 86 | if (isset( $ppwc_options['enabled'] ) ) { |
| 87 | $ppwc_email = \get_option( 'yith_ppwc_merchant_email', '' ); |
| 88 | $details = array( |
| 89 | 'environment' => $ppwc_options['environment'] === 'production' ? 'live' : 'sandbox' , |
| 90 | 'email' => $ppwc_email |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 | return new \WP_REST_Response( |
| 95 | array( |
| 96 | 'complete' => $is_captive_flow_complete === 'true', |
| 97 | 'details' => $details, |
| 98 | 'integration' => $integration, |
| 99 | ), |
| 100 | 200 |
| 101 | ); |
| 102 | } |
| 103 | public function get_shippo_status() { |
| 104 | $details = null; |
| 105 | $integration = array( |
| 106 | 'captive' => \admin_url( 'admin.php?page=nfd-ecommerce-captive-flow-shippo' ), |
| 107 | 'plugin' => $this->get_plugin_details( 'nfd_slug_yith_shippo_shippings_for_woocommerce' ), |
| 108 | ); |
| 109 | $is_captive_flow_complete = \get_option( 'nfd-ecommerce-captive-flow-shippo', 'false' ); |
| 110 | if ($is_captive_flow_complete === 'true') { |
| 111 | $shippo_environment = \get_option( 'yith_shippo_environment', '' ); |
| 112 | $details = array( |
| 113 | 'environment' => $shippo_environment, |
| 114 | ); |
| 115 | } |
| 116 | return new \WP_REST_Response( |
| 117 | array( |
| 118 | 'complete' => $is_captive_flow_complete === 'true', |
| 119 | 'details' => $details, |
| 120 | 'integration' => $integration, |
| 121 | ), |
| 122 | 200 |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | public function get_razorpay_status() { |
| 127 | $integration = array( |
| 128 | 'captive' => null, |
| 129 | 'plugin' => $this->get_plugin_details( 'nfd_slug_woo_razorpay' ), |
| 130 | ); |
| 131 | $is_captive_flow_complete = \get_option( 'nfd-ecommerce-captive-flow-razorpay', 'false' ); |
| 132 | $razorpay_settings = \get_option( 'woocommerce_razorpay_settings', null ); |
| 133 | $details = array ( |
| 134 | 'settings' => $razorpay_settings |
| 135 | ); |
| 136 | if ($is_captive_flow_complete === 'true') { |
| 137 | $environment = ''; |
| 138 | if ( $razorpay_settings !== null && isset( $razorpay_settings['key_id'] ) ) { |
| 139 | $environment = str_starts_with( $razorpay_settings['key_id'], 'rzp_test_' ) ? 'sandbox' : 'live'; |
| 140 | } |
| 141 | $details['environment'] = $environment; |
| 142 | } |
| 143 | return new \WP_REST_Response( |
| 144 | array( |
| 145 | 'complete' => $is_captive_flow_complete === 'true', |
| 146 | 'details' => $details, |
| 147 | 'integration' => $integration, |
| 148 | ), |
| 149 | 200 |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | public function get_stripe_status() { |
| 154 | $integration = array( |
| 155 | 'captive' => null, |
| 156 | 'plugin' => $this->get_plugin_details( 'nfd_slug_yith_stripe_payments_for_woocommerce' ), |
| 157 | ); |
| 158 | $is_captive_flow_complete = \get_option( 'nfd-ecommerce-captive-flow-stripe', 'false' ); |
| 159 | $stripewc_options = \get_option( 'yith_stripe_payments_enabled', array() ); |
| 160 | $details = array(); |
| 161 | if ( $is_captive_flow_complete === 'true' ) { |
| 162 | $stripewc_email = \get_option( 'yith_stripe_payments_email', '' ); |
| 163 | $details = array( |
| 164 | 'environment' => \get_option( 'yith_stripe_payments_environment', 'live' ) === 'live' ? 'live' : 'sandbox' , |
| 165 | 'email' => $stripewc_email |
| 166 | ); |
| 167 | } |
| 168 | |
| 169 | return new \WP_REST_Response( |
| 170 | array( |
| 171 | 'complete' => $is_captive_flow_complete === 'true', |
| 172 | 'details' => $details, |
| 173 | 'integration' => $integration, |
| 174 | ), |
| 175 | 200 |
| 176 | ); |
| 177 | } |
| 178 | } |