Binance API - Account has insufficient balance for requested action - php

While trying to place an order, I'm receiving the following error:
Code: -2010 Account has insufficient balance for requested action
I'm requesting the POST endpoint https://api.binance.com/api/v3/order with the following parameters:
$params =
[
'symbol' => 'BTCUSDT',
'side' => 'BUY',
'type' => 'MARKET',
'quoteOrderQty' => 375.00,
'timestamp' => $timestamp,
];
And I just deposit 400$, which means I have enough funds to purchase 375$ worth of BTC.
What am I missing?

I have had this before numerous times and this is why it happens.
Say you have 0.007821 worth of BTC in your Binance Wallet. And you are trying to place a SELL order. Now, if you end up rounding your quantity to say 4 decimal places, your code would try and SELL 0.0079 BTC. This is obviously more than what you have in your Exchange Wallet. This will cause the "Account has insufficient balance for requested action" error.
Solution: Simply match or reduce the amount in your code that you are trying to SELL to match the amount in your exchange Wallet. So, in this case, try and use the correct rounding decimal places or try to SELL 0.0078 worth of BTC.

I suggest you find your money and convert it to USDT if you want. Check this page using your browser https://binance.com/en/my/wallet/account/main and find what currency do you have now. Keep in mind that USD != USDT

The other option is to make sure you have enough BNB in your account to pay for the fees:
https://dev.binance.vision/t/account-has-insufficient-balance-for-requested-action/2718/6

It is because you are trying to buy 375.00 bitcoin.
quoteOrderQty must reference to the amount of symbol you want to buy.
if you want to buy btc for a percentage of your total money you should use this formula: (YourTotalMoney / CurrentPrice) * (Percentage / 100)
Example: I want to buy BTC using 50% of my USDT
Quantity = (getBalanceUSDT() / getCurrentPriceBTC()) * (50 / 100)
getBalanceUSDT() and getCurrentPriceBTC() are functions you will have to create
Now you can use Quantity for the quoteOrderQty param.

Related

Stripe's fees on the application side with a subscription, trying to make an update on the invoice but its too fast

