diff --git a/lib/Twocheckout/Api/TwocheckoutUtil.php b/lib/Twocheckout/Api/TwocheckoutUtil.php index a5c2851..4f4dc64 100644 --- a/lib/Twocheckout/Api/TwocheckoutUtil.php +++ b/lib/Twocheckout/Api/TwocheckoutUtil.php @@ -39,15 +39,13 @@ public static function objectToJson($object) } public static function getRecurringLineitems($saleDetail) { - $i = 0; $invoiceData = array(); - while (isset($saleDetail['sale']['invoices'][$i])) { - $invoiceData[$i] = $saleDetail['sale']['invoices'][$i]; - $i++; + foreach ($saleDetail['sale']['invoices'] as $invoice) { + $invoiceData[strtotime($invoice['timestamp'])] = $invoice; } - $invoice = max($invoiceData); + $invoice = $invoiceData[max(array_keys($invoiceData))]; $i = 0; $lineitemData = array();