From 9d9f9e6a6bc3583e7159d0dfe330f639f44b8ed3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Nov 2022 07:58:24 +1100 Subject: [PATCH] Tests for delayed gocardless payments --- .../GoCardlessPaymentDriver.php | 2 + .../GoCardlessInstantBankPaymentTest.php | 42 ++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index ec56305c2f..0a027fd106 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -353,6 +353,8 @@ class GoCardlessPaymentDriver extends BaseDriver ]; $payment = $this->go_cardless->createPayment($data, Payment::STATUS_COMPLETED); + $payment->status_id = Payment::STATUS_COMPLETED; + $payment->save(); SystemLogger::dispatch( ['response' => $payment, 'data' => $data], diff --git a/tests/Feature/GoCardlessInstantBankPaymentTest.php b/tests/Feature/GoCardlessInstantBankPaymentTest.php index 04dfeab420..db7fe3b2e7 100644 --- a/tests/Feature/GoCardlessInstantBankPaymentTest.php +++ b/tests/Feature/GoCardlessInstantBankPaymentTest.php @@ -14,6 +14,7 @@ namespace Tests\Feature; use App\Models\CompanyGateway; use App\Models\GatewayType; use App\Models\Invoice; +use App\Models\Payment; use App\Models\PaymentHash; use App\Models\PaymentType; use App\Utils\Traits\MakesHash; @@ -159,7 +160,7 @@ class GoCardlessInstantBankPaymentTest extends TestCase $data_object->invoices = [$invoice_object]; $data_object->client = $this->client->id; $data_object->amount_with_fee = $invoice->amount; - + $payment_hash = new PaymentHash(); $payment_hash->hash = "1234567890abc"; $payment_hash->fee_total = 0; @@ -178,6 +179,18 @@ class GoCardlessInstantBankPaymentTest extends TestCase $this->assertEquals($invoice->balance, $test_invoice_object->amount); + $cg = new CompanyGateway; + $cg->company_id = $this->company->id; + $cg->user_id = $this->user->id; + $cg->gateway_key = 'b9886f9257f0c6ee7c302f1c74475f6c'; + $cg->require_cvv = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(config('ninja.testvars.stripe')); + $cg->fees_and_limits = ''; + $cg->save(); + foreach($this->mock['events'] as $event) { @@ -213,22 +226,29 @@ class GoCardlessInstantBankPaymentTest extends TestCase $this->assertEquals('my_mandate', $data['payment_method']); $this->assertEquals('gocardless_payment_id', $data['transaction_reference']); $this->assertEquals($invoice->balance, $data['amount']); + + $gocardless_driver = $cg->driver($this->client); + $gocardless_driver->setPaymentHash($hash); + + $payment = $gocardless_driver->createPayment($data, Payment::STATUS_COMPLETED); + + $this->assertInstanceOf(Payment::class, $payment); + + $this->assertEquals(round($invoice->amount,2), round($payment->amount,2)); + $this->assertEquals(Payment::STATUS_COMPLETED, $payment->status_id); + $this->assertEquals(1, $payment->invoices()->count()); + $this->assertEquals($invoice->number, $payment->invoices()->first()->number); + $this->assertEquals(Invoice::STATUS_PAID, $payment->invoices()->first()->status_id); + + + } } - - - - - - - - - - } + }