Skip to content

Commit

Permalink
Merge pull request #19 from fingent-corp/simplify_2.4.2
Browse files Browse the repository at this point in the history
Simplify 2.4.2
  • Loading branch information
jineshpv authored Aug 14, 2024
2 parents 87e3137 + 0957256 commit 068cb58
Show file tree
Hide file tree
Showing 4 changed files with 482 additions and 434 deletions.
66 changes: 30 additions & 36 deletions includes/class-gateway-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class Mastercard_Simplify_Gateway_Notification {
*/
protected $changelog = null;

/**
* Plugin slug.
*
* @var string|null
*/
protected $plugin_slug;

/**
* GatewayService constructor.
*
Expand All @@ -103,7 +110,7 @@ public function __construct() {

$this->id = 'simplify_commerce';
$this->wp_requires = '6.0';
$this->wp_tested = '6.5.1';
$this->wp_tested = '6.4.3';
$this->min_php_required = '7.4';
$this->plugin_slug = MPGS_SIMPLIFY_ROOT_FOLDER;
$this->base_url = 'github.com';
Expand All @@ -115,7 +122,7 @@ public function __construct() {
$this->api_url = 'https://api.' . $this->base_url . '/repos/' . $this->owner . '/' . $this->repo . '/releases/latest';

register_deactivation_hook( __FILE__, array( $this, 'clear_mgps_simplify_module_new_version_check' ) );
// $this->save_changelog( '' );
$this->save_changelog( '' );
add_action( 'init', array( $this, 'create_cron_mpgs_version_check' ) );
add_action( 'mgps_simplify_module_new_version_check', array( $this, 'mgps_new_version_check' ) );

Expand All @@ -140,15 +147,14 @@ public function mgps_new_version_check() {
'X-GitHub-Api-Version' => '2022-11-28'
),
)
);
);

if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) {
$plugin_file = MPGS_SIMPLIFY_PLUGIN_BASENAME;
$response_body = json_decode( wp_remote_retrieve_body( $response ), true );

if ( json_last_error() === JSON_ERROR_NONE || $response_body && is_array( $response_body ) ) {
$latest_version = $response_body['tag_name'];
$this->save_changelog( $response_body['body'] );

if ( version_compare( $latest_version, $this->current_version, '>' ) ) {
$mgps_plugin_info = new stdClass();
Expand All @@ -157,8 +163,7 @@ public function mgps_new_version_check() {
$mgps_plugin_info->plugin = $plugin_file;
$mgps_plugin_info->new_version = $latest_version;
$mgps_plugin_info->url = 'https://api.' . $this->base_url . '/repos/' . $this->owner . '/' . $this->repo;
// $mgps_plugin_info->package = $response_body['assets'][0]['browser_download_url'];
$mgps_plugin_info->package = "";
$mgps_plugin_info->package = $response_body['assets'][0]['browser_download_url'];
$mgps_plugin_info->icons = array();
$mgps_plugin_info->banners = array();
$mgps_plugin_info->banners_rtl = array();
Expand Down Expand Up @@ -231,35 +236,24 @@ public function update_database() {
* @return void
*/
public function save_changelog( $changelog ) {
// $changelog_with_tags = '';
// $response = wp_remote_get( $this->doc_url . 'changelog-simplify' );

// if ( is_array( $response ) && ! is_wp_error( $response ) ) {
// $dom = new DOMDocument();
// $html = $response['body'];
// libxml_use_internal_errors(true);
// $dom->loadHTML( $html );
// $xpath = new DOMXPath( $dom );
// $body = $dom->getElementsByTagName('body')->item(0);
// $divId = 'page-content';
// $divElements = $xpath->evaluate("//div[@class='$divId']/node()");

// foreach ( $divElements as $childNode ) {
// $changelog_with_tags .= $dom->saveHtml( $childNode );
// }
// }
$changelog = preg_replace( '/\*\*(.*?)\*\*/', '<b>$1</b>', $changelog );
preg_match_all( '/[^\n]+/', $changelog, $matches );

$changelog_with_tags = '';

if ( $matches && is_array( $matches ) ) {
foreach ( $matches[0] as $p_tag ) {
if ( '' !== $p_tag ) {
$changelog_with_tags .= '<p>' . $p_tag . '</p>';
}
}
}
$changelog_with_tags = '';
$response = wp_remote_get( $this->doc_url . 'changelog-simplify' );

if ( is_array( $response ) && ! is_wp_error( $response ) ) {
$dom = new DOMDocument();
$html = $response['body'];
libxml_use_internal_errors(true);
$dom->loadHTML( $html );
$xpath = new DOMXPath( $dom );
$body = $dom->getElementsByTagName('body')->item(0);
$divId = 'page-content';
$divElements = $xpath->evaluate("//div[@class='$divId']/node()");

foreach ( $divElements as $childNode ) {
$changelog_with_tags .= $dom->saveHtml( $childNode );
}
}

update_option( '_mgps_simplify_current_version_changelog', $changelog_with_tags );
}

Expand All @@ -284,7 +278,7 @@ public function render_changelog_html() {
*
* @return void
*/
public function display_simplify_changelog() {echo '<pre>';print_r($this->plugin_slug);echo '</pre>';exit;
public function display_simplify_changelog() {
$plugin = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : null; // phpcs:disable WordPress.Security.NonceVerification.Recommended

if ( $plugin !== $this->plugin_slug ) {
Expand Down
9 changes: 3 additions & 6 deletions includes/class-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,6 @@ public function do_payment( $order, $amount = 0, $token = array() ) {
),
'currency' => strtoupper( get_woocommerce_currency() ),
'reference' => $order->get_id(),
'card' => $order_builder->getCardInfo(),
'order' => $order_builder->getOrder(),
);

Expand All @@ -794,7 +793,6 @@ public function do_payment( $order, $amount = 0, $token = array() ) {
$payment = Simplify_Payment::createPayment( $data );

} catch ( Exception $e ) {

$error_message = $e->getMessage();

if ( $e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors() ) {
Expand All @@ -805,7 +803,7 @@ public function do_payment( $order, $amount = 0, $token = array() ) {
}
}

$order->add_order_note( sprintf( __( 'Gateway payment error: %s', 'woocommerce-gateway-simplify-commerce' ),
$order->add_order_note( sprintf( __( 'Gateway payment error 1: %s', 'woocommerce-gateway-simplify-commerce' ),
$error_message ) );

return new WP_Error( 'simplify_payment_declined', $err_msg, array( 'status' => $e->getCode() ) );
Expand Down Expand Up @@ -1161,7 +1159,6 @@ protected function authorize( $order, $card_token, $amount ) {
__( 'Order #%s', 'woocommerce-gateway-simplify-commerce' ),
$order->get_order_number()
),
'card' => $order_builder->getCardInfo(),
'order' => $order_builder->getOrder(),
);

Expand Down Expand Up @@ -1195,11 +1192,11 @@ protected function authorize( $order, $card_token, $amount ) {
__( 'Authorization was declined by your gateway.', 'woocommerce-gateway-simplify-commerce' )
);

$order->add_order_note( sprintf( __( 'Gateway payment error: %s', 'woocommerce-gateway-simplify-commerce' ),
$order->add_order_note( sprintf( __( 'Gateway payment error 2: %s', 'woocommerce-gateway-simplify-commerce' ),
$error_message ) );

wc_add_notice(
sprintf( __( 'Gateway payment error: %s', 'woocommerce-gateway-simplify-commerce' ), $error_message ),
sprintf( __( 'Gateway payment error 3: %s', 'woocommerce-gateway-simplify-commerce' ), $error_message ),
'error'
);

Expand Down
117 changes: 86 additions & 31 deletions includes/class-simplify-checkout-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,33 @@ public function getBilling() { // phpcs:ignore
return null;
}

return array(
'shippingFromAddress' => array(
'line1' => self::safe( WC()->countries->get_base_address(), 100 ),
'line2' => self::safe( WC()->countries->get_base_address_2(), 100 ),
'city' => self::safe( WC()->countries->get_base_city(), 100 ),
'zip' => self::safe( WC()->countries->get_base_postcode(), 10 ),
'country' => self::safe( WC()->countries->get_base_country(), 20 ),
'state' => self::safe( WC()->countries->get_base_state(), 20 ),
)
);
$billing = array();

if( WC()->countries->get_base_address() ) {
$billing['shippingFromAddress']['line1'] = self::safe( WC()->countries->get_base_address(), 100 );
}

if( WC()->countries->get_base_address_2() ) {
$billing['shippingFromAddress']['line2'] = self::safe( WC()->countries->get_base_address_2(), 100 );
}

if( WC()->countries->get_base_city() ) {
$billing['shippingFromAddress']['city'] = self::safe( WC()->countries->get_base_city(), 100 );
}

if( WC()->countries->get_base_postcode() ) {
$billing['shippingFromAddress']['zip'] = self::safe( WC()->countries->get_base_postcode(), 10 );
}

if( WC()->countries->get_base_country() ) {
$billing['shippingFromAddress']['country'] = self::safe( WC()->countries->get_base_country(), 20 );
}

if( WC()->countries->get_base_state() ) {
$billing['shippingFromAddress']['state'] = self::safe( WC()->countries->get_base_state(), 20 );
}

return $billing;
}

/**
Expand Down Expand Up @@ -113,16 +130,33 @@ public function getShipping() { // phpcs:ignore
return null;
}

return array(
'shippingAddress' => array(
'line1' => self::safe( $this->order->get_shipping_address_1(), 100 ),
'line2' => self::safe( $this->order->get_shipping_address_2(), 100 ),
'city' => self::safe( $this->order->get_shipping_city(), 100 ),
'zip' => self::safe( $this->order->get_shipping_postcode(), 10 ),
'country' => self::safe( $this->order->get_shipping_country(), 10 ),
'state' => self::safe( $this->order->get_shipping_state(), 20 ),
)
);
$shipping = array();

if( $this->order->get_shipping_address_1() ) {
$shipping['shippingAddress']['line1'] = self::safe( $this->order->get_shipping_address_1(), 100 );
}

if( $this->order->get_shipping_address_2() ) {
$shipping['shippingAddress']['line2'] = self::safe( $this->order->get_shipping_address_2(), 100 );
}

if( $this->order->get_shipping_city() ) {
$shipping['shippingAddress']['city'] = self::safe( $this->order->get_shipping_city(), 100 );
}

if( $this->order->get_shipping_postcode() ) {
$shipping['shippingAddress']['zip'] = self::safe( $this->order->get_shipping_postcode(), 10 );
}

if( $this->order->get_shipping_country() ) {
$shipping['shippingAddress']['country'] = self::safe( $this->order->get_shipping_country(), 10 );
}

if( $this->order->get_shipping_state() ) {
$shipping['shippingAddress']['state'] = self::safe( $this->order->get_shipping_state(), 20 );
}

return $shipping;
}

/**
Expand All @@ -135,15 +169,37 @@ public function getCardInfo() { // phpcs:ignore
return null;
}

return array(
'name' => self::safe( $this->order->get_billing_first_name(), 50 ) . ' ' . self::safe( $this->order->get_billing_last_name(), 50 ),
'addressLine1' => self::safe( $this->order->get_shipping_address_1(), 100 ),
'addressLine2' => self::safe( $this->order->get_shipping_address_2(), 100 ),
'addressCity' => self::safe( $this->order->get_shipping_city(), 100 ),
'addressZip' => self::safe( $this->order->get_shipping_postcode(), 10 ),
'addressCountry' => self::safe( $this->order->get_shipping_country(), 10 ),
'addressState' => self::safe( $this->order->get_shipping_state(), 10 ),
);
$card_info = array();

if( $this->order->get_billing_first_name() ) {
$card_info['name'] = self::safe( $this->order->get_billing_first_name(), 50 ) . ' ' . self::safe( $this->order->get_billing_last_name(), 50 );
}

if( $this->order->get_shipping_address_1() ) {
$card_info['addressLine1'] = self::safe( $this->order->get_shipping_address_1(), 100 );
}

if( $this->order->get_shipping_address_2() ) {
$card_info['addressLine2'] = self::safe( $this->order->get_shipping_address_2(), 100 );
}

if( $this->order->get_shipping_city() ) {
$card_info['addressCity'] = self::safe( $this->order->get_shipping_city(), 100 );
}

if( $this->order->get_shipping_postcode() ) {
$card_info['addressZip'] = self::safe( $this->order->get_shipping_postcode(), 10 );
}

if( $this->order->get_shipping_country() ) {
$card_info['addressCountry'] = self::safe( $this->order->get_shipping_country(), 10 );
}

if( $this->order->get_shipping_state() ) {
$card_info['addressState'] = self::safe( $this->order->get_shipping_state(), 10 );
}

return $card_info;
}

/**
Expand All @@ -166,8 +222,7 @@ public function getCustomer() { // phpcs:ignore
public function getOrderCustomer() { // phpcs:ignore
return array(
'customerEmail' => self::safe( $this->order->get_billing_email(), 100 ),
'customerName' => self::safe( $this->order->get_billing_first_name(), 50 ) . ' ' . self::safe( $this->order->get_billing_last_name(), 50 ),
'customerNote' => self::safe( $this->order->get_customer_note(), 100 ),
'customerName' => self::safe( $this->order->get_billing_first_name(), 50 ) . ' ' . self::safe( $this->order->get_billing_last_name(), 50 )
);
}

Expand Down
Loading

0 comments on commit 068cb58

Please sign in to comment.