I'm setting up an application using Paypal Adaptive Payments.
I'm currently implementing the call to the Preapproval, and the specification says the StartDate can not be before today.
With that in mind... under which timezone are they validating this against?
The API SDK has this in the example:
$currDate = getdate();
$startDate = $currDate['year'].'-'.$currDate['mon'].'-'.$currDate['mday'];
$startDate = strtotime($startDate);
$startDate = date('Y-m-d', mktime(0,0,0,date('m',$startDate),date('d',$startDate),date('Y',$startDate)));
$endDate = add_date($startDate, 1);
However that date can be different based on the timezone of the server sending the request.
Anyone have any ideas on how to ensure no issues will occur?
Edit w/ Bounty:
As of December 15th, we have now run into this as an error. We are using UTC time, and once it turns a new day in UTC, payments start getting failures.
I am using the above code in the following place:
$preapprovalRequest->startingDate = $startDate;
$preapprovalRequest->endingDate = $endDate;
What do I need to make this work?
Edit 2:
Yes timezone is setup as UTC, we did this intentionally so that all time information in our database is stored without timezone.
Essentially I'm trying to figure out how to specify that the date I'm sending to Paypal is in UTC, not whatever timezone they happen to be in.
Edit 3:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APPreapproval
There is the API, and it says the following
The startingDate and endingDate can be in eiter Zulu or GMT offset formats. as in the following respective examples: 2010-09-10Z 2010-09-10T17:24:03.874-07:00
Essentially I need the above code, to output something like that specifying I'm using UTC...
The api documentation says it uses GMT or Zulu time over the wire, and expects it to have a final 'Z' to indicate this (consistent with ISO 8601).
Additional Notes About the PreApproval API Operation
- Preapproval constraints are additive; thus, for example, if you specify a preapproval that allows payments only on Fridays and on the 13th day of the month, the preapproval would be valid only on Friday the 13th of months within the specified time period.
- The startingDate and endingDate can be in eiter Zulu or GMT offset formats. as in the following respective examples:
2010-09-10Z
[NOTE: THIS IS ZULU]
2010-09-10T17:24:03.874-07:00
[NOTE: THIS IS GMT OFFSET]
The safest thing to use is probably this:
$startingDate = gmdate('Y-m-d\Z', $startingDateTimestamp);
However, you must make absolutely sure that your own server's time zone (and time!) is set correctly. You may also need to set timezone separately in your PHP application using date_default_timezone_set()
.
Finally, there's another wrinkle--I do not know what SDK you are using. Possibly it tries to be clever and changes the date you pass in to something else. In that case you need to find out what date translation it does and what date it expects. (E.g., perhaps it expects a date in the system-local time, and it changes it to a UTC time.) Assuming it doesn't alter what you supply, however, you should be able to use the code above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With