dashed-slug.net › Forums › General discussion › examples of withdraw php-api › Reply To: examples of withdraw php-api
April 18, 2019 at 3:55 am
#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>