paypal Adaptive payment issue- fractional amount is rounded off - paypal

i have integrated paypal adaptive payment system in a website, but i get an error while i checkout that if the amount upto 2 decimal places is not rounded off, the fractional amount could be lost. what is the solution to this? I am currently rounding off the amounts, but any idea how to get the fractional amount too?

You have to make sure that the amount you're sending to PayPal is rounded properly for the currency. This means that a US dollar amount would have at most 2 subunits (cents).
If using the adaptive pay ruby gems and still experiencing issues:
Another issue that I recently ran into with their ruby gems is that they use floats instead of decimals, which is a bad practice for monetary values. Floats are inaccurate. For example in ruby...
2.20 - 2.01 = 0.1900000000000004
If you're properly setting the amount's subunits when passing in the param to their build_pay method and you're still getting the error...
If the fractional amount is rounded for currency conversion, funds could be lost
then the issue may very well be within their gem's use of float. Your logs will show this, and you can test it by using the amount 715.57, which their gem sends to their api as 715.57000000001 because of their use of .to_f in their paypal-sdk-core gem.
To fix this, I monkey patched their Float class in my rails app by adding this to my app, essentially casting it as a BigDecimal instead of a Float:
module PayPal::SDK::Core
module API
module DataTypes
module SimpleTypes
class Float < ::Float
def self.new(float)
# Floats are inccurate. BigDecimal is better.
# Ruby example: 2.20 - 2.01 = 0.1900000000000004
# To support currencies with up to 4 subunits, we round(4)
BigDecimal.new(float.to_f.round(4).to_s)
end
end
end
end
end
end
to my config/initializers/paypal.rb. I can't say this is the most elegant solution, but it works. I created an issue on their repo too, and can hopefully hear back soon.
More info on float problems with currency:
Reference 1: https://stackoverflow.com/a/3730040/1109211
Reference 2: https://stackoverflow.com/a/3730249/1109211

If you are using PHP you can apply this solution. It is working in my case
$amount = 50.4854;
$roundedAmount = number_format(round($amount, 2), 2, '.', '');
Send rounded amount to PayPal, Hope it will work!

Related

Cannot properly array googlefinance formula with dates

I am trying to convert money amounts in USD to EUR, but I want to do it in relation to date of transaction taking place due to dyncamic exchange rates.
Idea is to use googlefinance function with index function, along with date function, which will be made of right, mid, and left functions. All of that should be wrapped with arrayformula. Numbers should be rounded using round.
Non-working example:
Don't mind ;, this is instead of , in my google sheets language settings.
Formula: =ARRAYFORMULA(IF(B2:B="";"";ROUND(INDEX(B2:B*GOOGLEFINANCE("CURRENCY:USDEUR";"price";DATE(RIGHT(A2:A;4);MID(A2:A;4;2);LEFT(A2:A;2)));2;2);2)))
Formula (with , instead of ;):
=ARRAYFORMULA(IF(B2:B="","",ROUND(INDEX(B2:B*GOOGLEFINANCE("CURRENCY:USDEUR","price",DATE(RIGHT(A2:A,4),MID(A2:A,4,2),LEFT(A2:A,2))),2,2),2)))
Since I'm pretty sure this formula should work in "normal circumstances", I've replicated it leaving out arrayformula, and full ranges (such as B2:B, etc), and it works once I drag down the formula.
Working example:
Formula: =IF(F2="";"";ROUND(INDEX(F2*GOOGLEFINANCE("CURRENCY:USDEUR";"price";DATE(RIGHT(E2;4);MID(E2;4;2);LEFT(E2;2)));2;2);2))
Formula (with , instead of ;):
=IF(F2="","",ROUND(INDEX(F2*GOOGLEFINANCE("CURRENCY:USDEUR","price",DATE(RIGHT(E2,4),MID(E2,4,2),LEFT(E2,2))),2,2),2))
Does anyone have idea what's going on with the first case, i.e. why it doesn't work? I believe it has to be something with those full ranges (e.g. B2:B, A2:B, etc), but not sure why...
GOOGLEFINANCE is already an ARRAYFORMULA type formula so try like this:
=ARRAYFORMULA(IF(B2:B="";;ROUND(B2:B*IFNA(VLOOKUP(A2:A+0,9986111111;
GOOGLEFINANCE("CURRENCY:USDEUR"; "price"; MIN(A2:A); MAX(A2:A)+1); 2; 1)); 2)))

