I wanted the payment to be like 1$ for first month and 5$/month for 5 years or specific period .
So, I tried "CreateRecurringPaymentsProfile"
$fields['method']='CreateRecurringPaymentsProfile';
$fields['USER'] = Configuration::get('PAYPAL_API_USER');
$fields['PWD'] = Configuration::get('PAYPAL_API_PASSWORD');
$fields['SIGNATURE'] = Configuration::get('PAYPAL_API_SIGNATURE');
$fields['VERSION']=56;
$fields['PROFILESTARTDATE']='2015-10-20T00:00:00Z';
$fields['DESC']="xxx";
$fields['BILLINGPERIOD']='Month';
$fields['BILLINGFREQUENCY']=1;
$fields['TOTALBILLINGCYCLES']=12;
$fields['AMT']=5;
$fields['TRIALBILLINGPERIOD']='Month';
$fields['TRIALBILLINGFREQUENCY']=1;
$fields['TRIALTOTALBILLINGCYCLES']=1;
$fields['TRIALAMT']=1;
$fields['CURRENCYCODE']='USD';
$fields['COUNTRYCODE']='US';
i have specified the total billing cycle as 12 for one year. can i use total billing cycle as 60 for five years.
Try to set parameter $fields['INITAMT'] = $1; and other parameters for recurring payment to $5 for month:
$hosteddata['INITAMT'] = 1;$hosteddata['L_PAYMENTREQUEST_0_AMT0'] = 5;$hosteddata['AMT'] = 5;
In this case you will charge 1$ immediately and after that each month will charge $5 for recurring payment
Yes, you can use total billing cycle as 60 for five years, there is no problem.
You can have a try.
Related
How can I in a smart way get the first business day of a month after the weekend?
To get the first business day of the month (given dateInput), we can do:
firstBusdayMonth = fbusdate(year(dateInput),month(dateInput));
As an example, for November, using the above function will return Thursday November 1 as the first business day. However, the first business day of the month after the first weekend is Monday November 5. How can I get this latter date?
Notes:
The weekend does not have to be in the same month.
If the Monday is not a working day, then I would like it to return the next business day
This function will do the trick. Here is the logic:
Create a datetime array for all days in the given month.
Get the day numbers.
Create a logical array, true from the first Monday onwards (so after the first weekend, accounting for the last day of the previous month being a Sunday).
Create another logical array using isbusday to exclude Mondays which aren't working days.
Finding the first day number where these two logical arrays are true, therefore the first business day after the weekend.
Code:
function d = fbusdateAferWE( y, m )
% Inputs: y = year, m = month
% Outputs: day of the month, first business day after weekend
% Create array of days for the given month
dates = datetime( y, m, 1 ):days(1):datetime( y, m, eomday( y, m ) );
% Get the weekday numbers to find first Monday, 1 = Sunday
dayNum = weekday( dates );
% Create the logical array to determine days from first Monday
afterFirstWeekend = ( cumsum(dayNum==2) > 0 ).';
% Get first day which is afterFirstWeekend and a business day.
d = find( afterFirstWeekend & isbusday( dates ), 1 );
end
You could probably speed this up (although it will be pretty rapid already) by not looking at the whole month, but say just 2 weeks. I used eomday to get the last day of the month, which means I don't have to make assumptions about a low number of holiday days in the first week or anything.
Edit: Working with datenum speeds it up by half (C/O JohnAndrews):
function d = fbusdateAferWE( y, m )
% Inputs: y = year, m = month
% Outputs: day of the month, first business day after weekend
% Create array of days for (first 2 weeks of) the given month
dates = datenum(datetime(y,m,1)):datenum(datetime(y,m,eomday(y,m)))-14;
% Get the weekday numbers to find first Monday, 1 = Sunday
dayNum = weekday( dates );
% Create the logical array to determine days from first Monday
afterFirstWeekend = ( cumsum(dayNum==2) > 0 ).';
% Get first day which is afterFirstWeekend and a business day.
d = find( afterFirstWeekend & isbusday( dates ), 1 );
end
I would add something like this after your statement:
[DayNumber, DayName] = weekday(firstBusdayMonth);
if DayNumber > 2
day = 10 - DayNumber;
else
This works because 'weekday' will return a number between 1 (Sunday) and 7 (Saturday).
The fbusdate() function will never return a 1 or 7, so we can ignore those cases.
If weekday(fbusdate()) == 2, the first is on a Monday and the firstBusdayMonth variable doesn't need to be changed.
If weekday(firstBusdayMonth) returns between 2 and 6, we need to skip to the next week, so we subtract the weekday value from 10 to find the next Monday.
It might not be the most elegant solution, but should work.
We can use fbusdate to get the first business day of a month:
Date = fbusdate(Year, Month);
However, how do we get the first business day of a week?
As an example, during the week that I'm posting this, Monday 09/07/2017 was a holiday in the US:
isbusday(736942) % = 0
How do I determine that the first business day for this week would be the next day 736943?
I'm not aware of a builtin function that returns the first working day of a week, but you can obtain it by requesting the next working day after Sunday:
busdate(736941); % 736941 = Sunday 09/03/2017
Your desired fbusdateweek function can be done in one line using just the function weekday to get the first Sunday of the week then busdate to get the next business day after that:
dn = 736942; % Date number for any day in a week
Date = busdate(dn-weekday(dn)+1);
Note: busdate uses the function holidays by default to get all holidays and special nontrading days for the New York Stock Exchange. If necessary, you can define an alternate set of holidays for busdate to use as follows:
holidayArray = ...; % Some set of date numbers, vectors, or datetimes
Date = busdate(dn-weekday(dn)+1, 1, holidayArray);
This way you can define a set of localized holidays.
Solved it. Here is a function that is based on the answer of #m7913d:
function Busday = fbusdateweek(date)
% Return the first business day after Sunday
% 'date' is a datenum input
dperiod = date-6:date;
sundays = weekday(dperiod)==1;
sunday = find(sundays==1,1,'first');
datesunday = dperiod(sunday);
% -->
Busday = busdate(datesunday);
end
I am working on a calendar app and trying to schedule recurring events.
My biggest issues arise when it comes to events that are supposed to be scheduled on a monthly basis. like day-15 of every month.
Methods like :
Calendar.getInstance();
Calendar.MONTH;
date.setMonth(date.getMonth() + 1);
DateUtils.addMonths(new Date(), 1);
all seem to be not supported by Codename One.
Using date.getTime() appears not to be the best approach. Is there any other way to schedule recurring events in CN1?
Many thanks in advance.
Yes, you can increase the month by using just the Calendar class.
Similar to above is:
java.util.Calendar cal = java.util.Calendar.getInstance();
//first check if current month is December, if it is then switch to a new year
if (cal.get(java.util.Calendar.MONTH) == 11) {
cal.set(java.util.Calendar.YEAR, cal.get(java.util.Calendar.YEAR) + 1); //increase the year
cal.set(java.util.Calendar.MONTH, 0); //January = 0
} else {
cal.set(java.util.Calendar.MONTH, cal.get(java.util.Calendar.MONTH) + 1);//increase the month
}
If a number is 2017 and I divide it by 4, I get 504.25.
if the number is 2016 an I divide it by 4, I get 504.
My question is, is there a way to use perl to check if a number that was divided, if the answer is a whole number and has NO decimal at all?
UPDATE: I got it working from the answer I selected below. I was trying to check if this is leap year, because today my code broke, because my code ran from the cron job as set to run on the last day of every month. Typically for feb, that is the 28th, so it ran on the 28th and shut the website done for the end of month maintenance. so what I have it do now is run on both Feb 28th and Feb 29th (For if there is a 29th) and in the code, I have it check if it is leap year now like this:
my $_leapNum = 4; # Leap year is always divisible by 4 with no remainder...
my $_NotLeapRemain = $_lTimeYYYY % $_leapNum; # I have $_lTimeYYYY built for the year only - longyear
if($_NotLeapRemain) {
my $_isLeapYear = 0;
} else {
my $_isLeapYear = 1;
}
Then later I check if it is leap year. If it is, then I check if the day is 28th, if it is, then it just exits. If it is the 29th, then it does what it was intended to do.
I tested it and it works perfectly now.
Thank you for your help.
-Rich
If you want to know if the result of dividing a $dividend by a $divisor is going to be a whole number or a number with a fractional portion, you can test that condition first:
if (my $remainder = $dividend % $divisor) {
print "$dividend cannot be divided evenly by $divisor.",
" There is a remainder of $remainder.\n";
}
else {
print "$dividend is evenly divisible by $divisor,",
" and the result is ", $divident / $divisor, "\n";
}
*EDIT: * This answer was posted in response to the original, un-edited question, which asked how to determine if the result of division contains a decimal portion. Now that the sense of the question changed toward date math, I agree that a DateTime solution is much better.
Using os.time how can I get how many months have passed since the unix epoch (Unix Timestamp)
I just need it for a month ID, so any kind of number would be fine, as long as it changes every month, and it can be reversed to get the actual month.
local function GetMonth(seconds)
local dayduration,year = 3600*24
local days={31,0,31,30,31,30,31,31,30,31,30,31}
for i=1970,10000 do -- For some reason too lazy to use while
local yeardays = i%4 == 0 and i%100 ~= 0 and 366 or 365
local yearduration = dayduration * yeardays
if yearduration < seconds then
seconds = seconds - yearduration
else
year = i break
end
end
days[2]=(year%4==0) and 29 or 28
seconds = seconds%(365*24*3600)
for i=1,12 do
if seconds>days[i]*dayduration then
seconds=seconds-days[i]*dayduration
else
return --i + year*12 <-- If you want a unique ID
end
end
end
Currently, it'll give the number 2, since it's February. If you uncomment the code at the end for the unique ID, you'll get 554 instead, meaning we're currently at the 554th month since the epoch.
As Jean-Baptiste Yunès said in his answer's comments, I'm not sure if your sentence:
NOTE: This is for Lua, but I'm unable to use os.date
meant you have no os.date, or that you don't know how to use it. You have an answer for both cases, you can use the one you need.
This may do the trick:
print (os.date("*t",os.time())["month"])
os.time() gives you the current date as a number. os.date("*t",...) converts it into a table in which the month equals to the number of the month corresponding to the date.