bloyalControllerObj = new BloyalController(); $this->snippets_controller_obj = new BloyalSnippetsController(); } /** * This function is used to ajax * * @return json array */ function ajax_stored_payment_on_update() { try { $is_logged_in_user = is_user_logged_in(); $access_key = get_option( 'bloyal_access_key' ); if ( ! empty( $access_key ) ) { $user_details = $this->snippets_controller_obj->get_new_customer_details_from_wbdb(); $email_id = $user_details['Customer']['EmailAddress']; $user_id = $user_details['Customer']['ExternalId']; $session_key = $this->get_session_key( $user_id, $email_id ); if ( ! class_exists( 'Bloyal_Stored_Payment_Gateway' ) ) { // CON-106: the gateway class is only defined when WooCommerce (WC_Payment_Gateway) // is loaded. If it is unavailable on this request, skip the alert instead of fataling // with an uncaught Error (which try/catch ( Exception ) would not catch). wp_send_json( wp_json_encode( array( 'title' => '', 'html' => '', 'is_logged_in' => $is_logged_in_user, 'session_key' => $session_key, ) ) ); die; } $obj_payment = new Bloyal_Stored_Payment_Gateway(); $alertHtml = $obj_payment->payment_web_snippets_callback(); $alertValue = ''; if ( ! empty( $alertHtml ) ) { $alertsData = array( // 'title' => $alertValue->Category, 'title' => isset($alertValue->Category) && $alertValue->Category !== null ? $alertValue->Category : '', 'html' => $alertHtml, 'is_logged_in' => $is_logged_in_user, 'session_key' => $session_key, ); } wp_send_json( wp_json_encode( $alertsData ) ); die; } else { $alertsData = array( 'title' => '', 'html' => 'Access key is not generated', 'is_logged_in' => $is_logged_in_user, 'session_key' => '', ); wp_send_json( wp_json_encode( $alertsData ) ); die; } } catch ( Exception $ex ) { bLoyalLoggerService::write_custom_log( $ex->getMessage(), 3 ); } } /** * Generate session key using * * @param void * * @return string */ public function get_session_key( $user_id, $email_id ) { try { $customer_session = ''; $customer_details = $this->resolve_customer_in_director( $user_id, $email_id ); if ( ! empty( $customer_details ) ) { if ( $customer_details->status == 'success' ) { if(isset($customer_details->data)){ $customer_session = $customer_details->data->SessionKey; } } } return $customer_session; } catch ( Exception $e ) { $this->log( __FUNCTION__, 'Error in save multiple shipping addresses Reason: ' . $e->getMessage() ); return $e->getMessage(); } } /** * This function is used to resolve customer in director account * * @param integer $external_id * @param string $customer_email * @return json array */ function resolve_customer_in_director( $external_id, $customer_email ) { try { $action = 'resolvedcustomersession?EmailAddress=' . urlencode( $customer_email ) . '&ExternalId=' . $external_id; $result = $this->bloyalControllerObj->send_curl_request( '', $action, 'loyaltyengine', 0 ); return $result; } catch ( Exception $e ) { $this->log( __FUNCTION__, 'Error in resolving customer. Reason: ' . $e->getMessage() ); bLoyalLoggerService::write_custom_log( $e->getMessage(), 3 ); return $e->getMessage(); } } } }