Skip to content

Commit

Permalink
fix: development settings (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Programmer Per <[email protected]>
  • Loading branch information
plarsson and perjo927 authored Dec 14, 2022
1 parent 1a40be6 commit 6240968
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
23 changes: 23 additions & 0 deletions classes/class-ledyer-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ public static function fields() {
),
);

$devmode = 'local' === wp_get_environment_type() || 'development' === wp_get_environment_type();

if ( $devmode ) {
$dev_settings = array(
'development_section' => array(
'title' => __( 'Development settings', 'ledyer-checkout-for-woocommerce' ),
'type' => 'title',
),
'development_test_environment' => array(
'title' => __( 'Test Environment', 'ledyer-checkout-for-woocommerce' ),
'type' => 'select',
'options' => array(
'local' => 'Local (FE+BE)',
'local-fe' => 'Local (FE)',
'development' => 'Development',
'sandbox' => 'Sandbox',
),
'default' => 'sandbox',
'desc_tip' => false,
),
);
$settings = array_merge($settings, $dev_settings);
}

return apply_filters( 'lco_wc_gateway_settings', $settings );
}
Expand Down
38 changes: 35 additions & 3 deletions classes/class-ledyer-lco-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,28 @@ public function enqueue_scripts() {
return;
}

$scriptSrc = ledyer()->get_setting( 'testmode' ) ? 'sandbox' : 'live';

$scriptSrcUrl = 'https://checkout.live.ledyer.com/bootstrap.js';

if ( ledyer()->get_setting( 'testmode' ) ) {
switch (ledyer()->get_setting( 'development_test_environment' )) {
case 'local':
case 'local-fe':
$scriptSrcUrl = 'http://localhost:1337/bootstrap.iife.js';
break;
case 'development':
$scriptSrcUrl = 'https://checkout.dev.ledyer.com/bootstrap.js';
break;
default:
$scriptSrcUrl = 'https://checkout.sandbox.ledyer.com/bootstrap.js';
break;
}
}

//Register iframe script
wp_register_script(
'lco-iframe',
'https://checkout.' . $scriptSrc . '.ledyer.com/bootstrap.js',
$scriptSrcUrl,
array( 'jquery', 'wc-cart', 'jquery-blockui' ),
LCO_WC_VERSION,
true
Expand Down Expand Up @@ -344,7 +360,23 @@ public function show_thank_you_snippet( $order_id = null ) {
public function add_data_attributes( $tag, $handle ) {
if ( $handle == 'lco-iframe' ) {

$env = 'yes' === ledyer()->get_setting( 'testmode' ) ? 'sandbox' : 'production';
$env = 'production';

if ( ledyer()->get_setting( 'testmode' ) ) {
switch (ledyer()->get_setting( 'development_test_environment' )) {
case 'local':
case 'local-fe':
$env = 'localhost';
break;
case 'development':
$env = 'dev';
break;
default:
$env = 'sandbox';
break;
}
}

$buy_button_color = ledyer()->get_setting( 'color_button' );
$no_padding = 'yes' === ledyer()->get_setting( 'iframe_padding' ) ? 'true' : 'false';
$lco_order_id = WC()->session->get( 'lco_wc_session_id' );
Expand Down
18 changes: 17 additions & 1 deletion classes/requests/class-ledyer-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,23 @@ private function token() {

$client_credentials = ledyer()->credentials->get_credentials_from_session();

$api_auth_base = $this->is_test() ? 'https://auth.sandbox.ledyer.com/' : 'https://auth.live.ledyer.com/';

$api_auth_base = 'https://auth.live.ledyer.com/';

if ( $this->is_test() ) {
switch (ledyer()->get_setting( 'development_test_environment' )) {
case 'local':
$api_auth_base = 'http://host.docker.internal:9001/';
break;
case 'development':
case 'local-fe':
$api_auth_base = 'https://auth.dev.ledyer.com/';
break;
default:
$api_auth_base = 'https://auth.sandbox.ledyer.com/';
break;
}
}

$client = new \WP_Http();

Expand Down
18 changes: 17 additions & 1 deletion classes/requests/order/class-ledyer-request-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ abstract class Request_Order extends Request {
* Set request url for all Request_Order child classes
*/
protected function set_request_url() {
$this->request_url = parent::is_test() ? 'https://api.sandbox.ledyer.com/' : 'https://api.live.ledyer.com/';

$this->request_url = 'https://api.live.ledyer.com/';

if ( parent::is_test() ) {
switch (ledyer()->get_setting( 'development_test_environment' )) {
case 'local':
$this->request_url = 'http://host.docker.internal:8000/';
break;
case 'development':
case 'local-fe':
$this->request_url = 'https://api.dev.ledyer.com/';
break;
default:
$this->request_url = 'https://api.sandbox.ledyer.com/';
break;
}
}
$this->set_url();
}
/*
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'SCRIPT_DEBUG', true );
define( 'WP_ENVIRONMENT_TYPE', 'local' );
volumes:
- "./:/var/www/html/wp-content/plugins/ledyer-checkout-for-woocommerce"
- wpdata:/var/www/html
Expand Down

0 comments on commit 6240968

Please sign in to comment.