Plugin Directory

Changeset 3461995


Ignore:
Timestamp:
02/15/2026 06:19:20 PM (7 weeks ago)
Author:
coinsnap
Message:
  1. 1.2.3
Location:
coinsnap-bitcoin-voting
Files:
36 added
9 edited

Legend:

Unmodified
Added
Removed
  • coinsnap-bitcoin-voting/trunk/assets/css/style.css

    r3355796 r3461995  
    335335  transform: translate(-50%, -50%);
    336336  background: white;
    337   padding: 58px 28px;
    338337  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    339338  z-index: 99999;
     
    342341  flex-direction: column;
    343342  align-items: center;
    344   width: 340px;
     343  width: 90%;
     344  max-width: 720px;
     345  max-height: 95%;
     346  overflow: auto;
     347  box-sizing: border-box;
    345348  gap: 12px;
    346349}
     
    349352  max-width: 200px !important;
    350353}
     354
     355
    351356
    352357.close-popup {
     
    602607}
    603608
     609#blur-overlay-outer {
     610    z-index: 99998;
     611}
     612
     613#coinsnap-popup-outer {
     614    z-index: 99999;
     615}
     616
    604617.blur-overlay {
    605618  display: none;
     
    621634  flex-direction: column;
    622635  width: -webkit-fill-available;
    623   margin: 0px 24px;
     636  margin: 20px;
    624637}
    625638
    626639.payment-loading {
    627640  display: none;
     641  padding:20px;
    628642}
    629643
     
    633647  justify-content: center;
    634648  align-items: center;
     649  padding:20px;
    635650}
    636651
     
    644659  justify-content: center;
    645660  align-items: center;
    646 
     661  padding:20px;
    647662}
    648663
     
    689704}
    690705
     706.person-grid {
     707    display: flex;
     708    gap: 8px;
     709}
     710
     711@media screen and (max-width: 600px) { 
     712    .person-grid {
     713        flex-direction: column;
     714    }
     715}
     716
    691717.address-grid {
    692718  display: flex;
     
    700726  gap: 8px;
    701727  justify-content: space-between;
     728}
     729
     730.address-row .address-cell.half {
     731    width:50%;
     732}
     733
     734.address-row .address-cell.quart {
     735    width:25%;
    702736}
    703737
  • coinsnap-bitcoin-voting/trunk/assets/js/admin.js

    r3355796 r3461995  
    174174
    175175    async function handleCheckConnection(isSubmit = false) {
    176       event.preventDefault();
    177       var connection = false
     176      //event.preventDefault();
     177      var connection = false;
    178178      const ngrokLiveUrl = document.getElementById('ngrok_url')?.value;
    179179      const origin = ngrokLiveUrl ? ngrokLiveUrl : new URL(window.location.href).origin;
    180       const webhookUrl = `${origin}/wp-json/coinsnap-bitcoin-voting/v1/webhook`
    181       if ($providerSelector?.val() == 'coinsnap') {
     180      const webhookUrl = `${origin}/wp-json/coinsnap-bitcoin-voting/v1/webhook`;
     181      if ($providerSelector?.val() === 'coinsnap') {
    182182        const coinsnapStoreId = $('#coinsnap_store_id').val();
    183183        const coinsnapApiKey = $('#coinsnap_api_key').val();
    184         connection = await checkConnection(coinsnapStoreId, coinsnapApiKey)
     184        connection = await checkConnection(coinsnapStoreId, coinsnapApiKey);
    185185        if (connection) {
    186           const webhooks = await checkWebhooks(coinsnapStoreId, coinsnapApiKey)
     186          const webhooks = await checkWebhooks(coinsnapStoreId, coinsnapApiKey);
    187187          const webhookFound = webhooks?.find(webhook => webhook.url === webhookUrl);
    188188          if (!webhookFound) {
    189             await createWebhook(coinsnapStoreId, coinsnapApiKey, webhookUrl)
     189            await createWebhook(coinsnapStoreId, coinsnapApiKey, webhookUrl);
    190190          } else {
    191             await updateWebhook(coinsnapStoreId, coinsnapApiKey, webhookUrl, webhookFound.id)
     191            await updateWebhook(coinsnapStoreId, coinsnapApiKey, webhookUrl, webhookFound.id);
    192192          }
    193193        }
     
    207207        }
    208208      }
    209       setCookie('coinsnap_connection_', JSON.stringify({ 'connection': connection }), 20)
     209      setCookie('coinsnap_bitcoin_voting_connection', JSON.stringify({ 'connection': connection }), 20);
    210210      if (!isSubmit) {
    211211        $('#submit').click();
     
    223223    $checkConnectionBtcPayButton.on('click', async (event) => { await handleCheckConnection(); });
    224224
    225     const connectionCookie = getCookie('coinsnap_connection_');
     225    const connectionCookie = getCookie('coinsnap_bitcoin_voting_connection');
    226226    if (connectionCookie) {
    227227      const connectionState = JSON.parse(connectionCookie)?.connection
  • coinsnap-bitcoin-voting/trunk/assets/js/popup.js

    r3355796 r3461995  
    4747}
    4848
    49 const popupButtonListener = (exchangeRates, pollId, amount, amountFiat, currency, publicDonor) => {
     49const popupButtonListener = (pollId, amount, amountFiat, currency, publicDonor) => {
    5050
    5151    document.getElementById(`coinsnap-bitcoin-voting-public-donors-pay${pollId}`)?.addEventListener('click', async () => {
     
    7171            donorName: `${firstNameField.value} ${lastNameField?.value ?? ''}`,
    7272            donorEmail: emailField?.value,
    73             donorAddress: address != ' ,  , ' ? address : '',
     73            donorAddress: (address !== ' ,  , ')? address : '',
    7474            donorCustom: customContent,
    7575            formType: 'Coinsnap Bitcoin Voting',
     
    119119
    120120            // Add fiat amount
    121             //if (exchangeRates['EUR']) {
    122                 document.getElementById(`coinsnap-bitcoin-voting-qr-fiat${pollId}`).textContent = `≈ ${(res.amount * exchangeRates['EUR'])?.toFixed(3)} EUR`;
     121                document.getElementById(`coinsnap-bitcoin-voting-qr-fiat${pollId}`).textContent = `≈ ${amountFiat} ${currency}`;
    123122                document.getElementById(`coinsnap-bitcoin-voting-pay-in-wallet${pollId}`).setAttribute('href', `lightning:${qrLightning}`);
    124             //}
     123           
    125124
    126125            // Reset retry counter
     
    146145
    147146
    148                         } else if (qrContainer.style.display != 'flex') {
     147                        } else if (qrContainer.style.display !== 'flex') {
    149148                            retryId = '';
    150149                        }
    151                         else if (retryNum < 180 && retryId == res.id) {
     150                        else if (retryNum < 180 && retryId === res.id) {
    152151                            retryNum++;
    153152                            checkPaymentStatus();
     
    159158                        console.error('Error checking payment status:', error);
    160159                        retryNum++;
    161                         if (retryId == res.id) {
     160                        if (retryId === res.id) {
    162161                            setTimeout(checkPaymentStatus, 5000);
    163162                        }
    164163                    });
    165164            }
    166             checkPaymentStatus()
     165            checkPaymentStatus();
    167166
    168167        }
    169168        else {
    170             console.error('Error creating invoice')
     169            console.error('Error creating invoice');
    171170        }
    172171
  • coinsnap-bitcoin-voting/trunk/assets/js/shared.js

    r3355796 r3461995  
    1414    const expires = "expires=" + d.toUTCString();
    1515    document.cookie = name + "=" + value + ";" + expires + ";path=/";
    16 }
    17 
    18 async function fetchCoinsnapExchangeRates() {
    19     const exchangeRates = {}
    20     try {
    21         const response = await fetch(`https://app.coinsnap.io/api/v1/stores/${sharedData.coinsnapStoreId}/rates`, {
    22             method: 'GET',
    23             headers: {
    24                 'Content-Type': 'application/json',
    25                 'x-api-key': sharedData.coinsnapApiKey
    26             }
    27         });
    28 
    29         if (!response.ok) {
    30             throw new Error(`HTTP error! Status: ${response.status}`);
    31         }
    32 
    33         const data = await response.json();
    34         data
    35             .filter(item => item.currencyPair.includes("SATS")) // Filter only SATS rates
    36             .forEach(item => {
    37                 const currency = item.currencyPair.replace("SATS_", ""); // Remove "SATS_" prefix
    38                 exchangeRates[currency] = parseFloat(item.rate); // Update exchangeRates
    39             });
    40 
    41         return exchangeRates;
    42     } catch (error) {
    43         console.error('Error fetching exchange rates:', error);
    44         return null;
    45     }
    4616}
    4717
     
    6232
    6333const createActualVotingInvoice = async (amount, message, lastInputCurrency, name, coinsnap, type, redirect, metadata) => {
    64     deleteCookie('coinsnap_invoice_');
     34    deleteCookie('coinsnap_invoice_voting');
     35
     36    var orderId = 'VTNG_' + (Date.now()).toString(36);
     37   
     38    var provider = (coinsnap === true)? 'coinsnap' : 'btcpay';
     39   
     40    if(provider === 'btcpay'){
     41        metadata.orderId = orderId;
     42    }
    6543
    6644    const requestData = {
    6745        amount: amount,
    6846        currency: lastInputCurrency,
     47        buyerEmail: metadata.donorEmail,
    6948        redirectAutomatically: true,
     49        checkout: {
     50            redirectAutomatically: true
     51        },
     52        orderId: orderId,
     53        walletMessage: message,
    7054        metadata: {
    7155            orderNumber: message,
     
    7357            type: type,
    7458            name: name,
    75             ...metadata //TEST with voting
     59            ...metadata
    7660        }
    7761    };
    78 
     62   
     63    requestData.provider = (provider === 'coinsnap')? 'coinsnap' : 'btcpay';
     64   
    7965    if (type === 'Coinsnap Bitcoin Voting') {
    80         // requestData.metadata.optionId = metadata.optionId
    81         // requestData.metadata.option = metadata.option
    82         // requestData.metadata.pollId = metadata.pollId
    83         requestData.metadata.orderNumber = `Voted for ${metadata.option}`
    84         redirectAutomatically = false //TODO test
    85     }
    86 
     66        requestData.redirectUrl = requestData.checkout.redirectUrl = Coinsnap_Bitcoin_Voting_sharedData?.redirectUrl || window.location.href;
     67        requestData.metadata.orderNumber = `Voted for ${metadata.option}`;
     68    }
     69   
    8770    if (window.location.href.includes("localhost")) {
    88         requestData.redirectUrl = "https://coinsnap.io";
    89     }
    90 
    91     if (coinsnap) {
     71        requestData.redirectUrl = requestData.checkout.redirectUrl = "https://coinsnap.io";
     72    }
     73
     74    if (provider === 'coinsnap') {
    9275        requestData.referralCode = 'D19833';
    9376    }
    9477
    95     const url = coinsnap
    96         ? `https://app.coinsnap.io/api/v1/stores/${sharedData?.coinsnapStoreId}/invoices`
    97         : `${sharedData?.btcpayUrl}/api/v1/stores/${sharedData?.btcpayStoreId}/invoices`;
    98 
    99     const headers = coinsnap
     78    const url = (provider === 'coinsnap')
     79        ? `https://app.coinsnap.io/api/v1/stores/${Coinsnap_Bitcoin_Voting_sharedData?.coinsnapStoreId}/invoices`
     80        : `${Coinsnap_Bitcoin_Voting_sharedData?.btcpayUrl}/api/v1/stores/${Coinsnap_Bitcoin_Voting_sharedData?.btcpayStoreId}/invoices`;
     81
     82    const headers = (provider === 'coinsnap')
    10083        ? {
    101             'x-api-key': sharedData?.coinsnapApiKey,
     84            'x-api-key': Coinsnap_Bitcoin_Voting_sharedData?.coinsnapApiKey,
    10285            'Content-Type': 'application/json'
    10386        }
    10487        : {
    105             'Authorization': 'token '+sharedData?.btcpayApiKey,
     88            'Authorization': 'token '+Coinsnap_Bitcoin_Voting_sharedData?.btcpayApiKey,
    10689            'Content-Type': 'application/json'
    10790        };
     
    129112        };
    130113
    131         setCookie('coinsnap_invoice_', JSON.stringify(invoiceCookieData), 15);
    132         if (!coinsnap) {
    133             const url = `${sharedData?.btcpayUrl}/api/v1/stores/${sharedData?.btcpayStoreId}/invoices/${responseData.id}/payment-methods`;
     114        setCookie('coinsnap_invoice_voting', JSON.stringify(invoiceCookieData), 15);
     115        if (provider === 'btcpay') {
     116            const url = `${Coinsnap_Bitcoin_Voting_sharedData?.btcpayUrl}/api/v1/stores/${Coinsnap_Bitcoin_Voting_sharedData?.btcpayStoreId}/invoices/${responseData.id}/payment-methods`;
    134117            const response2 = await fetch(url, {
    135118                method: 'GET',
    136                 headers: headers,
     119                headers: headers
    137120            });
    138121            const responseData2 = await response2.json();
    139             const paymentLink = responseData2[0].paymentLink
    140             console.log('Payment Link:', paymentLink)
    141             responseData.lightningInvoice = paymentLink?.replace('lightning:', '')
    142             responseData.onchainAddress = ''
     122            const paymentLink = responseData2[0].paymentLink;
     123            responseData.lightningInvoice = paymentLink?.replace('lightning:', '');
     124            responseData.onchainAddress = '';
    143125
    144126            // Generate QR code image from lightning invoice
     
    146128            responseData.qrCodes = {
    147129                lightningQR: qrCodeImage || paymentLink
    148             }
     130            };
    149131        }
    150132        if (redirect) {
     
    161143const checkVotingInvoiceStatus = async (invoiceId, amount, message, lastInputCurrency, name, coinsnap, type, redirect, metadata) => {
    162144
    163     const url = coinsnap
    164         ? `https://app.coinsnap.io/api/v1/stores/${sharedData.coinsnapStoreId}/invoices/${invoiceId}`
    165         : `${sharedData.btcpayUrl}/api/v1/stores/${sharedData.btcpayStoreId}/invoices/${invoiceId}`;
    166 
    167     const headers = coinsnap
     145    var provider = (coinsnap === true)? 'coinsnap' : 'btcpay';
     146   
     147    const url = (provider === 'coinsnap')
     148        ? `https://app.coinsnap.io/api/v1/stores/${Coinsnap_Bitcoin_Voting_sharedData.coinsnapStoreId}/invoices/${invoiceId}`
     149        : `${Coinsnap_Bitcoin_Voting_sharedData.btcpayUrl}/api/v1/stores/${Coinsnap_Bitcoin_Voting_sharedData.btcpayStoreId}/invoices/${invoiceId}`;
     150
     151    const headers = (provider === 'coinsnap')
    168152        ? {
    169             'x-api-key': sharedData.coinsnapApiKey,
     153            'x-api-key': Coinsnap_Bitcoin_Voting_sharedData.coinsnapApiKey,
    170154            'Content-Type': 'application/json'
    171155
    172156        }
    173157        : {
    174             'Authorization': 'token '+sharedData.btcpayApiKey,
     158            'Authorization': 'token '+Coinsnap_Bitcoin_Voting_sharedData.btcpayApiKey,
    175159            'Content-Type': 'application/json'
    176160        };
     
    188172        var responseData = await response.json();
    189173
    190         if (!coinsnap) {
    191             const url = `${sharedData?.btcpayUrl}/api/v1/stores/${sharedData?.btcpayStoreId}/invoices/${responseData.id}/payment-methods`;
     174        if (provider === 'btcpay') {
     175            const url = `${Coinsnap_Bitcoin_Voting_sharedData?.btcpayUrl}/api/v1/stores/${Coinsnap_Bitcoin_Voting_sharedData?.btcpayStoreId}/invoices/${responseData.id}/payment-methods`;
    192176            const response2 = await fetch(url, {
    193177                method: 'GET',
    194                 headers: headers,
     178                headers: headers
    195179            });
    196180            const responseData2 = await response2.json();
    197             const paymentLink = responseData2[0].paymentLink
    198             console.log('Payment Link:', paymentLink)
    199             responseData.lightningInvoice = paymentLink?.replace('lightning:', '')
    200             responseData.onchainAddress = ''
     181            const paymentLink = responseData2[0].paymentLink;
     182            responseData.lightningInvoice = paymentLink?.replace('lightning:', '');
     183            responseData.onchainAddress = '';
    201184
    202185            // Generate QR code image from lightning invoice
     
    213196                window.location.href = responseData.checkoutLink;
    214197            }
    215             return responseData
     198            return responseData;
    216199        }
    217200
     
    222205};
    223206
     207//  Invoice creation
    224208const createVotingInvoice = async (amount, message, amountFiat, lastInputCurrency, name, type, redirect = true, metadata) => {
    225     existingInvoice = getCookie('coinsnap_invoice_');
     209    existingInvoice = getCookie('coinsnap_invoice_voting');
    226210    lastInputCurrency = 'SATS';
    227211    if (existingInvoice) {
     
    241225                lastInputCurrency,
    242226                name,
    243                 sharedData.provider == 'coinsnap',
     227                Coinsnap_Bitcoin_Voting_sharedData.provider === 'coinsnap',
    244228                type,
    245229                redirect,
    246230                metadata
    247             )
    248             return cs
     231            );
     232            return cs;
    249233        }
    250234        else {
     
    254238                lastInputCurrency,
    255239                name,
    256                 sharedData.provider == 'coinsnap',
     240                Coinsnap_Bitcoin_Voting_sharedData.provider === 'coinsnap',
    257241                type,
    258242                redirect,
    259243                metadata
    260             )
     244            );
    261245        }
    262246    }
     
    267251            lastInputCurrency,
    268252            name,
    269             sharedData.provider == 'coinsnap',
     253            Coinsnap_Bitcoin_Voting_sharedData.provider === 'coinsnap',
    270254            type,
    271255            redirect,
    272256            metadata
    273         )
    274     }
    275 }
     257        );
     258    }
     259};
    276260
    277261const hideVotingElementById = (id, prefix = '', sufix = '') => {
     
    282266        hideVotingElementById(id, prefix, sufix)
    283267    })
    284 }
     268};
    285269const showVotingElementById = (id, display, prefix = '', sufix = '') => {
    286     document.getElementById(`${prefix}${id}${sufix}`).style.display = display
    287 }
     270    document.getElementById(`${prefix}${id}${sufix}`).style.display = display;
     271};
    288272const showVotingElementsById = (ids, display, prefix = '', sufix = '') => {
    289273    ids.forEach(id => {
    290         showVotingElementById(id, display, prefix, sufix)
     274        showVotingElementById(id, display, prefix, sufix);
    291275    })
    292 }
     276};
  • coinsnap-bitcoin-voting/trunk/assets/js/voting.js

    r3355796 r3461995  
    1 jQuery(document).ready(function ($) {
     1jQuery(document).ready(function($) {
    22
     3    if(!$('#blur-overlay-outer').length){
     4        $('body').append('<div id="blur-overlay-outer"></div><div id="coinsnap-popup-outer"></div>');       
     5    }
     6   
    37    if (document.getElementsByClassName('coinsnap-bitcoin-voting-form')?.length > 0) {
     8       
     9        var overlayContainer = $('.blur-overlay.coinsnap-bitcoin-voting').detach();
     10        $('#blur-overlay-outer').append(overlayContainer); 
     11        var qrContainer = $('.qr-container.coinsnap-bitcoin-voting').detach();
     12        $('#coinsnap-popup-outer').append(qrContainer);
    413
    5         fetchCoinsnapExchangeRates().then(rates => {
     14        //fetchCoinsnapExchangeRates().then(rates => {
    615            addWindowListeners();
    716            const votingForms = document.getElementsByClassName('coinsnap-bitcoin-voting-form');
     
    1322                const currency = votingForm.dataset.pollCurrency;
    1423                const donorInfo = votingForm.dataset.donorInfo;
    15                 popupButtonListener(rates, pollId, amount, amountFiat, currency, donorInfo);
     24                popupButtonListener(pollId, amount, amountFiat, currency, donorInfo);
    1625            }
    17         });
     26        //});
    1827       
    1928
     
    6170            fetchResultsFromDb(pollId, votingForm);
    6271        };
    63 
    64         const votingForms = document.getElementsByClassName('coinsnap-bitcoin-voting-form');
    6572
    6673        for (let i = 0; i < votingForms.length; i++) {
  • coinsnap-bitcoin-voting/trunk/coinsnap-bitcoin-voting.php

    r3412858 r3461995  
    44 * Plugin URI:         https://coinsnap.io/coinsnap-bitcoin-voting-plugin/
    55 * Description:        Easy Bitcoin voting on a WordPress website
    6  * Version:            1.2.1
     6 * Version:            1.2.3
    77 * Author:             Coinsnap
    88 * Author URI:         https://coinsnap.io/
     
    1919
    2020if(!defined( 'COINSNAP_BITCOIN_VOTING_REFERRAL_CODE' ) ) { define( 'COINSNAP_BITCOIN_VOTING_REFERRAL_CODE', 'D46835' );}
    21 if(!defined( 'COINSNAP_BITCOIN_VOTING_VERSION' ) ) { define( 'COINSNAP_BITCOIN_VOTING_VERSION', '1.2.1' );}
     21if(!defined( 'COINSNAP_BITCOIN_VOTING_VERSION' ) ) { define( 'COINSNAP_BITCOIN_VOTING_VERSION', '1.2.3' );}
    2222if(!defined( 'COINSNAP_BITCOIN_VOTING_PHP_VERSION' ) ) { define( 'COINSNAP_BITCOIN_VOTING_PHP_VERSION', '8.0' );}
    2323if(!defined( 'COINSNAP_BITCOIN_VOTING_PLUGIN_DIR' ) ){ define('COINSNAP_BITCOIN_VOTING_PLUGIN_DIR',plugin_dir_url(__FILE__));}
     
    213213
    214214                    // Store the host to options before we leave the site.
    215                     coinsnap_settings_update(['btcpay_url' => $host]);
     215                    coinsnap_settings_update('coinsnap_bitcoin_voting_options',['btcpay_url' => $host]);
    216216
    217217                    // Return the redirect url.
     
    226226    }
    227227
    228     function coinsnap_bitcoin_voting_enqueue_scripts()
    229     {
    230        
    231         wp_enqueue_style('coinsnap-bitcoin-voting-style', plugin_dir_url(__FILE__) . 'assets/css/style.css', [], COINSNAP_BITCOIN_VOTING_VERSION);
    232         wp_enqueue_script('coinsnap-bitcoin-voting-script', plugin_dir_url(__FILE__) . 'assets/js/voting.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
    233 
    234         $provider_defaults = [
    235             'provider' => 'coinsnap',
    236             'coinsnap_store_id' => '',
    237             'coinsnap_api_key' => '',
    238             'btcpay_store_id' => '',
    239             'btcpay_api_key' => '',
    240             'btcpay_url' => ''
    241         ];
    242         $provider_options = array_merge($provider_defaults, (array) get_option('coinsnap_bitcoin_voting_options', []));
    243         wp_enqueue_script('coinsnap-bitcoin-voting-popup-script', plugin_dir_url(__FILE__) . 'assets/js/popup.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
    244 
    245         // Localize script for sharedData
    246         wp_enqueue_script('coinsnap-bitcoin-voting-shared-script', plugin_dir_url(__FILE__) . 'assets/js/shared.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
    247         wp_localize_script('coinsnap-bitcoin-voting-shared-script', 'sharedData', [
    248             'provider' => $provider_options['provider'],
    249             'coinsnapStoreId' => $provider_options['coinsnap_store_id'],
    250             'coinsnapApiKey' => $provider_options['coinsnap_api_key'],
    251             'btcpayStoreId' => $provider_options['btcpay_store_id'],
    252             'btcpayApiKey' => $provider_options['btcpay_api_key'],
    253             'btcpayUrl' => $provider_options['btcpay_url'],
    254             'nonce' => wp_create_nonce('wp_rest')
    255         ]);
     228    function coinsnap_bitcoin_voting_enqueue_scripts(){
     229       
     230        global $post;
     231   
     232        if ( is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'coinsnap_bitcoin_voting') ) {
     233            wp_enqueue_style('coinsnap-bitcoin-voting-style', plugin_dir_url(__FILE__) . 'assets/css/style.css', [], COINSNAP_BITCOIN_VOTING_VERSION);
     234            wp_enqueue_script('coinsnap-bitcoin-voting-script', plugin_dir_url(__FILE__) . 'assets/js/voting.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
     235
     236            $provider_defaults = [
     237                'provider' => 'coinsnap',
     238                'coinsnap_store_id' => '',
     239                'coinsnap_api_key' => '',
     240                'btcpay_store_id' => '',
     241                'btcpay_api_key' => '',
     242                'btcpay_url' => ''
     243            ];
     244            $provider_options = array_merge($provider_defaults, (array) get_option('coinsnap_bitcoin_voting_options', []));
     245            wp_enqueue_script('coinsnap-bitcoin-voting-popup-script', plugin_dir_url(__FILE__) . 'assets/js/popup.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
     246           
     247            $sharedDataArray = [
     248                'provider' => $provider_options['provider'],
     249                'nonce' => wp_create_nonce('wp_rest')
     250            ];
     251           
     252            if($provider_options['provider'] === 'btcpay'){
     253                $sharedDataArray['btcpayStoreId'] = $provider_options['btcpay_store_id'];
     254                $sharedDataArray['btcpayApiKey'] = $provider_options['btcpay_api_key'];
     255                $sharedDataArray['btcpayUrl'] = $provider_options['btcpay_url'];
     256            }
     257            else {
     258                $sharedDataArray['coinsnapStoreId'] = $provider_options['coinsnap_store_id'];
     259                $sharedDataArray['coinsnapApiKey'] = $provider_options['coinsnap_api_key'];
     260            }
     261
     262            // Localize script for sharedData
     263            wp_enqueue_script('coinsnap-bitcoin-voting-shared-script', plugin_dir_url(__FILE__) . 'assets/js/shared.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
     264            wp_localize_script('coinsnap-bitcoin-voting-shared-script', 'Coinsnap_Bitcoin_Voting_sharedData', $sharedDataArray);
     265        }
     266       
     267       
     268       
    256269       
    257270    }
     
    259272    function coinsnap_bitcoin_voting_enqueue_admin_styles($hook){
    260273        $post_id = (filter_input(INPUT_GET,'post',FILTER_SANITIZE_FULL_SPECIAL_CHARS ))? filter_input(INPUT_GET,'post',FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : '';
    261         wp_enqueue_script('coinsnap-bitcoin-voting-admin-script', plugin_dir_url(__FILE__) . 'assets/js/admin.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
    262         wp_localize_script('coinsnap-bitcoin-voting-admin-script', 'coinsnap_bitcoin_voting_ajax', array(
    263             'ajax_url' => admin_url('admin-ajax.php'),
    264             'nonce'  => wp_create_nonce( 'coinsnap-ajax-nonce' ),
    265             'post' => $post_id
    266         ));
     274        $post_type = (filter_input(INPUT_GET,'post_type',FILTER_SANITIZE_FULL_SPECIAL_CHARS ))? filter_input(INPUT_GET,'post_type',FILTER_SANITIZE_FULL_SPECIAL_CHARS ) :
     275            ((!empty($post_id))? get_post_type($post_id) : '');
     276        $page = (filter_input(INPUT_GET,'page',FILTER_SANITIZE_FULL_SPECIAL_CHARS ))? filter_input(INPUT_GET,'page',FILTER_SANITIZE_FULL_SPECIAL_CHARS ) : '';
     277       
     278        if($page === 'coinsnap-bitcoin-voting' || $post_type === 'coinsnap-polls'){
     279            wp_enqueue_script('coinsnap-bitcoin-voting-admin-script', plugin_dir_url(__FILE__) . 'assets/js/admin.js', ['jquery'], COINSNAP_BITCOIN_VOTING_VERSION, true);
     280            wp_localize_script('coinsnap-bitcoin-voting-admin-script', 'coinsnap_bitcoin_voting_ajax', array(
     281                'ajax_url' => admin_url('admin-ajax.php'),
     282                'nonce'  => wp_create_nonce( 'coinsnap-ajax-nonce' ),
     283                'post' => $post_id
     284            ));
     285        }
    267286       
    268287        wp_enqueue_style('coinsnap-bitcoin-voting-admin-style', plugin_dir_url(__FILE__) . 'assets/css/admin-style.css', [], COINSNAP_BITCOIN_VOTING_VERSION);
     
    338357});
    339358
    340 function coinsnap_settings_update($data){
    341        
    342         $form_data = get_option('coinsnap_bitcoin_voting_options', []);
     359if(!function_exists('coinsnap_settings_update')){
     360    function coinsnap_settings_update($option,$data){
     361       
     362        $form_data = get_option($option, []);
    343363       
    344364        foreach($data as $key => $value){
     
    346366        }
    347367       
    348         update_option('coinsnap_bitcoin_voting_options',$form_data);
    349     }
     368        update_option($option,$form_data);
     369    }
     370}
    350371
    351372// Adding template redirect handling for voting-btcpay-settings-callback.
     
    433454                if ($hasSingleStore && $hasRequiredPermissions) {
    434455
    435                     coinsnap_settings_update([
     456                    coinsnap_settings_update('coinsnap_bitcoin_voting_options',[
    436457                        'btcpay_api_key' => $data['apiKey'],
    437458                        'btcpay_store_id' => explode(':', $btcpay_server_permissions[0])[1],
  • coinsnap-bitcoin-voting/trunk/includes/class-coinsnap-bitcoin-voting-shortcode-voting.php

    r3412858 r3461995  
    239239                </div>
    240240            </div>
    241             <div id="coinsnap-bitcoin-voting-blur-overlay<?php echo esc_html($poll_id); ?>" class="blur-overlay"></div>
     241<?php ?>
     242            <div id="coinsnap-bitcoin-voting-blur-overlay<?php echo esc_html($poll_id); ?>" class="blur-overlay coinsnap-bitcoin-voting"></div>
    242243            <?php
    243244            $this->get_template('coinsnap-bitcoin-voting-modal', [
  • coinsnap-bitcoin-voting/trunk/readme.txt

    r3438837 r3461995  
    44Tags: Lightning, bitcoin, voting, polling, BTCPay
    55Tested up to: 6.9
    6 Stable tag: 1.2.1
     6Stable tag: 1.2.3
    77License: GPL2
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    188188* Fixed Wordpress Plugin Check warnings.
    189189* Compatibility with Wordpress 6.9 is tested.
     190
     191= 1.2.2 :: 2025-02-04 =
     192* Updated interface of donor information form.
     193* Compatibility with Wordpress 6.9.1 is tested.
     194
     195= 1.2.3 :: 2025-02-15 =
     196* Update: Added order ID and all the standard fields for invoice request.
     197* Update: Added plugin isolation from other Coinsnap plugins in backend.
     198* Update: Deleted currency exchange check on frontend.
     199* Update: Added plugin isolation from other plugins in backend.
  • coinsnap-bitcoin-voting/trunk/templates/coinsnap-bitcoin-voting-modal.php

    r3300564 r3461995  
    11<?php if (!defined('ABSPATH')){ exit;} ?>
    22
    3 <div id="<?php echo esc_html($prefix); ?>qr-container<?php echo esc_html($sufix); ?>" class="qr-container" data-public-donors="<?php echo esc_attr($public_donors); ?>">
     3<div id="<?php echo esc_html($prefix); ?>qr-container<?php echo esc_html($sufix); ?>" class="qr-container coinsnap-bitcoin-voting" data-public-donors="<?php echo esc_attr($public_donors); ?>">
    44    <div class="close-popup">×</div>
    55    <div id="<?php echo esc_html($prefix); ?>public-donor-popup<?php echo esc_html($sufix); ?>" class="public-donor-popup">
    6         <h3 style="margin-bottom: 24px; font-weight: bold">Donor Information</h3>
     6       
    77        <form class="public-donor-form">
     8            <?php if ($first_name !== 'hidden' || $last_name !== 'hidden' || $email !== 'hidden'){?>
     9            <label><?php esc_html_e('Donor Information', 'coinsnap-bitcoin-voting');?></label>
     10            <div class="person-grid">
    811            <?php if ($first_name !== 'hidden'): ?>
    9                 <label for="<?php echo esc_html($prefix); ?>first-name<?php echo esc_html($sufix); ?>">First Name</label>
    10                 <input <?php echo $first_name === 'mandatory' ? 'required' : ''; ?>
    11                     type="text"
     12                <div class="person-cell">
     13                <input <?php echo $first_name === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    1214                    id="<?php echo esc_html($prefix); ?>first-name<?php echo esc_html($sufix); ?>"
    13                     placeholder="<?php echo $first_name === 'mandatory' ? 'Required' : 'Optional'; ?>">
     15                    placeholder="<?php esc_html_e('First Name', 'coinsnap-bitcoin-voting'); echo $first_name === 'mandatory' ? '*' : ''; ?>">
     16                </div>
    1417            <?php endif; ?>
    1518
    1619            <?php if ($last_name !== 'hidden'): ?>
    17                 <label for="<?php echo esc_html($prefix); ?>last-name<?php echo esc_html($sufix); ?>">Last Name</label>
    18                 <input <?php echo $last_name === 'mandatory' ? 'required' : ''; ?>
    19                     type="text"
     20                <div class="person-cell">
     21                    <input <?php echo $last_name === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    2022                    id="<?php echo esc_html($prefix); ?>last-name<?php echo esc_html($sufix); ?>"
    21                     placeholder="<?php echo $last_name === 'mandatory' ? 'Required' : 'Optional'; ?>">
     23                    placeholder="<?php esc_html_e('Last Name', 'coinsnap-bitcoin-voting'); echo $last_name === 'mandatory' ? '*' : ''; ?>">
     24                </div>
    2225            <?php endif; ?>
    2326
    2427            <?php if ($email !== 'hidden'): ?>
    25                 <label for="<?php echo esc_html($prefix); ?>donor-email<?php echo esc_html($sufix); ?>">Email</label>
    26                 <input <?php echo $email === 'mandatory' ? 'required' : ''; ?>
    27                     type="email"
     28                <div class="person-cell">
     29                <input <?php echo $email === 'mandatory' ? 'required' : ''; ?> type="email"
    2830                    id="<?php echo esc_html($prefix); ?>donor-email<?php echo esc_html($sufix); ?>"
    29                     placeholder="<?php echo $email === 'mandatory' ? 'Required' : 'Optional'; ?>">
     31                    placeholder="<?php esc_html_e('Email', 'coinsnap-bitcoin-voting'); echo $email === 'mandatory' ? '*' : ''; ?>">
     32                </div>
    3033            <?php endif; ?>
     34            </div>
     35               
     36                <?php
     37           
     38            }?>
    3139
    3240            <?php if ($address !== 'hidden'): ?>
    33                 <label>Address</label>
     41                <label><?php esc_html_e('Address', 'coinsnap-bitcoin-voting');?></label>
    3442                <div class="address-grid">
    3543                    <div class="address-row">
    36                         <input <?php echo $address === 'mandatory' ? 'required' : ''; ?>
    37                             type="text"
     44                        <div class="address-cell half">
     45                            <input <?php echo $address === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    3846                            id="<?php echo esc_html($prefix); ?>street<?php echo esc_html($sufix); ?>"
    39                             placeholder="Street"
    40                             style="width: 50%;">
    41                         <input <?php echo $address === 'mandatory' ? 'required' : ''; ?>
    42                             type="text"
     47                            placeholder="<?php esc_html_e('Street', 'coinsnap-bitcoin-voting'); echo ($address === 'mandatory')? '*' : '';?>" />
     48                        </div>
     49                        <div class="address-cell quart">
     50                        <input <?php echo $address === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    4351                            id="<?php echo esc_html($prefix); ?>house-number<?php echo esc_html($sufix); ?>"
    44                             placeholder="No."
    45                             style="width: 24%;">
    46                         <input <?php echo $address === 'mandatory' ? 'required' : ''; ?>
    47                             type="text"
     52                            placeholder="<?php esc_html_e('No.', 'coinsnap-bitcoin-voting'); echo ($address === 'mandatory')? '*' : '';?>" />
     53                        </div>
     54                        <div class="address-cell quart">
     55                        <input <?php echo $address === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    4856                            id="<?php echo esc_html($prefix); ?>postal<?php echo esc_html($sufix); ?>"
    49                             placeholder="ZIP"
    50                             style="width: 26%;">
    51 
     57                            placeholder="<?php esc_html_e('ZIP', 'coinsnap-bitcoin-voting'); echo ($address === 'mandatory')? '*' : '';?>" />
     58                        </div>
    5259                    </div>
    5360                    <div class="address-row">
    54                         <input <?php echo $address === 'mandatory' ? 'required' : ''; ?>
     61                        <div class="address-cell half">
     62                        <input <?php echo $address === 'mandatory' ? 'required="required"' : ''; ?>
    5563                            type="text"
    5664                            id="<?php echo esc_html($prefix); ?>town<?php echo esc_html($sufix); ?>"
    57                             placeholder="Town"
    58                             style="width: 50%;">
    59                         <input <?php echo $address === 'mandatory' ? 'required' : ''; ?>
    60                             type="text"
     65                            placeholder="<?php esc_html_e('Town', 'coinsnap-bitcoin-voting'); echo ($address === 'mandatory')? '*' : '';?>" />
     66                        </div>
     67                        <div class="address-cell half">
     68                        <input <?php echo $address === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    6169                            id="<?php echo esc_html($prefix); ?>country<?php echo esc_html($sufix); ?>"
    62                             placeholder="Country"
    63                             style="width: 50%;">
     70                            placeholder="<?php esc_html_e('Country', 'coinsnap-bitcoin-voting'); echo ($address === 'mandatory')? '*' : '';?>" />
     71                        </div>
    6472                    </div>
    6573                </div>
    6674            <?php endif; ?>
    67 
    68             <?php if ($custom !== 'hidden'): ?>
    69                 <label id="<?php echo esc_html($prefix); ?>custom-name<?php echo esc_html($sufix); ?>" for="<?php echo esc_html($prefix); ?>custom<?php echo esc_html($sufix); ?>"><?php echo esc_html($custom_name); ?></label>
    70                 <input <?php echo $custom === 'mandatory' ? 'required' : ''; ?>
    71                     type="text"
     75               
     76        <?php if ($custom !== 'hidden'): ?>
     77                <label for="<?php echo esc_html($prefix); ?>custom<?php echo esc_html($sufix); ?>"><?php echo esc_html($custom_name);?></label>
     78                <input <?php echo $custom === 'mandatory' ? 'required="required"' : ''; ?> type="text"
    7279                    id="<?php echo esc_html($prefix); ?>custom<?php echo esc_html($sufix); ?>"
    73                     placeholder="<?php echo $custom === 'mandatory' ? 'Required' : 'Optional'; ?>">
    74             <?php endif; ?>
    75             <button type="submit" id="<?php echo esc_html($prefix); ?>public-donors-pay<?php echo esc_html($sufix); ?>">Pay</button>
     80                    placeholder="<?php echo esc_html($custom_name); echo ($custom === 'mandatory')? '*' : '';?>">
     81        <?php endif; ?>
     82            <button type="submit" id="<?php echo esc_html($prefix); ?>public-donors-pay<?php echo esc_html($sufix); ?>"><?php esc_html_e('Pay with Bitcoin', 'coinsnap-bitcoin-voting');?></button>
    7683        </form>
    7784    </div>
     
    9097            <div class="qr-address-wrapper" id="<?php echo esc_html($prefix); ?>lightning-wrapper<?php echo esc_html($sufix); ?>" style="display: none; margin-top:8px">
    9198                <div class="qr-address-title">
    92                     Lightning:
     99                    <?php esc_html_e('Lightning', 'coinsnap-bitcoin-voting');?>:
    93100                </div>
    94101                <div id="<?php echo esc_html($prefix); ?>qr-lightning-container<?php echo esc_html($sufix); ?>" style="display: none;" class="qr-lightning-container">
     
    102109            <div id="<?php echo esc_html($prefix); ?>btc-wrapper<?php echo esc_html($sufix); ?>" style="display: none; margin-top:12px" class="qr-address-wrapper">
    103110                <div class="qr-address-title">
    104                     Address:
     111                    <?php esc_html_e('Address', 'coinsnap-bitcoin-voting');?>:
    105112                </div>
    106113                <div id="<?php echo esc_html($prefix); ?>qr-btc-container<?php echo esc_html($sufix); ?>" style="display: none;" class="qr-lightning-container">
     
    113120            </div>
    114121        </details>
    115         <a id="<?php echo esc_html($prefix);?>pay-in-wallet<?php echo esc_html($sufix);?>" class="qr-pay-in-wallet"><?php echo esc_html__('Pay in wallet','coinsnap-bitcoin-voting'); ?></a>
     122        <a id="<?php echo esc_html($prefix);?>pay-in-wallet<?php echo esc_html($sufix);?>" class="qr-pay-in-wallet"><?php esc_html_e('Pay in wallet','coinsnap-bitcoin-voting'); ?></a>
    116123    </div>
    117124    <div id="<?php echo esc_html($prefix); ?>thank-you-popup<?php echo esc_html($sufix); ?>" class="thank-you-popup">
Note: See TracChangeset for help on using the changeset viewer.