I'm creating a stripe subscription with the following code:
$subscription = $stripe->subscriptions->create([
'customer' => {{CUSTOMER ID}},
'items' => [
[
'price' => $price->id,
'quantity' => $quantity,
],
],
'default_source' => $card,
'billing_cycle_anchor'=> $time,
'proration_behavior' => 'create_prorations',
'transfer_data' => [
'destination'=>{{DESTINATION ID}}
]
]);
Everything works out fine, but there is an issue. The fees fall on the platform's side and here's the dilemma through a realistic outcome:
Customer is charged 0.40 cents. Stripe's fee is 2.9% + 30 cents (.31 cents) and the platform we operate takes 2.5% (.01 cents). As the fee falls on us as the platform, we don't have the money because of the percentage we take. So the solution is to "charge" the connected account for both our take and the credit card processing fee (meaning 2.5% + 2.9% + 30 cents).
The issue here is that we can't use the application_fee_percent because that's purely a percentage (it will ignore the 30 cents - plus this can't be calculated from a percentage basis because prorations are enabled).
I have tried listening to the webhook of invoice.created so that I can calculate the application_fee_amount dynamically but it says "Cannot change finalized invoice." So the question becomes, what's the proper flow here? What am I missing to fix this issue we're having?
Invoices created for less than the minimum amount for the currency do not actually make a charge, and instead just affect the Customer Balance: https://stripe.com/docs/billing/customer/balance#examples
Ok, so I figured it out.
As per the documentation here: https://stripe.com/docs/billing/invoices/subscription
This explains that the first invoice on creating the subscription is created and finalized immediately (you cannot change it), while the next invoice in the billing cycle sits in "draft" for an hour. During that time, you can modify that invoice however you please during that hour. This means I have to figure out a different approach to gathering fees.

Stripe Partial refund and full refund issue

Here is what i am trying to do. Total is $120
1 : First i did a Partial Refund with this charge ID ch_1AfNOwAWa9KSz110***** .
\Stripe\Refund::create(array(
"charge" => 'ch_1AfNOwAWa9KSz*******',
"amount" => 60 * 100,
));
2 : After that i want to refund full the amount that left in this chargeID ch_1AfNOwAWa9KSz110*********
\Stripe\Refund::create(array(
"charge" => 'ch_1AfNOwAWa9KSz1********'
));
I am getting error Charge ch_1AfNOwAWa9KSz110********* has already been refunded.
What should i do first i did partial and after full refund in stripe.?
According to the docs:
You can optionally refund only part of a charge. You can do so
multiple times, until the entire charge has been refunded.
So it seems you can create a refund without an amount (a full refund) only if you have not refunded already (partially), otherwise you need to specify the amount explicitly.
It would be great, though, if Stripe accepted refunding without an amount specified even after a partial refund, meaning to refund the remaining amount.
Based on the docs, I think you want to use the update refund endpoint instead of the create refund endpoint for the second call.

Subtract until zero

Okay so let's say I have
A balance of $6.00 created from a credit.
An invoice of $12.00 created by an admin.
You subtract the invoice amount from the balance and get a total of $-6.00
How would you subtract the two until you reach $0.00 to figure out the amount taken from the balance to pay the invoice.
So you would get that the balance paid for was a total of $6.00 and the client still owes $6.00
My PHP code is as follows for this predicament!
if($balance >= $due)
{
$amount = $due;
}
else
{
$amount = $due - $balance;
}
if($balance > '0')
{
$data = array(
'invoice_id' => $invoice_id,
'balance_pay' => '1',
'amount' =>
);
$this->payment->create($data);
}
UPDATE
I'm just trying to figure out how much is still owed on the invoice. If I don't figure this out, because of how my application is set-up, it will display that the total invoice was paid when really only half of it was paid.
This is a VERY simple problem, that has needlessly been complicated, which often happens. Just need to take a step back rather than getting deeper into the problem (if that is even possible) and further complicatingn the issue.
Firstly, you don't have to subtract to reach $0.00.
In the most general case, the amount of current credit balance could be negative (customer currently owes you money), 0 (customer does not owe you any money currently), or positive (you currently owe customer money). But the actual calculation is the same in all three cases. Let the current credit balance for the customer be x.
Now you wish to generate an invoice. Let this invoice amount be y. (I assume that y will always be positive, but doesn't really matter.)
Then, z = x - y is the new credit balance for the customer:
If z < 0: customer did not have enough credit balance to pay off the new invoice. Customer still needs to pay z.
If z = 0: customer had just enough credit balance to completely pay off the new invoice, and the new credit balance is 0.
If z > 0: customer had more than enough credit to pay off the new invoice, and the new credit balance is z.
It's just straightforward addition/subtraction, needlessly complicated in your head by credit/debit/plus/minus signs, with the added confusion resulting from wanting to balance to zero when you really don't have to.

PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts

I got an above error when place an order with other than base currency. My store base currency is USD.If i place an order with "GBP" or "INR" or else currency, I got an error like
PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts (#10413: Transaction refused because of an invalid argument. See additional error messages for details).
I have searched google. Most of the forum said, it may be a rounding issue! But it was working well still now.Today only i got an error like this. And also they got an error with all currency. But for me its only showing other than base currency
EDIT:
[ITEMAMT] => 239.00
[TAXAMT] => 0.00
[SHIPPINGAMT] => 0.00
[L_NUMBER0] => 8sa-N7407
[L_NAME0] => Pink & Gold Velvet, Net Party Wear Sarees
[L_QTY0] => 1
[L_AMT0] => 239.00 )
Request result from checkout page
Anybody have an idea to uplift me from this issue? Thanks in advance
I just put a wrong condition on my custom module. So it called core files. So only it didn't work other than base currency
if(Mage::helper('paypalmulticurrency')->isActive()){
return parent::_render();
}
From above if condition, I set if its being active, call parent method. But I want like,
If it isn't being active only, call parent method. Just changed the if condition, its working well now!
if(!Mage::helper('paypalmulticurrency')->isActive()){
return parent::_render();
}

Creating a Stripe Summary Report

I've recently switched payment processing to Stripe. I now need to create a report for our finance department that shows a rollup of transactions within a specified date range. I've started to create a simple PHP web page (and using the Stripe PHP library) that will give the following summaries:
Transaction Count
Transaction Amount
Refund Count
Refund Amount
Fees
Net
I'm having some trouble figuring out how to properly query charges with Stripe for my reporting purposes.
I know I can retrieve charges with:
$charges = Stripe_Charge::all();
And from the returned set of charges, I can compute the summary information that I need in the report. However, this will only return me a maximum of 100 charges, and I don't know how to return the charges within a specified date range.
I'm hoping more experienced Stripe developers can point me to the correct method of building the report I need.
How can I return all charges within a specified date range?
Is there a better way to get this summary information from Stripe?
You could use webhooks to be notified when a charge.succeeded or charge.refunded event occurs and store the relevant information in a database you control. That will give you flexibility to do the reporting you need. You can download charges that have already occurred as a CSV from the Stripe dashboard.
You can paginate through the charges by using the count and offset parameters (documented at https://stripe.com/docs/api?lang=php#list_charges). I would suggest using these to process 100 charges at a time. Then you can stop iterating through your charges once you get a charge beyond your date range.
I received confirmation from a Stripe employee that the only two options are in fact the ones described in the answers from #dwhalen and #Saikat Chakrabarti.
Quoting from the Stripe employee to the same question I asked on Stripe:
Other than the options you described (retrieving all charges, or
tracking in your database as charges come in) there isn't any
alternative way of producing the stats that you want there.
Realize this is old-ish, but.. this is now possible, a php example:
$charges=Stripe_Charge::all(array("created" => array("gt" => $unix_time),"limit" => 100));
You can use offset like
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 0)); // set count
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 100)); // set count
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 200)); // set count

Categories