How to get nifty and sensex data using Alpha Vantage api key

Is possible to get nifty 50 data using Alpha Vantage?
Also the current price of gold?
As of now, Alpha Vantage only has 100% support for US ETFs, so to get NIFTY data you can download the 50 tickers, you can download the list here, and then make a call to each ticker.
Yes, use the CURRENCY_EXCHANGE_RATE function, and "from_currency=XAU" parameter. XAU is the symbol for gold.
Example:
https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=XAU&to_currency=USD&apikey=KEY_HERE

Alpha Vantage error when symbol has digits

I'm trying to get quotes for an Australian stock with ticker A200.AX (aka A200.AUS) from Alpha Vantage.
I have no issues getting other symbols from the AX market, e.g.:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=ETHI.AUS&apikey=demo
...returns data as expected
However when a symbol has digit(s) in it, it seems to return an error:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=A200.AUS&apikey=demo
Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for TIME_SERIES_INTRADAY.
Same result for F100.AUS
I checked to make sure the ticker was valid: A200.AUS shows up if I search for it:
https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=A200.AUS&apikey=demo
I'm aware of some questions related to URL encoding, but I can't see any URL special characters in A200.AUS . Besides, using the search endpoint works with the ticker passed on literally.
Does anyone know how to download this stock's information or what I'm doing wrong?
Your use of the search endpoint is great, however A200.AUS is an ETF. Alpha Vantage has some ETFs, but currently, only 100% supports stocks.

Retrieve Bloomberg Historical Data - API

From the below code, I was attempting to retrieve 250 observations rather than 177. The gap is due to the fact that the call only considers trading days which is fine to me.
s='SX5E INDEX';
f='LAST_PRICE'
t= datestr(today()-250,'mm/dd/yy');
T= datestr(today(),'mm/dd/yy');
[dt,~]=history(con,s,f,t,T)
However, is there a way of retrieving the last 250 observations from today(), whatever the starting date t is ?
Best
EDIT
#Daniel : Based on your suggestion, and Going forward with while loop, I've ended up with the below way around which is free from any Matlab default calendar setting. Thanks
while l~=p
n=p-l;
t=t-n;
[dt,~]=history(con,s,f,t,T);
l=length(dt);
end
Maybe my idea to use isbusday wasn't well explained in the comments. Here is what I would try:
n=250;
m=n;
while(sum(isbusday(today()-n:today()))<m)
missing=m-sum(isbusday(today()-n:today()));
n=n+missing;
end
Count the number of missing days, add the missing days and check again (in case you added a holiday)
You should end up with n the total number of days you have to query.
(Lacking the toolbox, I was unable to test the code)

Is UUID random enought for password recovery link?

Does Data::UUID generates secure and random sequences? Is it ok to use it to generate password recovery link?
For example:
use Data::UUID;
my $u = Data::UUID->new;
my $uuid = $u->create_from_name_str(NameSpace_URL, 'www.example.com');
#then add $uuid to db
#and send email to user
Personally I'd use UUID::Tiny because that's capable of generating version 4 UUIDs, which are more random. However, in either case the modules are just using Perl's rand function which isn't considered random enough for serious crypto work.
Still, this is likely to be random enough for a typical password-recovery e-mail. Especially if the password recovery link is only kept working for, say, 24 hours and stops working after that.
It really depends on what you're securing though. Is it a forum for posting pictures of your pets dressed in superhero costumes, or is it nuclear launch codes? If you think that your website is likely to be a target for criminal elements, then it might be wise to opt for something stronger.
A fairly good random string with low collision probability can be generated using:
use Crypt::PRNG;
my $string = sprintf(
q/%08x%s/,
time(),
Crypt::PRNG->new->bytes_hex(24),
);
Data::UUID can generate either version 1 (create) or version 3 (create_from_name) UUIDs. Neither of those is random. Version 1 is your MAC address plus a timestamp, and version 3 is a MD5 hash of the string you passed in.