Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/PaymentsMollieTest.php
- This file was copied to src/tests/Feature/Controller/PaymentsMollieEuroTest.php.
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | public function testMandates(): void | ||||
$post = ['amount' => -100, 'balance' => 0]; | $post = ['amount' => -100, 'balance' => 0]; | ||||
$response = $this->actingAs($user)->post("api/v4/payments/mandate", $post); | $response = $this->actingAs($user)->post("api/v4/payments/mandate", $post); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
$min = intval(PaymentProvider::MIN_AMOUNT / 100) . ' CHF'; | $min = $wallet->money(PaymentProvider::MIN_AMOUNT); | ||||
$this->assertSame("Minimum amount for a single payment is {$min}.", $json['errors']['amount']); | $this->assertSame("Minimum amount for a single payment is {$min}.", $json['errors']['amount']); | ||||
// Test creating a mandate (negative balance, amount too small) | // Test creating a mandate (negative balance, amount too small) | ||||
Wallet::where('id', $wallet->id)->update(['balance' => -2000]); | Wallet::where('id', $wallet->id)->update(['balance' => -2000]); | ||||
$post = ['amount' => PaymentProvider::MIN_AMOUNT / 100, 'balance' => 0]; | $post = ['amount' => PaymentProvider::MIN_AMOUNT / 100, 'balance' => 0]; | ||||
$response = $this->actingAs($user)->post("api/v4/payments/mandate", $post); | $response = $this->actingAs($user)->post("api/v4/payments/mandate", $post); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
Show All 12 Lines | public function testMandates(): void | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertMatchesRegularExpression('|^https://www.mollie.com|', $json['redirectUrl']); | $this->assertMatchesRegularExpression('|^https://www.mollie.com|', $json['redirectUrl']); | ||||
// Assert the proper payment amount has been used | // Assert the proper payment amount has been used | ||||
$payment = Payment::where('id', $json['id'])->first(); | $payment = Payment::where('id', $json['id'])->first(); | ||||
$this->assertSame(2010, $payment->amount); | $this->assertSame(2010, $payment->amount); | ||||
$this->assertSame($wallet->id, $payment->wallet_id); | $this->assertSame($wallet->id, $payment->wallet_id); | ||||
$this->assertSame(\config('app.name') . " Auto-Payment Setup", $payment->description); | $this->assertSame($user->tenant->title . " Auto-Payment Setup", $payment->description); | ||||
$this->assertSame(PaymentProvider::TYPE_MANDATE, $payment->type); | $this->assertSame(PaymentProvider::TYPE_MANDATE, $payment->type); | ||||
// Test fetching the mandate information | // Test fetching the mandate information | ||||
$response = $this->actingAs($user)->get("api/v4/payments/mandate"); | $response = $this->actingAs($user)->get("api/v4/payments/mandate"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | class PaymentsMollieTest extends TestCase | ||||
public function testStoreAndWebhook(): void | public function testStoreAndWebhook(): 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); | ||||
// Invalid amount | |||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | |||||
// Invalid amount | |||||
$post = ['amount' => -1]; | $post = ['amount' => -1]; | ||||
$response = $this->actingAs($user)->post("api/v4/payments", $post); | $response = $this->actingAs($user)->post("api/v4/payments", $post); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
$min = intval(PaymentProvider::MIN_AMOUNT / 100) . ' CHF'; | $min = $wallet->money(PaymentProvider::MIN_AMOUNT); | ||||
$this->assertSame("Minimum amount for a single payment is {$min}.", $json['errors']['amount']); | $this->assertSame("Minimum amount for a single payment is {$min}.", $json['errors']['amount']); | ||||
// Invalid currency | // Invalid currency | ||||
$post = ['amount' => '12.34', 'currency' => 'FOO', 'methodId' => 'creditcard']; | $post = ['amount' => '12.34', 'currency' => 'FOO', 'methodId' => 'creditcard']; | ||||
$response = $this->actingAs($user)->post("api/v4/payments", $post); | $response = $this->actingAs($user)->post("api/v4/payments", $post); | ||||
$response->assertStatus(500); | $response->assertStatus(500); | ||||
// Successful payment | // Successful payment | ||||
$post = ['amount' => '12.34', 'currency' => 'CHF', 'methodId' => 'creditcard']; | $post = ['amount' => '12.34', 'currency' => 'CHF', 'methodId' => 'creditcard']; | ||||
$response = $this->actingAs($user)->post("api/v4/payments", $post); | $response = $this->actingAs($user)->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->assertMatchesRegularExpression('|^https://www.mollie.com|', $json['redirectUrl']); | $this->assertMatchesRegularExpression('|^https://www.mollie.com|', $json['redirectUrl']); | ||||
$wallet = $user->wallets()->first(); | |||||
$payments = Payment::where('wallet_id', $wallet->id)->get(); | $payments = Payment::where('wallet_id', $wallet->id)->get(); | ||||
$this->assertCount(1, $payments); | $this->assertCount(1, $payments); | ||||
$payment = $payments[0]; | $payment = $payments[0]; | ||||
$this->assertSame(1234, $payment->amount); | $this->assertSame(1234, $payment->amount); | ||||
$this->assertSame(1234, $payment->currency_amount); | $this->assertSame(1234, $payment->currency_amount); | ||||
$this->assertSame('CHF', $payment->currency); | $this->assertSame('CHF', $payment->currency); | ||||
$this->assertSame(\config('app.name') . ' Payment', $payment->description); | $this->assertSame($user->tenant->title . ' Payment', $payment->description); | ||||
$this->assertSame('open', $payment->status); | $this->assertSame('open', $payment->status); | ||||
$this->assertEquals(0, $wallet->balance); | $this->assertEquals(0, $wallet->balance); | ||||
// Test the webhook | // Test the webhook | ||||
// Note: Webhook end-point does not require authentication | // Note: Webhook end-point does not require authentication | ||||
$mollie_response = [ | $mollie_response = [ | ||||
"resource" => "payment", | "resource" => "payment", | ||||
▲ Show 20 Lines • Show All 613 Lines • ▼ Show 20 Lines | public function testListingPayments(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame(1, $json['count']); | $this->assertSame(1, $json['count']); | ||||
$this->assertSame(1, $json['page']); | $this->assertSame(1, $json['page']); | ||||
$this->assertSame(false, $json['hasMore']); | $this->assertSame(false, $json['hasMore']); | ||||
$this->assertCount(1, $json['list']); | $this->assertCount(1, $json['list']); | ||||
$this->assertSame(PaymentProvider::STATUS_OPEN, $json['list'][0]['status']); | $this->assertSame(PaymentProvider::STATUS_OPEN, $json['list'][0]['status']); | ||||
$this->assertSame('CHF', $json['list'][0]['currency']); | |||||
$this->assertSame(PaymentProvider::TYPE_ONEOFF, $json['list'][0]['type']); | |||||
$this->assertSame(1234, $json['list'][0]['amount']); | |||||
$response = $this->actingAs($user)->get("api/v4/payments/has-pending"); | $response = $this->actingAs($user)->get("api/v4/payments/has-pending"); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(true, $json['hasPending']); | $this->assertSame(true, $json['hasPending']); | ||||
// Set the payment to paid | // Set the payment to paid | ||||
$payments = Payment::where('wallet_id', $wallet->id)->get(); | $payments = Payment::where('wallet_id', $wallet->id)->get(); | ||||
Show All 29 Lines | public function testListingPaymentMethods(): void | ||||
$response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_ONEOFF); | $response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_ONEOFF); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(3, $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']); | $this->assertSame('banktransfer', $json[2]['id']); | ||||
$this->assertSame('CHF', $json[0]['currency']); | |||||
$this->assertSame('CHF', $json[1]['currency']); | |||||
$this->assertSame('EUR', $json[2]['currency']); | |||||
$response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_RECURRING); | $response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_RECURRING); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(1, $json); | $this->assertCount(1, $json); | ||||
$this->assertSame('creditcard', $json[0]['id']); | $this->assertSame('creditcard', $json[0]['id']); | ||||
$this->assertSame('CHF', $json[0]['currency']); | |||||
} | } | ||||
} | } |