Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
Show All 23 Lines | class PaymentsMollieTest extends TestCase | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
// All tests in this file use Mollie | // All tests in this file use Mollie | ||||
\config(['services.payment_provider' => 'mollie']); | \config(['services.payment_provider' => 'mollie']); | ||||
$reseller = $this->getTestUser('reseller@kolabnow.com'); | $reseller = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$wallet = $reseller->wallets()->first(); | $wallet = $reseller->wallets()->first(); | ||||
Payment::where('wallet_id', $wallet->id)->delete(); | Payment::where('wallet_id', $wallet->id)->delete(); | ||||
Wallet::where('id', $wallet->id)->update(['balance' => 0]); | Wallet::where('id', $wallet->id)->update(['balance' => 0]); | ||||
WalletSetting::where('wallet_id', $wallet->id)->delete(); | WalletSetting::where('wallet_id', $wallet->id)->delete(); | ||||
Transaction::where('object_id', $wallet->id)->delete(); | Transaction::where('object_id', $wallet->id)->delete(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$reseller = $this->getTestUser('reseller@kolabnow.com'); | $reseller = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$wallet = $reseller->wallets()->first(); | $wallet = $reseller->wallets()->first(); | ||||
Payment::where('wallet_id', $wallet->id)->delete(); | Payment::where('wallet_id', $wallet->id)->delete(); | ||||
Wallet::where('id', $wallet->id)->update(['balance' => 0]); | Wallet::where('id', $wallet->id)->update(['balance' => 0]); | ||||
WalletSetting::where('wallet_id', $wallet->id)->delete(); | WalletSetting::where('wallet_id', $wallet->id)->delete(); | ||||
Transaction::where('object_id', $wallet->id)->delete(); | Transaction::where('object_id', $wallet->id)->delete(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
Show All 10 Lines | public function testMandates(): void | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$response = $this->post("api/v4/payments/mandate", []); | $response = $this->post("api/v4/payments/mandate", []); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$response = $this->put("api/v4/payments/mandate", []); | $response = $this->put("api/v4/payments/mandate", []); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$response = $this->delete("api/v4/payments/mandate"); | $response = $this->delete("api/v4/payments/mandate"); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$reseller = $this->getTestUser('reseller@kolabnow.com'); | $reseller = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$wallet = $reseller->wallets()->first(); | $wallet = $reseller->wallets()->first(); | ||||
$wallet->balance = -10; | $wallet->balance = -10; | ||||
$wallet->save(); | $wallet->save(); | ||||
// Test creating a mandate (valid input) | // Test creating a mandate (valid input) | ||||
$post = ['amount' => 20.10, 'balance' => 0]; | $post = ['amount' => 20.10, 'balance' => 0]; | ||||
$response = $this->actingAs($reseller)->post("api/v4/payments/mandate", $post); | $response = $this->actingAs($reseller)->post("api/v4/payments/mandate", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | class PaymentsMollieTest extends TestCase | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
Bus::fake(); | Bus::fake(); | ||||
// Unauth access not allowed | // Unauth access not allowed | ||||
$response = $this->post("api/v4/payments", []); | $response = $this->post("api/v4/payments", []); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
$reseller = $this->getTestUser('reseller@kolabnow.com'); | $reseller = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
// Successful payment | // Successful payment | ||||
$post = ['amount' => '12.34', 'currency' => 'CHF', 'methodId' => 'creditcard']; | $post = ['amount' => '12.34', 'currency' => 'CHF', 'methodId' => 'creditcard']; | ||||
$response = $this->actingAs($reseller)->post("api/v4/payments", $post); | $response = $this->actingAs($reseller)->post("api/v4/payments", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertRegExp('|^https://www.mollie.com|', $json['redirectUrl']); | $this->assertRegExp('|^https://www.mollie.com|', $json['redirectUrl']); | ||||
} | } | ||||
/** | /** | ||||
* Test listing a pending payment | * Test listing a pending payment | ||||
* | * | ||||
* @group mollie | * @group mollie | ||||
*/ | */ | ||||
public function testListingPayments(): void | public function testListingPayments(): void | ||||
{ | { | ||||
Bus::fake(); | Bus::fake(); | ||||
$reseller = $this->getTestUser('reseller@kolabnow.com'); | $reseller = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
// Empty response | // Empty response | ||||
$response = $this->actingAs($reseller)->get("api/v4/payments/pending"); | $response = $this->actingAs($reseller)->get("api/v4/payments/pending"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
Show All 14 Lines | class PaymentsMollieTest extends TestCase | ||||
* Test listing payment methods | * Test listing payment methods | ||||
* | * | ||||
* @group mollie | * @group mollie | ||||
*/ | */ | ||||
public function testListingPaymentMethods(): void | public function testListingPaymentMethods(): void | ||||
{ | { | ||||
Bus::fake(); | Bus::fake(); | ||||
$reseller = $this->getTestUser('reseller@kolabnow.com'); | $reseller = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$response = $this->actingAs($reseller)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_ONEOFF); | $response = $this->actingAs($reseller)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_ONEOFF); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(2, $json); | $this->assertCount(3, $json); | ||||
$this->assertSame('creditcard', $json[0]['id']); | $this->assertSame('creditcard', $json[0]['id']); | ||||
$this->assertSame('paypal', $json[1]['id']); | $this->assertSame('paypal', $json[1]['id']); | ||||
$this->assertSame('banktransfer', $json[2]['id']); | |||||
} | } | ||||
} | } |