diff --git a/app/Jobs/Util/SubscriptionHandler.php b/app/Jobs/Util/SubscriptionHandler.php index bbc28d6dbccb..fb944ce7da5e 100644 --- a/app/Jobs/Util/SubscriptionHandler.php +++ b/app/Jobs/Util/SubscriptionHandler.php @@ -43,7 +43,7 @@ class SubscriptionHandler implements ShouldQueue if(!$this->entity->company || $this->entity->company->company_users->first()->is_migrating) return true; - info("i got past the check"); + //info("i got past the check"); $subscriptions = Subscription::where('company_id', $this->entity->company_id) ->where('event_id', $this->event_id) diff --git a/app/Models/Payment.php b/app/Models/Payment.php index cac400cf7404..53612378747a 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -201,7 +201,9 @@ class Payment extends BaseModel public function refund(array $data) :Payment { - return $this->processRefund($data); + return $this->service()->refundPayment($data); + + //return $this->processRefund($data); } /** diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index cf4699d13bd7..ba17898919c5 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -8,6 +8,7 @@ use App\Factory\InvoiceItemFactory; use App\Models\Activity; use App\Models\CompanyGateway; use App\Models\Credit; +use App\Models\Invoice; use App\Models\Payment; use App\Repositories\ActivityRepository; @@ -54,6 +55,7 @@ class RefundPayment { if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) { + $gateway = CompanyGateway::find($this->company_gateway_id); if ($gateway) { @@ -62,13 +64,21 @@ class RefundPayment if (!$response) { throw new PaymentRefundFailed(); } + + //todo + //need to check the gateway response has successfully be transacted. + + //if a credit has been generated I think this is the correct section to fix the balance of the credit } } + else + $this->payment->refunded += $this->total_refund; + return $this; } - private function createActivity(array $data, int $credit_id) + private function createActivity() { $fields = new \stdClass; $activity_repo = new ActivityRepository(); @@ -81,8 +91,7 @@ class RefundPayment if (isset($this->refund_data['invoices'])) { foreach ($this->refund_data['invoices'] as $invoice) { - $fields->invoice_id = $invoice->id; - + $fields->invoice_id = $invoice['invoice_id']; $activity_repo->save($fields, $this->payment); } } else { @@ -96,7 +105,7 @@ class RefundPayment { if(isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) - $this->total_refund = collect($this->refund_data['invoices']->sum('amount')); + $this->total_refund = collect($this->refund_data['invoices'])->sum('amount'); else $this->total_refund = $this->refund_data['amount']; @@ -133,6 +142,8 @@ class RefundPayment private function buildCreditLineItems() { + $ledger_string = ''; + if(isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) { foreach ($this->refund_data['invoices'] as $invoice) @@ -144,7 +155,7 @@ class RefundPayment $credit_line_item->quantity = 1; $credit_line_item->cost = $invoice['amount']; $credit_line_item->product_key = ctrans('texts.invoice'); - $credit_line_item->notes = ctrans('texts.refund_body', ['amount' => $data['amount'], 'invoice_number' => $inv->number]); + $credit_line_item->notes = ctrans('texts.refund_body', ['amount' => $invoice['amount'], 'invoice_number' => $inv->number]); $credit_line_item->line_total = $invoice['amount']; $credit_line_item->date = $this->refund_data['date']; diff --git a/tests/Feature/RefundTest.php b/tests/Feature/RefundTest.php index 898ac90a82ab..1df44379e248 100644 --- a/tests/Feature/RefundTest.php +++ b/tests/Feature/RefundTest.php @@ -125,6 +125,8 @@ class RefundTest extends TestCase $response->assertStatus(200); +info($arr); + $this->assertEquals(50, $arr['data']['refunded']); $this->assertEquals(Payment::STATUS_REFUNDED, $arr['data']['status_id']); }