我可能错过了一些明显的东西;我正在尝试从返回的数据中获取与Braintree Payments建立订阅的日期。我的代码如下:
$result1 = Braintree_Subscription::create($subscriptionData);
if ($result1->success) {
echo("Subscription ID: " . $result1->subscription->id . "<br />");
echo("Transaction ID: " . $result1->subscription->transactions[0]->id . "<br />");
echo("Type: " . $result1->subscription->transactions[0]->amount . "<br />");
//next line has error!!!!!!
echo("Date: " . $result1->subscription->billingPeriodEndDate . "<br />");
前三个“回声”会毫无问题地返回它们的内容。如果我尝试获取任何日期值,例如:billingPeriodEndDate,billingPeriodStartDate,createdAt,updatedAt页面刚刚失败,(不再显示)但没有错误。错误报告已打开。任何帮助表示赞赏。
如果我删除错误所在的行并在下面添加以下内容
echo "<ul>";
foreach ($result1 AS $item) {
echo "<li>" . $item . "</li>";
}
然后我可以看到数组的全部内容。但我仍然无法拉出我需要的东西。日期格式为:
billingPeriodEndDate =星期五,01-Jan-16 00:00:00 UTC,
因为它包含可能是问题的逗号......?
由于
答案 0 :(得分:2)
完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support。
日期属性返回DateTime对象。尝试格式化日期,可能会收到Object of class DateTime could not be converted to string
错误。
echo("Date: " . $result1->subscription->billingPeriodEndDate->format('Y-m-d H:i:s') . "<br />");
如果有帮助,请告诉我!
答案 1 :(得分:0)
完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support。
如果不知道确切的错误我会猜测没有默认的时区设置。尝试设置一个并查看它是否有效。
date_default_timezone_set("America/Chicago")