dashed-slug.net › Forums › General discussion › examples of withdraw php-api
- This topic has 11 replies, 2 voices, and was last updated 5 years, 4 months ago by
Anonymous.
-
AuthorPosts
-
April 9, 2019 at 12:46 am #6105
Anonymous
InactiveI 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,
it can be json api im not that particular but im overwhelmed and need some “visual” example(s) to get this working
April 9, 2019 at 4:49 am #6106Anonymous
Inactivebeen digging thru this:
plugins/wallets/includes/views/withdraw/default.php
i would use the info here:
to set up as a template and do shortcode example [wallets_withdraw template=”toadmin”]
April 9, 2019 at 4:50 am #6107Anonymous
Inactivenot 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”
April 9, 2019 at 4:54 am #6108Anonymous
Inactiveit wonrt let me post the code from
plugins/wallets/includes/views/withdraw/default.php
keeps showing word fence
so will show in pastebin
April 9, 2019 at 5:06 am #6109Anonymous
Inactiveinfact i do not need anything but “Amount” and “send” “reset form” and then the confirmation page that normally happens after you withdraw
April 9, 2019 at 3:16 pm #6110alexg
KeymasterHello,
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 ofwp.wallets.viewModels.wallets.nonces()['do_withdraw']
Please let me know if you need any help with any of this.
with regards
April 9, 2019 at 5:24 pm #6112Anonymous
InactiveYes 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
April 10, 2019 at 9:04 am #6115alexg
KeymasterIt 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
April 18, 2019 at 2:24 am #6217Anonymous
InactiveNo 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
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
April 18, 2019 at 3:55 am #6219Anonymous
InactiveOk 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>
April 18, 2019 at 3:57 am #6220Anonymous
Inactivefor ppl that have issue copying and pasting from the forum
April 18, 2019 at 5:43 am #6221Anonymous
Inactiveupdated 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 boxi will prob add some different alerts and maybe decimals but for now we only want/need whole number transfers
-
AuthorPosts
- You must be logged in to reply to this topic.