Plugin Directory

Changeset 2794884


Ignore:
Timestamp:
10/06/2022 07:10:05 AM (3 years ago)
Author:
aircash
Message:

updated LocationID, QR code reading

File:
1 edited

Legend:

Unmodified
Added
Removed
  • aircash-for-woocommerce/trunk/includes/class-aircash-payment-gateway.php

    r2735596 r2794884  
    99use BaconQrCode\Renderer\ImageRenderer;
    1010use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
     11use BaconQrCode\Renderer\PlainTextRenderer;
    1112use BaconQrCode\Renderer\RendererStyle\RendererStyle;
    1213use BaconQrCode\Writer;
     
    121122     */
    122123    public function add_html_to_admin() {
    123         echo '<div id="aircash-new-account-request-url" data-url="' . esc_attr($this->get_new_account_request_url()) . '"></div>';
     124        echo '<div id="aircash-new-account-request-url" data-url="' . esc_attr( $this->get_new_account_request_url() ) . '"></div>';
    124125    }
    125126
     
    427428            $order->save();
    428429        }
    429         $store_address   = get_option( 'woocommerce_store_address' );
    430         $store_address_2 = get_option( 'woocommerce_store_address_2' );
    431         $store_city      = get_option( 'woocommerce_store_city' );
    432         $store_postcode  = get_option( 'woocommerce_store_postcode' );
    433         $location        = null;
    434         if ( $store_address ) {
    435             $location .= $store_address . ', ';
    436         }
    437         if ( $store_address_2 ) {
    438             $location .= $store_address_2 . ', ';
    439         }
    440         if ( $store_city ) {
    441             $location .= trim( $store_postcode . ' ' . $store_city );
    442         }
    443         $store_raw_country = get_option( 'woocommerce_default_country' );
    444         if ( $store_raw_country ) {
    445             $location .= ', ' . $store_raw_country;
    446         }
     430        $location   = preg_replace( '/^https?:\/\//i', '', get_site_url() );
    447431        $parameters = array(
    448432            'Amount'               => (float) number_format( $order->get_total(), 2, '.', '' ),
     
    459443        // phpcs:ignore
    460444        ini_set( 'serialize_precision', - 1 );
    461         $body = wp_json_encode( $parameters, \JSON_UNESCAPED_SLASHES );
     445        $body = wp_json_encode( $parameters, JSON_UNESCAPED_SLASHES );
    462446        // phpcs:ignore
    463447        ini_set( 'serialize_precision', $serialize_precizion );
     
    472456            )
    473457        );
    474         $result   = $error_message = $qr_code_image_data = null;
     458        $result   = $error_message = $qr_code_image_data = $qr_code_textual = null;
    475459
    476460        $response_code = (int) wp_remote_retrieve_response_code( $response );
     
    485469            if ( isset( $result['codeLink'] ) && is_string( $result['codeLink'] ) ) {
    486470                // It's all good man, display the QR code
    487                 $renderer           = new ImageRenderer( new RendererStyle( 400 ), new ImagickImageBackEnd() );
    488                 $writer             = new Writer( $renderer );
    489                 $qr_code_image_data = $writer->writeString( $result['codeLink'] );
     471                if ( ! extension_loaded( 'imagick' ) ) {
     472                    $qr_code_textual    = true;
     473                    $renderer           = new PlainTextRenderer();
     474                    $writer             = new Writer( $renderer );
     475                    $qr_code_image_data = $writer->writeString( $result['codeLink'] );
     476                } else {
     477                    $qr_code_textual    = false;
     478                    $renderer           = new ImageRenderer( new RendererStyle( 400 ), new ImagickImageBackEnd() );
     479                    $writer             = new Writer( $renderer );
     480                    $qr_code_image_data = $writer->writeString( $result['codeLink'] );
     481                }
    490482            } else {
    491483                $error_message = 'Unable to generate QR code';
     
    520512
    521513                    <div class="aircash-qr-code-wrapper">
    522                         <img class="aircash-qr-code" src="data:image/png;base64,<?php
    523                         // phpcs:ignore
    524                         echo base64_encode( $qr_code_image_data );
    525                         ?>">
     514                        <?php
     515                        if ( $qr_code_textual ) {
     516                            ?>
     517                            <pre style="line-height:100%;color:black;font-family:monospace;font-size:11px;background:white;font-weight:100;letter-spacing:-1px;user-select:none;-webkit-user-select:none"><?php
     518                            echo $qr_code_image_data;
     519                            ?></pre><?php
     520                        } else {
     521                            ?>
     522                            <img class="aircash-qr-code" src="data:image/png;base64,<?php
     523                            // phpcs:ignore
     524                            echo base64_encode( $qr_code_image_data );
     525                            ?>">
     526                            <?
     527                        }
     528                        ?>
    526529                        <ol>
    527530                            <li><?php echo esc_html__( 'Open Aircash application', 'aircash-for-woocommerce' ) ?></li>
     
    951954        $this->update_option( $aircash_callback_url_option, $callback_url );
    952955
    953         $body          = wp_json_encode( $parameters, \JSON_UNESCAPED_SLASHES ^ \JSON_UNESCAPED_LINE_TERMINATORS ^ \JSON_PRETTY_PRINT );
     956        $body          = wp_json_encode( $parameters, JSON_UNESCAPED_SLASHES ^ JSON_UNESCAPED_LINE_TERMINATORS ^ JSON_PRETTY_PRINT );
    954957        $response      = wp_remote_post(
    955958            'https://' . ( $test ? 'staging-m3.aircash.eu' : 'm3.aircash.eu' ) . '/api/AircashPay/ActivatePartner',
Note: See TracChangeset for help on using the changeset viewer.