/** * @param string $action */ private function processBills($action, array $bills) { foreach ($bills as $bill) { $existingPayment = $this->paymentRepository->getPaymentBySourceId($bill['id']); if ($existingPayment) { if ($bill['status'] == 'failed' || $bill['status'] == 'cancelled') { //Payment failed or cancelled - either way we don't have the money! //We need to retrieve the payment from the user somehow but don't want to cancel the subscription. //$this->handleFailedCancelledBill($existingPayment); $this->paymentRepository->recordPaymentFailure($existingPayment->id, $bill['status']); } elseif ($bill['status'] == 'pending' && $action == 'retried') { //Failed payment is being retried $subCharge = $this->subscriptionChargeRepository->getById($existingPayment->reference); if ($subCharge) { if ($subCharge->amount == $bill['amount']) { $this->subscriptionChargeRepository->markChargeAsProcessing($subCharge->id); } else { //@TODO: Handle partial payments \Log::warning("Sub charge handling - gocardless partial payment"); } } } elseif ($bill['status'] == 'refunded') { //Payment refunded //Update the payment record and possible the user record } elseif ($bill['status'] == 'withdrawn') { //Money taken out - not our concern } } else { \Log::info("GoCardless Webhook received for unknown payment: " . $bill['id']); } } }