Plugin Directory

Changeset 2850806


Ignore:
Timestamp:
01/19/2023 01:21:03 AM (3 years ago)
Author:
trakadev
Message:

Add cardano as currency
fix error when markup is 0
update to Preview Testnet

Location:
sargapay/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sargapay/trunk/admin/class-sargapay-admin.php

    r2827431 r2850806  
    337337            } else {
    338338                $api_call = $gateway->check_API_KEY(1, $blockfrost_test_key);
    339                 if ($api_call === 1) return __('Error: blockforst testnet api call failed', 'sargapay');
     339                if ($api_call === 1) return __('Error: blockforst testnet api call failed >>>' . $api_call, 'sargapay');
    340340            }
    341341        } else {
     
    367367
    368368        $markup = $request->get_param('markup');
    369         if (empty($markup)) {
    370             return __('Error: markup can\'t be empty', 'sargapay');
    371         } else if (!is_numeric($markup)) {
     369        if (!is_numeric($markup)) {
    372370            return __('Error: markup is not a number', 'sargapay');
    373371        }
     
    376374        if (empty($time_wait)) {
    377375            return __('Error: time to wait can\'t be empty', 'sargapay');
    378         } else if (!is_numeric($markup)) {
     376        } else if (!is_numeric($time_wait)) {
    379377            return __('Error: time to wait is not a number', 'sargapay');
    380378        }
  • sargapay/trunk/includes/class-sargapay.php

    r2827431 r2850806  
    144144        require_once SARGAPAY_PATH . 'paymentGateway/cardano/functions/sargapay-thank-you-page.php';
    145145        require_once SARGAPAY_PATH . 'paymentGateway/cardano/functions/sargapay-cancel-order.php';
     146        require_once SARGAPAY_PATH . 'paymentGateway/cardano/functions/sargapay-cardano-currency.php';
    146147
    147148        add_action('plugins_loaded', [$this, 'sargapay_init_gateway_class']);
    148149        // Add QR and Payment Address to thank you page
    149150        add_filter('woocommerce_thankyou_order_received_text', 'sargapay_thank_you_text', 20, 2);
     151        add_filter('woocommerce_currencies', 'add_sarga_cardano_currency');
     152        add_filter('woocommerce_currency_symbol', 'add_sarga_cardano_currency_symbol', 10, 2);
    150153    }
    151154
     
    227230        $this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_menu');
    228231        $this->loader->add_action('wp_register_script', $plugin_admin, 'register_admin_resources');
    229         $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_resources');     
     232        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_resources');
    230233        $this->loader->add_action('init', $plugin_admin, 'register_admin_resources');
    231234        $this->loader->add_action('init', $plugin_admin, 'add_translation_json');
  • sargapay/trunk/paymentGateway/cardano/assets/js/hotWallets.js

    r2827431 r2850806  
    6161        const amount = BigInt(amount_span.innerText * 1000000)
    6262
    63         const net = network == 1 ? "Mainnet" : "Testnet"
     63        const net = network == 1 ? "Mainnet" : "Preview"
    6464        const url = `https://cardano-${net.toLowerCase()}.blockfrost.io/api/v0`
    6565        const lucid = await Lucid.new(new Blockfrost(url, apikey), net)
     
    8484
    8585                console.log(txHash)
    86                 const explorerUrl = network == 1 ? "https://cexplorer.io/tx/" : "https://testnet.cexplorer.io/tx/"
     86                const explorerUrl = network == 1 ? "https://cexplorer.io/tx/" : "https://preview.cexplorer.io/tx/"
    8787
    8888                //Notify Success
  • sargapay/trunk/paymentGateway/cardano/class-sargapay-confirm-payment.php

    r2827431 r2850806  
    119119            $stake_key = substr($payment_address, 53, -6);
    120120        } else {
    121             $url_network = 'https://cardano-testnet.blockfrost.io/api/v0/';
     121            $url_network = "https://cardano-preview.blockfrost.io/api/v0/";
    122122            $api_key = WC()->payment_gateways->payment_gateways()['sargapay_cardano']->blockfrost_test_key;
    123123            $stake_key = substr($payment_address, 58, -6);
  • sargapay/trunk/paymentGateway/cardano/class-sargapay-gateway.php

    r2827431 r2850806  
    224224    {
    225225        if ($testmode == 1) {
    226             $url = "https://cardano-testnet.blockfrost.io/api/v0/";
     226            $url = "https://cardano-preview.blockfrost.io/api/v0/";
    227227            $network = "TESTNET";
    228228        } else {
     
    260260    }
    261261
    262     public function payment_fields()
    263     {
    264         // Get supported currencies
     262    private function getCurrency()
     263    {
     264        $result = new stdClass();
     265
     266        if (strtolower(get_woocommerce_currency()) === "sargacardano") {
     267            $result->currency = "ADA";
     268            $result->symbol = get_woocommerce_currency_symbol();
     269            return $result;
     270        }
     271
     272        // Get supported currencies coingeeko
    265273        $request = wp_remote_retrieve_body(wp_remote_get('https://api.coingecko.com/api/v3/simple/supported_vs_currencies'));
    266274        $supported_currencies = json_decode($request, true);
    267         // check if the wc currency is supported if is not we remplace it with the plugin options currency           
     275
     276        // check if the wc currency is supported if is not we remplace it with the plugin options currency
    268277        if (in_array(strtolower(get_woocommerce_currency()), $supported_currencies)) {
    269             $currency = get_woocommerce_currency();
    270             $symbol = get_woocommerce_currency_symbol();
     278            $result->currency = get_woocommerce_currency();
     279            $result->symbol = get_woocommerce_currency_symbol();
    271280        } else {
    272281            $currency = $this->currency;
    273             $currency === "USD" ? $symbol = "$" : $symbol = "€";
    274         }
    275         $request = wp_remote_retrieve_body(wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=' . $currency));
    276         $data = json_decode($request, true);
    277         if (count($data) == 1) {
     282            switch ($currency) {
     283                case "ADA":
     284                    $result->symbol = "₳";
     285                    break;
     286                case "EUR":
     287                    $result->symbol = "€";
     288                    break;
     289                default:
     290                    $result->symbol = "$";
     291                    break;
     292            }
     293        }
     294
     295        return $result;
     296    }
     297
     298    public function payment_fields()
     299    {
     300        $currencyObj = $this->getCurrency();
     301        $currency = $currencyObj->currency;
     302        $symbol = $currencyObj->symbol;
     303        if ($currency !== "ADA") {
     304            $request = wp_remote_retrieve_body(wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=' . $currency));
     305            $data = json_decode($request, true);
     306        }
     307        if ($currency === "ADA" || count($data) == 1) {
    278308            if ($this->testmode) {
    279309        ?>
     
    290320            $cryptoMarkup = $cryptoMarkupPercent / 100.0;
    291321            $cryptoPriceRatio = 1.0 + $cryptoMarkup;
    292             $fiat = $data['cardano'][array_key_first($data['cardano'])];
     322
     323            $fiat = $currency === "ADA" ? 1 : $data['cardano'][array_key_first($data['cardano'])];
    293324            global $wp;
    294             if(isset($wp->query_vars['order-pay'])){
     325            if (isset($wp->query_vars['order-pay'])) {
    295326                $order_id = $wp->query_vars['order-pay'];
    296327                $order = new WC_Order($order_id);
    297328                $fiat_total_order = $order->get_total();
    298             }else{
     329            } else {
    299330                $fiat_total_order = WC()->cart->get_totals()["total"];
    300331            }
     
    304335            <p><?php echo esc_html($instrucciones); ?></p>
    305336            <div style='text-align:center;'>
    306                 <p><?php echo __("Currency", 'sargapay') . " = " . esc_html($currency); ?></p>
    307                 <p><?php echo __("ADA Price", 'sargapay') . " = " . esc_html($symbol) . " " . esc_html($fiat); ?></p>
     337                <?php if ($currency !== "ADA") { ?>
     338                    <p><?php echo __("Currency", 'sargapay') . " = " . esc_html($currency); ?></p>
     339                    <p><?php echo __("ADA Price", 'sargapay') . " = " . esc_html($symbol) . " " . esc_html($fiat); ?></p>
     340                <?php } ?>
    308341                <p><?php echo __("ADA Total", 'sargapay') . " = " . esc_html($total_ada) . "*"; ?></p>
    309342            </div>
     
    332365    {
    333366        global $woocommerce;
    334         $order = new WC_Order($order_id);       
     367        $order = new WC_Order($order_id);
    335368        // Mark as on-hold (we're awaiting the confirmations)
    336369        $order->update_status('on-hold', __('Awaiting valid payment', 'woocommerce'));
     
    338371        // GENERATE PAYMENT ADDRESS
    339372        $total_ada = 0;
    340         // Get supported currencies
    341         $request = wp_remote_retrieve_body(wp_remote_get('https://api.coingecko.com/api/v3/simple/supported_vs_currencies'));
    342         $supported_currencies = json_decode($request, true);
    343         // check if the wc currency is supported if is not we remplace it with the plugin options currency           
    344         if (in_array(strtolower(get_woocommerce_currency()), $supported_currencies)) {
    345             $currency = get_woocommerce_currency();
    346         } else {
    347             $currency = $this->currency;
    348         }
    349         $request = wp_remote_retrieve_body(wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=' . $currency));
    350         $data = json_decode($request, true);
    351         if (count($data) == 1) {
     373        $currencyObj = $this->getCurrency();
     374        $currency = $currencyObj->currency;
     375        if ($currency !== "ADA") {
     376            $request = wp_remote_retrieve_body(wp_remote_get('https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=' . $currency));
     377            $data = json_decode($request, true);
     378        }
     379        if ($currency === "ADA" || count($data) == 1) {
    352380
    353381            $cryptoMarkupPercent = $this->markup;
     
    359387            $cryptoMarkup = $cryptoMarkupPercent / 100.0;
    360388            $cryptoPriceRatio = 1.0 + $cryptoMarkup;
    361             $fiat = $data['cardano'][array_key_first($data['cardano'])];
     389            $fiat = $currency === "ADA" ? 1 : $data['cardano'][array_key_first($data['cardano'])];
    362390            $fiat_total_order = WC()->cart->get_totals()["total"];
    363391            $cryptoTotalPreMarkup = round($fiat_total_order / $fiat, 6, PHP_ROUND_HALF_UP);
     
    382410
    383411            if ($wpdb->last_error === "" && isset($get_key[0]->pay_address)) {
    384                 $pay_address = $get_key[0]->pay_address;
    385412                $id = $get_key[0]->id;
    386413                // Update data                 
  • sargapay/trunk/readme.txt

    r2827431 r2850806  
    6969== Changelog ==
    7070
     71= 2.1 =
     72* Add Cardano Currency to WooCommerce
     73* Fix markup error
     74* Update Testnet to Preview Testnet Network
     75
    7176= 2.0 =
    7277* Admin Dashboard UI
  • sargapay/trunk/sargapay.php

    r2827447 r2850806  
    1717 * Plugin URI:        https://sargatxet.cloud/sargapay-cardano/
    1818 * Description:       WordPress payment gateway for crypto.
    19  * Version:           2.0.0
     19 * Version:           2.1.0
    2020 * Author:            Sargatxet
    2121 * Author URI:        https://sargatxet.cloud/
     
    6262define('SARGAPAY_PATH', plugin_dir_path(__FILE__));
    6363define('SARGAPAY_URL', plugin_dir_url(__FILE__));
    64 define('SARGAPAY_VERSION', '2.0.0');
     64define('SARGAPAY_VERSION', '2.1.0');
    6565
    6666add_filter('cron_schedules', 'sargapay_cron_hook');
Note: See TracChangeset for help on using the changeset viewer.