I reply to all queries on the forums and via email, once per day, Monday to Friday (not weekends).

If you are new here, please see some information on how to ask for support. Thank you!

examples of withdraw php-api

dashed-slug.net Forums General discussion examples of withdraw php-api

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #6105
    Anonymous
    Inactive

    I have been searching and searching for a way to set up just a redeem or withdrawal button.

    I just want to have a page that will have a form of how much they want to withdraw and click withdrawal or redeem, and a page that says thanks

    do you have a php example of how i would set up this Redeem?

    or send me the file that does it now, so i can see how it is done… i just cant wrap my head around this in the docs,

    https://wallets-phpdoc.dashed-slug.net/classes/Dashed_Slug_Wallets_PHP_API.html#method_api_withdraw_action

    it can be json api im not that particular but im overwhelmed and need some “visual” example(s) to get this working

    #6106
    Anonymous
    Inactive

    been digging thru this:

    plugins/wallets/includes/views/withdraw/default.php

    i would use the info here:

    How can I set default withdrawal address

    to set up as a template and do shortcode example [wallets_withdraw template=”toadmin”]

    #6107
    Anonymous
    Inactive

    not knowing knockout.js i do not want to mess anything up.

    what can i delete? im worried about screwing something up if i delet any of this, but it would be a hidden “withdraw address”

    #6108
    Anonymous
    Inactive

    it wonrt let me post the code from

    plugins/wallets/includes/views/withdraw/default.php

    keeps showing word fence

    so will show in pastebin

    https://pastebin.com/b82niK4b

    #6109
    Anonymous
    Inactive

    infact i do not need anything but “Amount” and “send” “reset form” and then the confirmation page that normally happens after you withdraw

    #6110
    alexg
    Keymaster

    Hello,

    Do not attempt to edit the plugin code. To see why, check the FAQ under “I want to do changes to the plugin’s code.” If you wanted to provide alternative knockout templates, you’d use the wallets_views_dir filter to specify another directory on your server where you could copy and modify all the knockout views. However, there is no need to do all this in your case:

    Instead, design your own HTML form in any way you like. Then, make it so that when it is submitted, you use JavaScript to call the JSON API yourself. The JSON API is documented in the accompanying PDF documentation, under APIs -> Wallets JSON API -> Withdraw funds to an external address. To see how the plugin does the calls: https://github.com/dashed-slug/wallets/blob/4.2.0/assets/scripts/wallets-ko.js#L717-L753

    Just make sure to pass the correct fields to the call, and you will get a JSON response indicating success/failure. For the _wpnonce field, just pass the value of wp.wallets.viewModels.wallets.nonces()['do_withdraw']

    Please let me know if you need any help with any of this.

    with regards

    #6112
    Anonymous
    Inactive

    Yes the docs are overwhelming to me and I thought I was just making a new knockout template minus everything but amount and send and reset buttons

    Can u provide a working sample as I tried for like 3 days b4 even posting here. I’m a visual learner when I start going thru docs I just get overwhelmed and lost more . A simple example I can build off would help so much

    #6115
    alexg
    Keymaster

    It would be hard to achieve what you ask with knockout templates, this is why I suggested using a standard HTML form and some simple JavaScript.

    The JSON API call, using jQuery would be:

    $.ajax({
    	dataType: 'json',
    	data: {
    		'__wallets_apiversion' : 3
    		'__wallets_action' : 'do_withdraw',
    		'__wallets_withdraw_address' : address,
    		'__wallets_symbol' : symbol,
    		'__wallets_withdraw_amount' : amount,
    		'__wallets_withdraw_comment' : comment,
    		'__wallets_withdraw_extra' : extra,
    		'_wpnonce' : wp.wallets.viewModels.wallets.nonces()['do_withdraw']
    	},
    	success: function( response ) {
    
    		$( form ).trigger( 'wallets_do_withdraw', [
    			response,
    			symbol,
    			amount,
    			address,
    			comment,
    			extra
    		] );
    
    	error: function() {
    		alert( 'Withdrawal not submitted' );
    	}
    });

    Just make sure to attach this to whatever button your form has, and pass the variables in from the form.

    Hope this is a bit more clear. The rest is just standard html/javascript.

    with regards

    #6217
    Anonymous
    Inactive

    No matter what i try to do to create this form its is not working

    “wp.wallets.viewModels.wallets.nonces()[‘do_withdraw’]” is tossing up errors

    https://prntscr.com/ndhaai

    so frustrating 🙁

    Ajax forms in WordPress are very different

    can you post a working example please? i have spent days trying to get this to work and nothing is working

    #6219
    Anonymous
    Inactive

    Ok so i got this working !!

    for anyone needing similar here is my example PLEASE KEEP IN MIND this was for move but can be changed to Withdrawal very easy

    <?php
    // ====   Change to your coin symbol  =====
    
    $symbol ="ODAC";
    
    // ==================================
    
    $current_user = wp_get_current_user();
    $user_ID = $current_user->ID;
    
    //  available to spend in wallet
    $my_balance = apply_filters( 'wallets_api_available_balance', 0, array(
         'symbol' => $symbol,
         'user_id' => $user_ID,
     ) );
    
    //  we used floor here as we wanted whole Coins  you can just replace "$my_balance"
    echo  'Hello ' . ucfirst($current_user->user_login) . '<br> Your Availabe Balance to transfer is: <br> <strong>' . floor($my_balance). ' ' .$symbol. '</strong><br /><br />';
    
    ?>
    
    <form class="send2bank" action="#" method="get">
        <input id="amount" name="amount" type="text" class="field text medium" value="" maxlength="255" tabindex="1" />
        <input type="submit" id="my_submit" name="my_submit" value="submit"/>
    </form>
    
    <!--Javascript goes here -->
    
    <script type="text/javascript" >
    
    jQuery(document).ready(function($) {
    
    	$('.send2bank').on('click', '#my_submit', function(e) {
    
    		e.preventDefault();
    		var form = e.delegateTarget;
    		var amount = document.getElementById("amount").value;
    		var user = "Central Bank";
    		var comment = "Exchanged to Bank"
    		var nonce = wp.wallets.viewModels.wallets.nonces()['do_move'];
    		var symbol ="<?php echo $symbol; ?>";
    
    		if(amount==""){
    			
    			alert('its empty: ');
    
    			$('.success').fadeOut(200).hide();
    			$('.error').fadeOut(200).show();
    
    			} else {
    
    				if (true) {
    					alert('this is the amount: ' + amount);
    
    					//form.submit();
    
    					$.ajax({
    						dataType: 'json',
    						cache: false,
    						data: {
    							'__wallets_apiversion' : 3,
    							'__wallets_action' : 'do_move',
    							'__wallets_move_toaccount' : user,
    							'__wallets_move_amount' : amount,
    							'__wallets_move_comment' : comment,
    							'__wallets_symbol' : symbol,
    							'_wpnonce' : nonce
    						},
    						success: function( response ) {
    							$( form ).trigger( 'wallets_do_move', [
    								response,
    								symbol,
    								amount,
    								user,
    								comment
    							] );
    						}
    					});
    			}
    	  }  
       })
    });
    </script>
    #6220
    Anonymous
    Inactive

    https://pastebin.com/XKBKshBp

    for ppl that have issue copying and pasting from the forum

    #6221
    Anonymous
    Inactive

    updated to add some alerts

    1.) only whole numbers in input box
    NOTE: you can take that out just delete this code
    onkeypress="return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13) ? null : event.charCode >= 48 && event.charCode <= 57"
    2.) no copy and paste in input box
    3.) no auto complete in input box

    https://pastebin.com/8xKzfQgt

    i will prob add some different alerts and maybe decimals but for now we only want/need whole number transfers

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.