Fixes for subscriptions

This commit is contained in:
David Bomba 2021-06-29 16:05:03 +10:00
parent 07e4cc715a
commit ac842d0d83
2 changed files with 13 additions and 2 deletions

View File

@ -319,7 +319,10 @@ class PaymentController extends Controller
* @return Response The response view * @return Response The response view
*/ */
public function credit_response(Request $request) public function credit_response(Request $request)
{ {
nlog("credit response");
nlog($request->all());
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first(); $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first();
/* Hydrate the $payment */ /* Hydrate the $payment */

View File

@ -309,6 +309,9 @@ class SubscriptionService
*/ */
private function calculateProRataRefundItems($invoice, $is_credit = false) :array private function calculateProRataRefundItems($invoice, $is_credit = false) :array
{ {
if(!$invoice)
return [];
/* depending on whether we are creating an invoice or a credit*/ /* depending on whether we are creating an invoice or a credit*/
$multiplier = $is_credit ? 1 : -1; $multiplier = $is_credit ? 1 : -1;
@ -444,6 +447,8 @@ class SubscriptionService
->withTrashed() ->withTrashed()
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->first(); ->first();
if(!$last_invoice)
return true;
if($last_invoice->balance > 0) if($last_invoice->balance > 0)
{ {
@ -489,7 +494,10 @@ class SubscriptionService
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->first(); ->first();
if($last_invoice->balance > 0) if(!$last_invoice){
//do nothing
}
else if($last_invoice->balance > 0)
{ {
$pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription); $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription);
nlog("pro rata charge = {$pro_rata_charge_amount}"); nlog("pro rata charge = {$pro_rata_charge_amount}");