Assuming I have stored in the database the following
withdraw fee = 2
then upon withdrawing money i want the user to pay 2% for withdrawal fees for any amount he/she is receiving. Given the code below, it only deducts $2 instead of deducting %2 of the balance.
In my code, $postd_cashout is the fees to pay,
balance is the user's balance
What change should I make to this line for this to work
$postd_cashout = substr(number_format($ir['balance'], 3, '.', ','), 0, -1);
$postd_cashout = ($ir['balance']*(1.02));
This results in a gross withdrawal of the intended amount plus 2% of that amount. I am unclear if this is exactly what you are trying to achieve, however. The amount the withdrawee receives in hand would be represented in $ir['balance'] whereas the gross amount withdrawn is reflected in $postd_cashout.
optionally:
$withdrawalmultiplier = 1.02;
$postd_cashout = ($ir['balance']*($withdrawalmultiplier));
This allows you to change the fee amount anywhere it is referenced in the code as opposed to hardcoding a static number. the intial example is more clear, imho.
finally:
$fee = ($postd_cashout - $ir['balance'])
I suppose tracking the fee amount is useful for reporting a sum of fees paid or itemizing a receipt and it sounds like this is ultimately what you're wanting after re-reading the question a few times. If the fee amount is all you're after then the other answer fits more elegantly.
Just multiply the balance by the withdrawal fee as a percentage
$fees = ($ir['balance'] * $withdrawal_fee / 100);
You can then utilise $fees in your calculation.
Don't use number_format before the calculation as you want to avoid the commas - that converts the value to a string.
Related
I have a problem in reverting the original amount of a customer.
A customer can amortize its balance in 3 months.
So, if the balance is 1,100.00
1,100.00 / 3 = 366.666666667 rounded up to 366.67
But then, he decided to cancel the amortization.
What I do is amortized amount * 3, which is:
366.67 * 3 = 1,100.01
Expected output should be 1,100.00
Thanks!
Your problem here is the original calculation, if you have 1,100.00 to pay and simply divide by 3 with rounding, your customer will actually pay 1,100.01!
The usual solution is to compensate this difference in the last (or first) amount to pay:
n-1 first payments: total / n -> for your example: 2 times 366.67
last payment: total - sum of precedent payments -> for your example: 1,100.00 - (2 * 366.67) so 366.66 to pay
Like this the total paid will always be right, whatever you apply flooring or rounding, and you can reverse any time by adding each value.
Save the original value 1,100.00 somewhere (database, variable, etc.) and when they cancel their amortization, set the display from the saved value instead of calculating it.
If we are using 100% discount voucher code and price gets 0 and needs to be processed via Stripe how can we do it? Or via subscriptions that are free how to do it?
The minimum value for a charge is $0.50 USD. If the invoice has an amount smaller than this, it will not create a charge, but rather add that as a "debt" on the customer for the next invoice.
amount A positive integer in the smallest currency unit (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency) representing how much to charge. The minimum amount is $0.50 US or equivalent in charge currency.
From Stripe API Reference.
Right now, I am using GetOrders to launch all my orders to my database. Normally, it works fine. I can get the total amount(includes item price and tax) by using:
$totalAmount = $order->AmountPaid;
However, when I tried to import an International Order, the amount was wrong.
The thing is: I only charged him $102.90, but the amount here gives me $157.62
Does anyone know how can I get the total price, which under the "Total" column, in eBay? What kind of value I need to use? Or maybe how to calculate the price for international order?
There few fields related to order price
OrderArray.Order.AmountPaid
This value indicates the total amount of the order. This amount includes the sale price of each line item, shipping and handling charges, shipping insurance (if offered and selected by the buyer), additional services, and any applied sales tax. This value is returned after the buyer has completed checkout (the CheckoutStatus.Status output field reads 'Complete').
OrderArray.Order.Total
The Total amount equals the Subtotal value plus the shipping/handling, shipping insurance, and sales tax costs.
OrderArray.Order.Subtotal
The subtotal amount for the order is the total cost of all order line items. This value does not include any shipping/handling, shipping insurance, or sales tax costs.
I would suggest you try Order.Total for receive price of the order.
I'm using Paypal to process payments.
The subtotal (without taxes) for the purchase is 132.94$. My customers are in Canada and I need to multiply a tax percent to that subtotal in order to get the real total.
The tax percent is 1.14975, but Paypal doesn't accept a tax percent with more than two decimals, so it rounds it to 1.15.
Here's the code that I use to setup the payment :
// Not shown- create an ItemList, add Item's to it
// ...
$details = new Details;
$details->setSubtotal(132.94);
$details->setTax(1.14975);
$amount = new Amount;
$amount->setCurrency('CAD');
$amount->setTotal(152.88); // 132.94 * 1.15
$amount->setDetails($details);
// ...
// Not shown - create the transaction, try to create the payment
However, when I try to send the information to Paypal, I get this error :
Transaction amount details (subtotal, tax, shipping) must add up to specified amount total
I tried dumping out $amount to see what it contains, and here's what I see :
Why does it tell me that the details don't add up to the amount? Am I missing something here? If I multiply the subtotal by the tax, I get the total for the amount, they do match up.
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.