/**
  * The bill has been cancelled or failed, update the user records to compensate
  *
  * @param $existingPayment
  */
 private function handleFailedCancelledBill(Payment $existingPayment)
 {
     if ($existingPayment->reason == 'subscription') {
         //If the payment is a subscription payment then we need to take action and warn the user
         $user = $existingPayment->user()->first();
         $user->status = 'suspended';
         //Rollback the users subscription expiry date or set it to today
         $expiryDate = \BB\Helpers\MembershipPayments::lastUserPaymentExpires($user->id);
         if ($expiryDate) {
             $user->subscription_expires = $expiryDate;
         } else {
             $user->subscription_expires = new Carbon();
         }
         $user->save();
         //Update the subscription charge to reflect the payment failure
         $subCharge = $this->subscriptionChargeRepository->getById($existingPayment->reference);
         if ($subCharge) {
             $this->subscriptionChargeRepository->paymentFailed($subCharge->id);
         }
     } elseif ($existingPayment->reason == 'induction') {
         //We still need to collect the payment from the user
     } elseif ($existingPayment->reason == 'box-deposit') {
     } elseif ($existingPayment->reason == 'key-deposit') {
     }
 }
 /**
  * A payment has been cancelled
  *
  * @param $paymentId
  * @param $userId
  * @param $reason
  * @param $ref
  * @param $status
  */
 public function onCancel($paymentId, $userId, $reason, $ref, $status)
 {
     if ($reason == 'subscription') {
         if (empty($ref)) {
             \Log::warning('Subscription payment failure, no sub charge id. Payment ID: ' . $paymentId);
             return;
         }
         $this->subscriptionChargeRepository->paymentFailed($ref);
     }
 }