Plugin Directory

Changeset 2676477


Ignore:
Timestamp:
02/10/2022 03:44:54 PM (4 years ago)
Author:
grilabs
Message:

Gri SMS provider updated.

Location:
wp-sms-functions/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-sms-functions/trunk/inc/providers/Gri_Provider.php

    r2640751 r2676477  
    1212        $this->slug = 'Gri';
    1313        $this->name = 'Gri SMS';
    14         $this->api_base_url = 'https://sms-api.gri.net';
     14        $this->api_base_url = 'https://sms-api2.gri.net';
    1515
    1616        add_filter('Smsfunctions_providers', function ($prov) {
     
    5353        $secret_key = $options['gri_secret_key'];
    5454        return array(
    55             'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $secret_key)
     55            'Authorization' => 'Basic ' . base64_encode($api_key . ':' . $secret_key),
     56            'Content-Type' => 'application/json'
    5657        );
    5758    }
     
    6566
    6667        $post_fields = json_encode(array(
    67             'from' => $header,
    68             'msg' => $message,
    69             'to' => $gsmNo,
    70             'lang' => explode('_', get_locale())[0]
     68            'header' => $header,
     69            'message' => $message,
     70            'phone' => $gsmNo
    7171        ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    7272
     
    7474
    7575        try {
    76             $request = parent::wpPost($this->api_base_url . '/send-sms', $post_fields, $authentication);
     76            $request = parent::wpPost($this->api_base_url . '/SendSms', $post_fields, $authentication);
    7777            $response = json_decode($request);
    7878
    79             if ($response->status === false)
    80                 throw new Exception(isset($response->details) ? $response->details : 'An error occurred!');
     79            $errors = array();
     80            if (isset($response->errors)) {
     81                foreach ($response->errors as $error)
     82                {
     83                    $errors[] = implode(" - " , $error);
     84                }
     85                throw new Exception( count( $errors ) ? implode("\n", $errors) : 'An error occurred!' );
     86            }
    8187        } catch (Exception $ex) {
    8288            throw $ex;
     
    9298        $is_tokens = !empty($options['gri_api_key']) && !empty($options['gri_secret_key']);
    9399        if ($selected_provider === 'gri') {
    94             $request = parent::wpGet($this->api_base_url . '/get-headers', array(), $this->getAuthentication());
     100            $request = parent::wpGet($this->api_base_url . '/Headers', array(), $this->getAuthentication());
    95101            $response_for_sms_headers = json_decode($request);
    96102
    97             if (!$response_for_sms_headers->status) {
     103            if (!is_array($response_for_sms_headers) && isset($response_for_sms_headers->message)) {
    98104                echo "<strong style='color:red'>" .
    99                     $response_for_sms_headers->details .
     105                    $response_for_sms_headers->message .
    100106                    "</strong>";
    101107            }
     
    116122                    /></td>
    117123            </tr>
    118             <?php if (isset($response_for_sms_headers) && $response_for_sms_headers->status): ?>
     124            <?php if (is_array($response_for_sms_headers) && count($response_for_sms_headers)): ?>
    119125                <tr>
    120126                    <th><?php esc_html_e('SMS Header', 'wp-sms-functions') ?></th>
     
    128134                                <option value=""><?php esc_html_e('Select', 'wp-sms-functions'); ?></option>
    129135                                <?php
    130                                 foreach ($response_for_sms_headers->details as $header) {
     136                                foreach ($response_for_sms_headers as $header) {
    131137                                    $selected = ($options['gri_msg_header'] == $header) ? 'selected' : '';
    132138
     
    146152                            esc_html_e('You must save api key and secret key to view the balance.', 'wp-sms-functions');
    147153                        } else {
    148                             $request = parent::wpGet($this->api_base_url . '/get-balance', array(), $this->getAuthentication());
     154                            $request = parent::wpGet($this->api_base_url . '/Balance', array(), $this->getAuthentication());
    149155                            $response_for_balance = json_decode($request);
    150                             if ($response_for_balance->status) {
    151                                 esc_html_e($response_for_balance->details);
     156                            if ($response_for_balance->Balance) {
     157                                esc_html_e($response_for_balance->Balance);
    152158                            } else {
    153159                                esc_html_e('There is no balance defined for you. Please contact us!', 'wp-sms-functions');
  • wp-sms-functions/trunk/readme.txt

    r2640749 r2676477  
    4646== Changelog ==
    4747
     48= 1.2.5 =
     49* Gri SMS provider updated.
     50
    4851= 1.2.4 =
    4952* Gri SMS provider added.
  • wp-sms-functions/trunk/wp-sms-functions.php

    r2640749 r2676477  
    66 * Author URI: https://www.gri.net
    77 * Text Domain: wp-sms-functions
    8  * Version: 1.2.4
     8 * Version: 1.2.5
    99 * Domain Path: /lang
    1010 * Requires at least: 4.9
Note: See TracChangeset for help on using the changeset viewer.