Plugin Directory

Changeset 3031381


Ignore:
Timestamp:
02/05/2024 07:50:12 AM (2 years ago)
Author:
twispay
Message:

Twispay 2.0.17

Location:
twispay/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • twispay/trunk/helpers/Twispay_TW_Helper_Response.php

    r2997774 r3031381  
    6464
    6565            /** Check if the decryption was successful. */
    66             if (NULL === $decodedResponse) {
     66              if (NULL === $decodedResponse) {
    6767                /** Log the last error occurred during the last JSON encoding/decoding. */
    6868                switch (json_last_error()) {
    6969                    case JSON_ERROR_DEPTH:
    7070                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_DEPTH']);
    71                         break;
     71                    break;
    7272
    7373                    case JSON_ERROR_STATE_MISMATCH:
    7474                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_STATE_MISMATCH']);
    75                         break;
     75                    break;
    7676
    7777                    case JSON_ERROR_CTRL_CHAR:
    7878                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_CTRL_CHAR']);
    79                         break;
     79                    break;
    8080
    8181                    case JSON_ERROR_SYNTAX:
    8282                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_SYNTAX']);
    83                         break;
     83                    break;
    8484
    8585                    case JSON_ERROR_UTF8:
    8686                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_UTF8']);
    87                         break;
     87                    break;
    8888
    8989                    case JSON_ERROR_RECURSION:
    9090                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_RECURSION']);
    91                         break;
     91                    break;
    9292
    9393                    case JSON_ERROR_INF_OR_NAN:
    9494                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_INF_OR_NAN']);
    95                         break;
     95                    break;
    9696
    9797                    case JSON_ERROR_UNSUPPORTED_TYPE:
    9898                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_UNSUPPORTED_TYPE']);
    99                         break;
     99                    break;
    100100
    101101                    case JSON_ERROR_INVALID_PROPERTY_NAME:
    102102                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_INVALID_PROPERTY_NAME']);
    103                         break;
     103                    break;
    104104
    105105                    case JSON_ERROR_UTF16:
    106106                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_UTF16']);
    107                         break;
     107                    break;
    108108
    109109                    default:
    110110                        Twispay_TW_Logger::twispay_tw_log($tw_lang['JSON_ERROR_UNKNOWN']);
    111                         break;
     111                    break;
    112112                }
    113113
     
    136136
    137137            if ( empty( $tw_response['status'] ) && empty( $tw_response['transactionStatus'] ) ) {
    138                 $tw_errors[] = $tw_lang['log_error_empty_status'];
     138               $tw_errors[] = $tw_lang['log_error_empty_status'];
    139139            }
    140140
  • twispay/trunk/helpers/Twispay_TW_Status_Updater.php

    r3030007 r3031381  
    2626        /* Array containing the possible result statuses. */
    2727        public static $RESULT_STATUSES = [
    28             'UNCERTAIN' => 'uncertain' /* No response from provider */
     28                'UNCERTAIN' => 'uncertain' /* No response from provider */
    2929            , 'IN_PROGRESS' => 'in-progress' /* Authorized */
    3030            , 'COMPLETE_OK' => 'complete-ok' /* Captured */
     
    9797                    </div>
    9898                    <?php
    99                     break;
     99                break;
    100100
    101101                case Twispay_TW_Status_Updater::$RESULT_STATUSES['THREE_D_PENDING']:
     
    131131                    </div>
    132132                    <?php
    133                     break;
     133                break;
    134134
    135135                case Twispay_TW_Status_Updater::$RESULT_STATUSES['IN_PROGRESS']:
     
    139139                    if(class_exists('WC_Subscriptions') && wcs_order_contains_subscription($order)){
    140140
    141                         $subscription = wcs_get_subscriptions_for_order($order);
    142                         $subscription = reset($subscription);
    143 
    144                         /* First payment on order, process payment & activate subscription. */
    145                         if ( 0 == $subscription->get_payment_count() ) {
    146 
    147                             $order->payment_complete();
    148 
    149                             if(class_exists('WC_Subscriptions') ){
    150                                 WC_Subscriptions_Manager::activate_subscriptions_for_order( $order );
    151                             }
    152                         } else {
    153                             if(class_exists('WC_Subscriptions') ){
    154                                 WC_Subscriptions_Manager::process_subscription_payments_on_order( $order );
    155                             }
    156                         }
    157 
     141                      $subscription = wcs_get_subscriptions_for_order($order);
     142                      $subscription = reset($subscription);
     143
     144                      /* First payment on order, process payment & activate subscription. */
     145                      if ( 0 == $subscription->get_payment_count() ) {
     146
     147                          $order->payment_complete();
     148                         
     149                          if(class_exists('WC_Subscriptions') ){
     150                              WC_Subscriptions_Manager::activate_subscriptions_for_order( $order );
     151                          }
     152                      } else {
     153                          if(class_exists('WC_Subscriptions') ){
     154                              WC_Subscriptions_Manager::process_subscription_payments_on_order( $order );
     155                          }
     156                      }
     157                           
    158158                    }
    159159                    try {
    160160                        global $wpdb;
    161                         $query = $wpdb->prepare(
    162                             "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s",
    163                             $decrypted['transactionId']
     161                    $query = $wpdb->prepare(
     162                        "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s",
     163                        $decrypted['transactionId']
    164164                        );
    165 
     165                   
    166166                        // Execute the query
    167167                        $item_count = (int) $wpdb->get_var( $query );
    168 
    169                         // Check if the transaction already exists
     168           
     169                        // Check if the transaction already exists 
    170170                        if ($item_count == 0) {
    171                             $wpdb->get_results(
     171                            $wpdb->get_results( 
    172172                                $wpdb->prepare( "
    173173                                INSERT INTO `" . $wpdb->prefix . "twispay_tw_transactions` (
     
    189189                                    '%d',
    190190                                    '%s'
    191                                 );",
    192                                     'complete-ok',
    193                                     $order->get_id(),
    194                                     $order->get_customer_id(),
    195                                     $decrypted['orderId'],
    196                                     $decrypted['transactionId'],
    197                                     $decrypted['customerId'],
    198                                     $decrypted['cardId'],
    199                                     $checkout_url )
    200                             );
    201                             Twispay_TW_Logger::twispay_tw_log("Correspondence between twispay transaction and woocommerce order saved in database: orderID: $orderId, transactionID: {$decrypted['transactionId']}, customerID: {$decrypted['customerId']}, cardID: {$decrypted['cardId']}" );
    202                         } else {
    203                             $wpdb->query(
    204                                 $wpdb->prepare(
    205                                     "UPDATE `" . $wpdb->prefix . "twispay_tw_transactions`
     191                                );", 
     192                                $serverStatus,
     193                                $order->get_id(),
     194                                $order->get_customer_id(),
     195                                $decrypted['orderId'],
     196                                $decrypted['transactionId'],
     197                                $decrypted['customerId'],
     198                                $decrypted['cardId'],
     199                                $checkout_url )
     200                        );
     201                        Twispay_TW_Logger::twispay_tw_log("Correspondence between twispay transaction and woocommerce order saved in database: orderID: $orderId, transactionID: {$decrypted['transactionId']}, customerID: {$decrypted['customerId']}, cardID: {$decrypted['cardId']}" );
     202                    } else {
     203                        $wpdb->query(
     204                            $wpdb->prepare(
     205                                "UPDATE `" . $wpdb->prefix . "twispay_tw_transactions`
    206206                                 SET `checkout_url` = %s
    207207                                 WHERE `transactionId` = %d",
    208                                     $checkout_url,
    209                                     $decrypted['transactionId']
    210                                 )
    211                             );
    212                             Twispay_TW_Logger::twispay_tw_log("CheckoutURL updated:" . $checkout_url);
    213                         }
     208                                $checkout_url,
     209                                $decrypted['transactionId']
     210                            )
     211                        );
     212                        Twispay_TW_Logger::twispay_tw_log("CheckoutURL updated:" . $checkout_url);
     213                    }
    214214                    } catch(Throwable | Exception $e) {
    215215                        Twispay_TW_Logger::twispay_tw_log("Exception while trying to register transaction: " . $e->getMessage() . " <> " . $e->getTraceAsString());
     
    224224                        new Twispay_TW_Default_Thankyou( $order );
    225225                    }
    226                     break;
     226                break;
    227227
    228228                default:
     
    260260                    </div>
    261261                    <?php
    262                     break;
     262                break;
    263263            }
    264264        }
     
    287287
    288288                    Twispay_TW_Logger::twispay_tw_log($tw_lang['log_ok_status_failed'] . $orderId);
    289                     break;
     289                break;
    290290
    291291                case Twispay_TW_Status_Updater::$RESULT_STATUSES['CANCEL_OK']:
     
    301301
    302302                    Twispay_TW_Logger::twispay_tw_log($tw_lang['log_ok_status_refund'] . $orderId);
    303                     break;
     303                break;
    304304
    305305                case Twispay_TW_Status_Updater::$RESULT_STATUSES['THREE_D_PENDING']:
     
    308308
    309309                    Twispay_TW_Logger::twispay_tw_log($tw_lang['log_ok_status_hold'] . $orderId);
    310                     break;
     310                break;
    311311
    312312                case Twispay_TW_Status_Updater::$RESULT_STATUSES['IN_PROGRESS']:
     
    317317
    318318                    if(class_exists('WC_Subscriptions') && wcs_order_contains_subscription($order)){
    319                         $subscription = wcs_get_subscriptions_for_order($order);
    320                         $subscription = reset($subscription);
    321 
    322                         /* First payment on order, process payment & activate subscription. */
    323                         if ( 0 == $subscription->get_payment_count() ) {
    324                             $order->payment_complete();
    325                             $order->update_status('completed', esc_html__( $tw_lang['wa_order_complete_ok'], 'woocommerce' ));
    326 
    327                             if(class_exists('WC_Subscriptions') ){
    328                                 WC_Subscriptions_Manager::activate_subscriptions_for_order( $order );
    329                             }
    330                         } else {
    331                             if(class_exists('WC_Subscriptions') ){
    332                                 WC_Subscriptions_Manager::process_subscription_payments_on_order( $order );
    333                             }
     319                      $subscription = wcs_get_subscriptions_for_order($order);
     320                      $subscription = reset($subscription);
     321
     322                      /* First payment on order, process payment & activate subscription. */
     323                      if ( 0 == $subscription->get_payment_count() ) {
     324                          $order->payment_complete();
     325                          $order->update_status('completed', esc_html__( $tw_lang['wa_order_complete_ok'], 'woocommerce' ));
     326
     327                          if(class_exists('WC_Subscriptions') ){
     328                              WC_Subscriptions_Manager::activate_subscriptions_for_order( $order );
     329                          }
     330                      } else {
     331                        if(class_exists('WC_Subscriptions') ){
     332                            WC_Subscriptions_Manager::process_subscription_payments_on_order( $order );
    334333                        }
    335 
     334                      }
     335                     
    336336
    337337                    } else {
    338338                        try {
    339339                            global $wpdb;
    340                             $query = $wpdb->prepare(
    341                                 "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s",
    342                                 $decrypted['transactionId']
    343                             );
    344 
    345                             // Execute the query
    346                             $item_count = (int) $wpdb->get_var( $query );
    347 
    348                             // Check if the transaction already exists
    349                             if ($item_count == 0) {
    350                                 $wpdb->get_results(
    351                                     $wpdb->prepare( "
     340                      $query = $wpdb->prepare(
     341                        "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s",
     342                        $decrypted['transactionId']
     343                        );
     344                   
     345                        // Execute the query
     346                        $item_count = (int) $wpdb->get_var( $query );
     347           
     348                        // Check if the transaction already exists
     349                        if ($item_count == 0) {
     350                            $wpdb->get_results(
     351                                $wpdb->prepare( "
    352352                                INSERT INTO `" . $wpdb->prefix . "twispay_tw_transactions` (
    353353                                    `status`,
     
    368368                                    '%d',
    369369                                    '%s'
    370                                 );",
    371                                         'complete-ok',
    372                                         $order->get_id(),
    373                                         $order->get_customer_id(),
    374                                         $decrypted['orderId'],
    375                                         $decrypted['transactionId'],
    376                                         $decrypted['customerId'],
    377                                         $decrypted['cardId'],
    378                                         "" )
    379                                 );
    380                                 Twispay_TW_Logger::twispay_tw_log("Correspondence between twispay transaction and woocommerce order saved in database: orderID: $orderId, transactionID: {$decrypted['transactionId']}, customerID: {$decrypted['customerId']}, cardID: {$decrypted['cardId']}" );
    381                             }
     370                                );", 
     371                                $serverStatus,
     372                                $order->get_id(),
     373                                $order->get_customer_id(),
     374                                $decrypted['orderId'],
     375                                $decrypted['transactionId'],
     376                                $decrypted['customerId'],
     377                                $decrypted['cardId'],
     378                                "" )
     379                            );
     380                            Twispay_TW_Logger::twispay_tw_log("Correspondence between twispay transaction and woocommerce order saved in database: orderID: $orderId, transactionID: {$decrypted['transactionId']}, customerID: {$decrypted['customerId']}, cardID: {$decrypted['cardId']}" );
     381                        }
    382382                        } catch(Throwable | Exception $e) {
    383383                            Twispay_TW_Logger::twispay_tw_log("Exception while trying to register transaction: " . $e->getMessage() . " <> " . $e->getTraceAsString());
     
    386386
    387387                    Twispay_TW_Logger::twispay_tw_log($tw_lang['log_ok_status_complete'] . $orderId);
    388                     break;
     388                break;
    389389
    390390                default:
    391                     Twispay_TW_Logger::twispay_tw_log($tw_lang['log_error_wrong_status'] . $serverStatus);
    392                     break;
     391                  Twispay_TW_Logger::twispay_tw_log($tw_lang['log_error_wrong_status'] . $serverStatus);
     392                break;
    393393            }
    394394        }
     
    396396
    397397        /**
    398          * Update the status of an Woocommerce subscription according to the received server status.
    399          *
    400          * @param orderId: The ID of the order that is the parent of the subscription.
    401          * @param serverStatus: The status received from server.
    402          * @param tw_lang: The array of available messages.
    403          *
    404          * @return void
    405          */
     398        * Update the status of an Woocommerce subscription according to the received server status.
     399        *
     400        * @param orderId: The ID of the order that is the parent of the subscription.
     401        * @param serverStatus: The status received from server.
     402        * @param tw_lang: The array of available messages.
     403        *
     404        * @return void
     405        */
    406406        public static function updateSubscriptionStatus($orderId, $serverStatus, $tw_lang){
    407407            /* Check that the subscriptions plugin is installed. */
    408408            if(!class_exists('WC_Subscriptions') ){
    409                 return;
     409              return;
    410410            }
    411411
     
    424424                        Twispay_TW_Logger::twispay_tw_updateTransactionStatus($orderId, $serverStatus);
    425425                    }
    426                     break;
     426                break;
    427427
    428428                case Twispay_TW_Status_Updater::$RESULT_STATUSES['COMPLETE_OK']: /* The subscription has been completed. */
     
    436436                        Twispay_TW_Logger::twispay_tw_updateTransactionStatus($orderId, $serverStatus);
    437437                    }
    438                     break;
     438                break;
    439439
    440440                case Twispay_TW_Status_Updater::$RESULT_STATUSES['EXPIRING']: /* The subscription will expire soon. */
     
    445445                        Twispay_TW_Logger::twispay_tw_updateTransactionStatus($orderId, $serverStatus);
    446446                    }
    447                     break;
     447                break;
    448448
    449449                default:
    450                     Twispay_TW_Logger::twispay_tw_log($tw_lang['log_error_wrong_status'] . $serverStatus);
    451                     break;
     450                  Twispay_TW_Logger::twispay_tw_log($tw_lang['log_error_wrong_status'] . $serverStatus);
     451                break;
    452452            }
    453453        }
  • twispay/trunk/includes/admin/transaction/requests.php

    r2627254 r3031381  
    195195}
    196196add_action( 'tw_synchronize_subscriptions', 'tw_twispay_p_synchronize_subscriptions' );
     197
     198
     199function tw_twispay_p_synchronize_transactions( $request ) {
     200    $orders = [];
     201    global $wpdb;
     202    $apiKey = '';
     203    $configuration = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "twispay_tw_configuration" );
     204
     205    if ( $configuration ) {
     206        if ( $configuration->live_mode == 1 ) {
     207            $apiKey = sanitize_text_field( $configuration->live_key );
     208            $baseUrl = 'https://api.twispay.com/order?createdAtFrom=2024-01-29T00%3A00%3A00%2B00%3A00&reverseSorting=0';
     209        } else if ( $configuration->live_mode == 0 ) {
     210            $apiKey = sanitize_text_field( $configuration->staging_key );
     211            $baseUrl = 'https://api-stage.twispay.com/order?createdAtFrom=2024-01-29T00%3A00%3A00%2B00%3A00&reverseSorting=0';
     212        }
     213    }
     214
     215
     216    /* Load languages. */
     217    $lang = explode( '-', get_bloginfo( 'language' ) )[0];
     218    if ( file_exists( TWISPAY_PLUGIN_DIR . 'lang/' . $lang . '/lang.php' ) ) {
     219        require( TWISPAY_PLUGIN_DIR . 'lang/' . $lang . '/lang.php' );
     220    } else {
     221        require( TWISPAY_PLUGIN_DIR . 'lang/en/lang.php' );
     222    }
     223
     224    /* Execute the request. This means to perform a "GET"/"PUT" request at the specified URL. */
     225    $args = array('method' => 'GET', 'headers' => ['accept' => 'application/json', 'Authorization' => $apiKey]);
     226    $response = wp_remote_request( $baseUrl, $args );
     227
     228    if( FALSE === $response ) {
     229        Twispay_TW_Logger::twispay_tw_log( $tw_lang['subscriptions_log_error_call_failed'] . WP_Error::get_error_message() );
     230        $skip = TRUE;
     231    }
     232    $response = json_decode($response['body']);
     233
     234    if ( 'Success' == $response->message ) {
     235        if ($response->pagination->currentItemCount) {
     236            foreach ($response->data as $order) {
     237                $orders[$order->id]['externalOrderId'] = $order->externalOrderId;
     238            }
     239        }
     240    }
     241
     242    if ( $configuration ) {
     243        if ( $configuration->live_mode == 1 ) {
     244            $apiKey = sanitize_text_field( $configuration->live_key );
     245            $baseUrl = 'https://api.twispay.com/transaction?createdAtFrom=2024-01-29T00%3A00%3A00%2B00%3A00&reverseSorting=0';
     246        } else if ( $configuration->live_mode == 0 ) {
     247            $apiKey = sanitize_text_field( $configuration->staging_key );
     248            $baseUrl = 'https://api-stage.twispay.com/transaction?createdAtFrom=2024-01-29T00%3A00%3A00%2B00%3A00&reverseSorting=0';
     249        }
     250    }
     251
     252    /* Execute the request. This means to perform a "GET"/"PUT" request at the specified URL. */
     253    $args = array('method' => 'GET', 'headers' => ['accept' => 'application/json', 'Authorization' => $apiKey]);
     254    $response = wp_remote_request( $baseUrl, $args );
     255
     256   
     257    if( FALSE === $response ) {
     258        Twispay_TW_Logger::twispay_tw_log( $tw_lang['subscriptions_log_error_call_failed'] . WP_Error::get_error_message() );
     259        $skip = TRUE;
     260    }
     261
     262    $response = json_decode($response['body']);
     263
     264    if ( 'Success' == $response->message ) {
     265        if ($response->pagination->currentItemCount) {
     266            foreach ($response->data as $transaction) {
     267                if (isset($orders[$transaction->orderId])) {
     268                    if (isset($orders[$transaction->orderId]['transactionId']) && $transaction->id < $orders[$transaction->orderId]['transactionId']) {
     269                        continue;
     270                    }
     271                    $orders[$transaction->orderId]['transactionId'] = $transaction->id;
     272                    $orders[$transaction->orderId]['cardId'] = $transaction->cardId;
     273                    $orders[$transaction->orderId]['status'] = $transaction->transactionStatus;
     274                }
     275            }
     276        }
     277    }
     278
     279    foreach ($orders as $orderId => $details) {
     280        if (!isset($details['status'])) {
     281            Twispay_TW_Logger::twispay_tw_log("Error: Status not found for orderId=$orderId");
     282            continue;
     283        }
     284        if (!isset($details['externalOrderId'])) {
     285            Twispay_TW_Logger::twispay_tw_log("Error: externalOrderId not found for orderId=$orderId");
     286            continue;
     287        }
     288        if (!isset($details['transactionId'])) {
     289            Twispay_TW_Logger::twispay_tw_log("Error: transactionId not found for orderId=$orderId");
     290            continue;
     291        }
     292        if (!isset($details['cardId'])) {
     293            Twispay_TW_Logger::twispay_tw_log("Error: cardId not found for orderId=$orderId");
     294            continue;
     295        }
     296        // echo "Successfully added woocommerce order no. " . $details['externalOrderId'] . " with status: " . $details['status'] . " and transactionId: " . $details['transactionId'];die;
     297        global $wpdb;
     298        $query = $wpdb->prepare(
     299            "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s",
     300            $details['transactionId']
     301            );
     302       
     303            // Execute the query
     304            $item_count = (int) $wpdb->get_var( $query );
     305
     306            // Check if the transaction already exists
     307            if ($item_count == 0) {
     308                $wcOrder =  wc_get_order($details['externalOrderId']);
     309                if (false == $wcOrder) {
     310                    Twispay_TW_Logger::twispay_tw_log("Invalid externalOrderId: " . $details['orderId'] . ". Transaction has been skipped.");
     311                    continue;
     312                }
     313                $wcCustomerId = $wcOrder->get_customer_id();
     314                if (false == $wcCustomerId) {
     315                    Twispay_TW_Logger::twispay_tw_log("Invalid wcCustomerId. Transaction has been skipped.");
     316                    continue;
     317                }
     318                try {
     319                    $wpdb->get_results(
     320                        $wpdb->prepare( "
     321                            INSERT INTO `" . $wpdb->prefix . "twispay_tw_transactions` (
     322                                `status`,
     323                                `id_cart`,
     324                                `identifier`,
     325                                `orderId`,
     326                                `transactionId`,
     327                                `customerId`,
     328                                `cardId`,
     329                                `checkout_url`
     330                            ) VALUES (
     331                                '%s',
     332                                '%s',
     333                                '%s',
     334                                '%d',
     335                                '%d',
     336                                '%d',
     337                                '%d',
     338                                '%s'
     339                            );",
     340                            $details['status'],
     341                            $details['externalOrderId'],
     342                            $wcCustomerId,
     343                            $details['externalOrderId'],
     344                            $details['transactionId'],
     345                            $wcCustomerId,
     346                            $details['cardId'],
     347                            "" )
     348                    );
     349                } catch (Throwable | Exception $e) {
     350                    Twispay_TW_Logger::twispay_tw_log("Failed to add woocommerce order no. " . $details['externalOrderId'] . " with status " . $details['status'] . " and transactionId: " . $details['transactionId'] . " due to error " . $e->getMessage());
     351                }
     352               
     353
     354            Twispay_TW_Logger::twispay_tw_log("Successfully added woocommerce order no. " . $details['externalOrderId'] . " with status " . $details['status'] . " and transactionId: " . $details['transactionId']);
     355            }
     356    }
     357
     358}
     359
     360add_action( 'tw_synchronize_transactions', 'tw_twispay_p_synchronize_transactions');
  • twispay/trunk/includes/admin/transaction/transaction.php

    r2627254 r3031381  
    6969                        </form>
    7070                    <?php } ?>
     71
     72                    <form method="post" id="synchronize_transactions">
     73                        <table class="form-table">
     74                            <tr class="form-field" id="contact_email_o">
     75                                <th scope="row"><label><?= esc_html( $tw_lang['transactions_sync_label'] ); ?></span></label></th>
     76                                <td>
     77                                    <input type="hidden" name="tw_general_action" value="synchronize_transactions" />
     78                                    <?php submit_button( esc_attr( $tw_lang['transactions_sync_button'] ), 'primary', 'createuser', true, array( 'id' => 'synchronizetransactions' ) ); ?>
     79                                    <p class="description"><?= esc_html( $tw_lang['transactions_sync_desc'] ); ?></p>
     80                                </td>
     81                            </tr>
     82                        </table>
     83                    </form>
    7184
    7285
  • twispay/trunk/includes/class-tw-server-to-server.php

    r3030007 r3031381  
    2626        }
    2727
    28         /** @var array $tw_lang */
     28        /** @var array $tw_lang */
    2929
    3030        // Check if the POST is corrupted: doesn't contain the 'opensslResult' and the 'result' fields.
    3131        if (isset($_POST['opensslResult']) === false && isset($_POST['result']) === false) {
    32             Twispay_TW_Logger::twispay_tw_log($tw_lang['log_error_empty_response']);
     32            Twispay_TW_Logger::twispay_tw_log($tw_lang['log_error_empty_response']);
    3333            die($tw_lang['log_error_empty_response']);
    3434        }
     
    7070
    7171            // Prepare the query to prevent SQL injection
    72             $query = $wpdb->prepare(
    73                 "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s",
    74                 $transactionId
     72            $query = $wpdb->prepare( 
     73                "SELECT COUNT(*) FROM {$wpdb->prefix}twispay_tw_transactions WHERE TransactionId = %s", 
     74                $transactionId 
    7575            );
    76 
     76           
    7777            // Execute the query
    7878            $item_count = (int) $wpdb->get_var( $query );
    7979
    80             // Check if the transaction already exists
     80            // Check if the transaction already exists 
    8181            //update order status and dont continue with new order
    8282            if ($item_count > 0) {
     
    9797            }
    9898            Twispay_TW_Status_Updater::updateStatus_IPN($order->get_id(), $status, $tw_lang, $decrypted);
    99 
     99       
    100100            // Send the 200 OK response back to the Twispay server.
    101101            die('OK');
  • twispay/trunk/includes/scripts.php

    r3009867 r3031381  
    482482
    483483
    484 /**
    485  * Suppress email functionality
    486  */
    487 function twispay_tw_unhook_woo_order_emails( $email_class ) {
    488     return;
    489     // New order emails
    490     remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    491     remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    492     remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    493     remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    494     remove_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    495     remove_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    496 
    497     // Processing order emails
    498     remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
    499     remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
    500 
    501     // Completed order emails
    502     remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
    503 }
    504 
    505 function twispay_tw_hook_woo_order_emails( $email_class ) {
    506     return;
    507     if (! has_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) )) {
    508         add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    509     }
    510 
    511     if(! has_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) )){
    512         add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    513     }
    514 
    515     if(! has_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) )){
    516         add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    517     }
    518 
    519     if(! has_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) )){
    520         add_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    521     }
    522 
    523     if(! has_action( 'woocommerce_order_status_failed_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) )){
    524         add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    525     }
    526 
    527     if(! has_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) )){
    528         add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    529     }
    530 
    531     if(! has_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) )){
    532         add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
    533     }
    534 
    535     if(! has_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) )){
    536         add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );
    537     }
    538 
    539     if(! has_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) )){
    540         add_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
    541     }
    542 }
    543 
    544 // Get configuration from database
    545 global $wpdb;
    546 $suppress_email = $wpdb->get_row( "SELECT suppress_email FROM " . $wpdb->prefix . "twispay_tw_configuration" );
    547 
    548 //if ( $suppress_email ) {
    549 //    if ( $suppress_email->suppress_email == 1 ) {
    550 //        add_action( 'woocommerce_email', 'twispay_tw_unhook_woo_order_emails' );
    551 //    } else {
    552 //        add_action('woocommerce_email', 'twispay_tw_hook_woo_order_emails');
    553 //    }
    554 //}
    555 
    556 
    557 
    558484function subscription_terminated( $subscription ){
    559485    /* Get configuration from database. */
     
    567493        )
    568494    );
     495
    569496    if ( $configuration ) {
    570497        if ( $configuration->live_mode == 1 ) {
     
    584511        require( TWISPAY_PLUGIN_DIR . 'lang/en/lang.php' );
    585512    }
    586 
    587513    $args = array( 'method' => 'DELETE'
    588514                  , 'headers' => ['accept' => 'application/json', 'Authorization' => $apiKey]);
     515               
    589516    $response = wp_remote_request($url, $args);
    590517
  • twispay/trunk/lang/en/lang.php

    r2923880 r3031381  
    160160$tw_lang['general_error_invalid_order'] = ' Order does not exist.';
    161161$tw_lang['general_error_invalid_private'] = ' Private key is not valid.';
     162$tw_lang['transactions_sync_label'] = 'Update transactions list';
     163$tw_lang['transactions_sync_desc'] = 'Updates the corespondence between twispay transactions and woocomerce orders.';
     164$tw_lang['transactions_sync_button'] = 'Update';
    162165
    163166
  • twispay/trunk/lang/ro/lang.php

    r2923880 r3031381  
    160160$tw_lang['general_error_invalid_order'] = ' Comanda nu există.';
    161161$tw_lang['general_error_invalid_private'] = ' Cheie privată nevalidă.';
     162$tw_lang['transactions_sync_label'] = 'Actualizeaza lista de tranzactii';
     163$tw_lang['transactions_sync_desc'] = 'Actualizeaza corespondenta dintre tranzactiile twispay si comenzile woocommerce.';
     164$tw_lang['transactions_sync_button'] = 'Actualizeaza';
    162165
    163166
  • twispay/trunk/readme.txt

    r3030007 r3031381  
    4040
    4141== Changelog ==
     42
     43= 2.0.17 =
     44* Add update transactions list button
    4245
    4346= 2.0.15 =
  • twispay/trunk/twispay.php

    r3030007 r3031381  
    44 * Plugin URI: https://wordpress.org/plugins/twispay/
    55 * Description: Plugin for Twispay payment gateway.
    6  * Version: 2.0.15
     6 * Version: 2.0.17
    77 * Author: twispay
    88 * Author URI: https://www.twispay.com
Note: See TracChangeset for help on using the changeset viewer.