Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/PaymentsMollieTest.php
Show First 20 Lines • Show All 119 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 = $wallet->money(PaymentProvider::MIN_AMOUNT); | $min = $wallet->money(Payment::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' => Payment::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); | ||||
$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']); | ||||
$this->assertSame("The specified amount does not cover the balance on the account.", $json['errors']['amount']); | $this->assertSame("The specified amount does not cover the balance on the account.", $json['errors']['amount']); | ||||
// Test creating a mandate (valid input) | // Test creating a mandate (valid input) | ||||
$post = ['amount' => 20.10, 'balance' => 0, 'methodId' => PaymentProvider::METHOD_CREDITCARD]; | $post = ['amount' => 20.10, 'balance' => 0, 'methodId' => PaymentProvider::METHOD_CREDITCARD]; | ||||
$response = $this->actingAs($user)->post("api/v4/payments/mandate", $post); | $response = $this->actingAs($user)->post("api/v4/payments/mandate", $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']); | ||||
// 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($user->tenant->title . " Auto-Payment Setup", $payment->description); | $this->assertSame($user->tenant->title . " Auto-Payment Setup", $payment->description); | ||||
$this->assertSame(PaymentProvider::TYPE_MANDATE, $payment->type); | $this->assertSame(Payment::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(); | ||||
$this->assertEquals(20.10, $json['amount']); | $this->assertEquals(20.10, $json['amount']); | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | public function testStoreAndWebhook(): void | ||||
$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 = $wallet->money(PaymentProvider::MIN_AMOUNT); | $min = $wallet->money(Payment::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 | ||||
Show All 34 Lines | public function testStoreAndWebhook(): void | ||||
// to make the payment status change. | // to make the payment status change. | ||||
$responseStack = $this->mockMollie(); | $responseStack = $this->mockMollie(); | ||||
$responseStack->append(new Response(200, [], json_encode($mollie_response))); | $responseStack->append(new Response(200, [], json_encode($mollie_response))); | ||||
$post = ['id' => $payment->id]; | $post = ['id' => $payment->id]; | ||||
$response = $this->post("api/webhooks/payment/mollie", $post); | $response = $this->post("api/webhooks/payment/mollie", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payment->fresh()->status); | $this->assertSame(Payment::STATUS_PAID, $payment->fresh()->status); | ||||
$this->assertEquals(1234, $wallet->fresh()->balance); | $this->assertEquals(1234, $wallet->fresh()->balance); | ||||
$transaction = $wallet->transactions() | $transaction = $wallet->transactions() | ||||
->where('type', Transaction::WALLET_CREDIT)->get()->last(); | ->where('type', Transaction::WALLET_CREDIT)->get()->last(); | ||||
$this->assertSame(1234, $transaction->amount); | $this->assertSame(1234, $transaction->amount); | ||||
$this->assertSame( | $this->assertSame( | ||||
"Payment transaction {$payment->id} using Mollie", | "Payment transaction {$payment->id} using Mollie", | ||||
$transaction->description | $transaction->description | ||||
); | ); | ||||
// Assert that email notification job wasn't dispatched, | // Assert that email notification job wasn't dispatched, | ||||
// it is expected only for recurring payments | // it is expected only for recurring payments | ||||
Bus::assertDispatchedTimes(\App\Jobs\PaymentEmail::class, 0); | Bus::assertDispatchedTimes(\App\Jobs\PaymentEmail::class, 0); | ||||
// Verify "paid -> open -> paid" scenario, assert that balance didn't change | // Verify "paid -> open -> paid" scenario, assert that balance didn't change | ||||
$mollie_response['status'] = 'open'; | $mollie_response['status'] = 'open'; | ||||
unset($mollie_response['paidAt']); | unset($mollie_response['paidAt']); | ||||
$responseStack->append(new Response(200, [], json_encode($mollie_response))); | $responseStack->append(new Response(200, [], json_encode($mollie_response))); | ||||
$response = $this->post("api/webhooks/payment/mollie", $post); | $response = $this->post("api/webhooks/payment/mollie", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payment->fresh()->status); | $this->assertSame(Payment::STATUS_PAID, $payment->fresh()->status); | ||||
$this->assertEquals(1234, $wallet->fresh()->balance); | $this->assertEquals(1234, $wallet->fresh()->balance); | ||||
$mollie_response['status'] = 'paid'; | $mollie_response['status'] = 'paid'; | ||||
$mollie_response['paidAt'] = date('c'); | $mollie_response['paidAt'] = date('c'); | ||||
$responseStack->append(new Response(200, [], json_encode($mollie_response))); | $responseStack->append(new Response(200, [], json_encode($mollie_response))); | ||||
$response = $this->post("api/webhooks/payment/mollie", $post); | $response = $this->post("api/webhooks/payment/mollie", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payment->fresh()->status); | $this->assertSame(Payment::STATUS_PAID, $payment->fresh()->status); | ||||
$this->assertEquals(1234, $wallet->fresh()->balance); | $this->assertEquals(1234, $wallet->fresh()->balance); | ||||
// Test for payment failure | // Test for payment failure | ||||
Bus::fake(); | Bus::fake(); | ||||
$payment->refresh(); | $payment->refresh(); | ||||
$payment->status = PaymentProvider::STATUS_OPEN; | $payment->status = Payment::STATUS_OPEN; | ||||
$payment->save(); | $payment->save(); | ||||
$mollie_response = [ | $mollie_response = [ | ||||
"resource" => "payment", | "resource" => "payment", | ||||
"id" => $payment->id, | "id" => $payment->id, | ||||
"status" => "failed", | "status" => "failed", | ||||
"mode" => "test", | "mode" => "test", | ||||
]; | ]; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public function testStoreAndWebhookForeignCurrency(): void | ||||
$responseStack = $this->mockMollie(); | $responseStack = $this->mockMollie(); | ||||
$responseStack->append(new Response(200, [], json_encode($mollie_response))); | $responseStack->append(new Response(200, [], json_encode($mollie_response))); | ||||
$post = ['id' => $payment->id]; | $post = ['id' => $payment->id]; | ||||
$response = $this->post("api/webhooks/payment/mollie", $post); | $response = $this->post("api/webhooks/payment/mollie", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payment->fresh()->status); | $this->assertSame(Payment::STATUS_PAID, $payment->fresh()->status); | ||||
$this->assertEquals(1234, $wallet->fresh()->balance); | $this->assertEquals(1234, $wallet->fresh()->balance); | ||||
} | } | ||||
/** | /** | ||||
* Test automatic payment charges | * Test automatic payment charges | ||||
* | * | ||||
* @group mollie | * @group mollie | ||||
*/ | */ | ||||
Show All 23 Lines | public function testTopUp(): void | ||||
$this->assertSame(2010, $payments[1]->amount); | $this->assertSame(2010, $payments[1]->amount); | ||||
$this->assertSame(2010, $payments[1]->currency_amount); | $this->assertSame(2010, $payments[1]->currency_amount); | ||||
$payment = $payments[1]; | $payment = $payments[1]; | ||||
// In mollie we don't have to wait for a webhook, the response to | // In mollie we don't have to wait for a webhook, the response to | ||||
// PaymentIntent already sets the status to 'paid', so we can test | // PaymentIntent already sets the status to 'paid', so we can test | ||||
// immediately the balance update | // immediately the balance update | ||||
// Assert that email notification job has been dispatched | // Assert that email notification job has been dispatched | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payment->status); | $this->assertSame(Payment::STATUS_PAID, $payment->status); | ||||
$this->assertEquals(2010, $wallet->fresh()->balance); | $this->assertEquals(2010, $wallet->fresh()->balance); | ||||
$transaction = $wallet->transactions() | $transaction = $wallet->transactions() | ||||
->where('type', Transaction::WALLET_CREDIT)->get()->last(); | ->where('type', Transaction::WALLET_CREDIT)->get()->last(); | ||||
$this->assertSame(2010, $transaction->amount); | $this->assertSame(2010, $transaction->amount); | ||||
$this->assertSame( | $this->assertSame( | ||||
"Auto-payment transaction {$payment->id} using Mastercard (**** **** **** 9399)", | "Auto-payment transaction {$payment->id} using Mastercard (**** **** **** 9399)", | ||||
$transaction->description | $transaction->description | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public function testTopUp(): void | ||||
// Test webhook for recurring payments | // Test webhook for recurring payments | ||||
$wallet->transactions()->delete(); | $wallet->transactions()->delete(); | ||||
$responseStack = $this->mockMollie(); | $responseStack = $this->mockMollie(); | ||||
Bus::fake(); | Bus::fake(); | ||||
$payment->refresh(); | $payment->refresh(); | ||||
$payment->status = PaymentProvider::STATUS_OPEN; | $payment->status = Payment::STATUS_OPEN; | ||||
$payment->save(); | $payment->save(); | ||||
$mollie_response = [ | $mollie_response = [ | ||||
"resource" => "payment", | "resource" => "payment", | ||||
"id" => $payment->id, | "id" => $payment->id, | ||||
"status" => "paid", | "status" => "paid", | ||||
// Status is not enough, paidAt is used to distinguish the state | // Status is not enough, paidAt is used to distinguish the state | ||||
"paidAt" => date('c'), | "paidAt" => date('c'), | ||||
"mode" => "test", | "mode" => "test", | ||||
]; | ]; | ||||
// We'll trigger the webhook with payment id and use mocking for | // We'll trigger the webhook with payment id and use mocking for | ||||
// a request to the Mollie payments API. We cannot force Mollie | // a request to the Mollie payments API. We cannot force Mollie | ||||
// to make the payment status change. | // to make the payment status change. | ||||
$responseStack->append(new Response(200, [], json_encode($mollie_response))); | $responseStack->append(new Response(200, [], json_encode($mollie_response))); | ||||
$post = ['id' => $payment->id]; | $post = ['id' => $payment->id]; | ||||
$response = $this->post("api/webhooks/payment/mollie", $post); | $response = $this->post("api/webhooks/payment/mollie", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payment->fresh()->status); | $this->assertSame(Payment::STATUS_PAID, $payment->fresh()->status); | ||||
$this->assertEquals(2010, $wallet->fresh()->balance); | $this->assertEquals(2010, $wallet->fresh()->balance); | ||||
$transaction = $wallet->transactions() | $transaction = $wallet->transactions() | ||||
->where('type', Transaction::WALLET_CREDIT)->get()->last(); | ->where('type', Transaction::WALLET_CREDIT)->get()->last(); | ||||
$this->assertSame(2010, $transaction->amount); | $this->assertSame(2010, $transaction->amount); | ||||
$this->assertSame( | $this->assertSame( | ||||
"Auto-payment transaction {$payment->id} using Mollie", | "Auto-payment transaction {$payment->id} using Mollie", | ||||
$transaction->description | $transaction->description | ||||
); | ); | ||||
// Assert that email notification job has been dispatched | // Assert that email notification job has been dispatched | ||||
Bus::assertDispatchedTimes(\App\Jobs\PaymentEmail::class, 1); | Bus::assertDispatchedTimes(\App\Jobs\PaymentEmail::class, 1); | ||||
Bus::assertDispatched(\App\Jobs\PaymentEmail::class, function ($job) use ($payment) { | Bus::assertDispatched(\App\Jobs\PaymentEmail::class, function ($job) use ($payment) { | ||||
$job_payment = $this->getObjectProperty($job, 'payment'); | $job_payment = $this->getObjectProperty($job, 'payment'); | ||||
return $job_payment->id === $payment->id; | return $job_payment->id === $payment->id; | ||||
}); | }); | ||||
Bus::fake(); | Bus::fake(); | ||||
// Test for payment failure | // Test for payment failure | ||||
$payment->refresh(); | $payment->refresh(); | ||||
$payment->status = PaymentProvider::STATUS_OPEN; | $payment->status = Payment::STATUS_OPEN; | ||||
$payment->save(); | $payment->save(); | ||||
$wallet->setSetting('mollie_mandate_id', 'xxx'); | $wallet->setSetting('mollie_mandate_id', 'xxx'); | ||||
$wallet->setSetting('mandate_disabled', null); | $wallet->setSetting('mandate_disabled', null); | ||||
$mollie_response = [ | $mollie_response = [ | ||||
"resource" => "payment", | "resource" => "payment", | ||||
"id" => $payment->id, | "id" => $payment->id, | ||||
"status" => "failed", | "status" => "failed", | ||||
"mode" => "test", | "mode" => "test", | ||||
]; | ]; | ||||
$responseStack->append(new Response(200, [], json_encode($mollie_response))); | $responseStack->append(new Response(200, [], json_encode($mollie_response))); | ||||
$response = $this->post("api/webhooks/payment/mollie", $post); | $response = $this->post("api/webhooks/payment/mollie", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$wallet->refresh(); | $wallet->refresh(); | ||||
$this->assertSame(PaymentProvider::STATUS_FAILED, $payment->fresh()->status); | $this->assertSame(Payment::STATUS_FAILED, $payment->fresh()->status); | ||||
$this->assertEquals(2010, $wallet->balance); | $this->assertEquals(2010, $wallet->balance); | ||||
$this->assertTrue(!empty($wallet->getSetting('mandate_disabled'))); | $this->assertTrue(!empty($wallet->getSetting('mandate_disabled'))); | ||||
// Assert that email notification job has been dispatched | // Assert that email notification job has been dispatched | ||||
Bus::assertDispatchedTimes(\App\Jobs\PaymentEmail::class, 1); | Bus::assertDispatchedTimes(\App\Jobs\PaymentEmail::class, 1); | ||||
Bus::assertDispatched(\App\Jobs\PaymentEmail::class, function ($job) use ($payment) { | Bus::assertDispatched(\App\Jobs\PaymentEmail::class, function ($job) use ($payment) { | ||||
$job_payment = $this->getObjectProperty($job, 'payment'); | $job_payment = $this->getObjectProperty($job, 'payment'); | ||||
return $job_payment->id === $payment->id; | return $job_payment->id === $payment->id; | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | public function testRefundAndChargeback(): void | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->transactions()->delete(); | $wallet->transactions()->delete(); | ||||
$mollie = PaymentProvider::factory('mollie'); | $mollie = PaymentProvider::factory('mollie'); | ||||
// Create a paid payment | // Create a paid payment | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'tr_123456', | 'id' => 'tr_123456', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'amount' => 123, | 'amount' => 123, | ||||
'credit_amount' => 123, | 'credit_amount' => 123, | ||||
'currency_amount' => 123, | 'currency_amount' => 123, | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'mollie', | 'provider' => 'mollie', | ||||
'description' => 'test', | 'description' => 'test', | ||||
]); | ]); | ||||
// Test handling a refund by the webhook | // Test handling a refund by the webhook | ||||
$mollie_response1 = [ | $mollie_response1 = [ | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function testRefundAndChargeback(): void | ||||
$this->assertSame(Transaction::WALLET_REFUND, $transactions[0]->type); | $this->assertSame(Transaction::WALLET_REFUND, $transactions[0]->type); | ||||
$this->assertSame("refund desc", $transactions[0]->description); | $this->assertSame("refund desc", $transactions[0]->description); | ||||
$payments = $wallet->payments()->where('id', 're_123456')->get(); | $payments = $wallet->payments()->where('id', 're_123456')->get(); | ||||
$this->assertCount(1, $payments); | $this->assertCount(1, $payments); | ||||
$this->assertSame(-101, $payments[0]->amount); | $this->assertSame(-101, $payments[0]->amount); | ||||
$this->assertSame(-101, $payments[0]->currency_amount); | $this->assertSame(-101, $payments[0]->currency_amount); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payments[0]->status); | $this->assertSame(Payment::STATUS_PAID, $payments[0]->status); | ||||
$this->assertSame(PaymentProvider::TYPE_REFUND, $payments[0]->type); | $this->assertSame(Payment::TYPE_REFUND, $payments[0]->type); | ||||
$this->assertSame("mollie", $payments[0]->provider); | $this->assertSame("mollie", $payments[0]->provider); | ||||
$this->assertSame("refund desc", $payments[0]->description); | $this->assertSame("refund desc", $payments[0]->description); | ||||
// Test handling a chargeback by the webhook | // Test handling a chargeback by the webhook | ||||
$mollie_response1["_links"] = [ | $mollie_response1["_links"] = [ | ||||
"chargebacks" => [ | "chargebacks" => [ | ||||
"href" => "https://api.mollie.com/v2/payments/{$payment->id}/chargebacks", | "href" => "https://api.mollie.com/v2/payments/{$payment->id}/chargebacks", | ||||
Show All 39 Lines | public function testRefundAndChargeback(): void | ||||
$this->assertSame(-15, $transactions[0]->amount); | $this->assertSame(-15, $transactions[0]->amount); | ||||
$this->assertSame(Transaction::WALLET_CHARGEBACK, $transactions[0]->type); | $this->assertSame(Transaction::WALLET_CHARGEBACK, $transactions[0]->type); | ||||
$this->assertSame('', $transactions[0]->description); | $this->assertSame('', $transactions[0]->description); | ||||
$payments = $wallet->payments()->where('id', 'chb_123456')->get(); | $payments = $wallet->payments()->where('id', 'chb_123456')->get(); | ||||
$this->assertCount(1, $payments); | $this->assertCount(1, $payments); | ||||
$this->assertSame(-15, $payments[0]->amount); | $this->assertSame(-15, $payments[0]->amount); | ||||
$this->assertSame(PaymentProvider::STATUS_PAID, $payments[0]->status); | $this->assertSame(Payment::STATUS_PAID, $payments[0]->status); | ||||
$this->assertSame(PaymentProvider::TYPE_CHARGEBACK, $payments[0]->type); | $this->assertSame(Payment::TYPE_CHARGEBACK, $payments[0]->type); | ||||
$this->assertSame("mollie", $payments[0]->provider); | $this->assertSame("mollie", $payments[0]->provider); | ||||
$this->assertSame('', $payments[0]->description); | $this->assertSame('', $payments[0]->description); | ||||
Bus::assertNotDispatched(\App\Jobs\PaymentEmail::class); | Bus::assertNotDispatched(\App\Jobs\PaymentEmail::class); | ||||
$this->unmockMollie(); | $this->unmockMollie(); | ||||
} | } | ||||
Show All 10 Lines | public function testRefundAndChargebackForeignCurrency(): void | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->transactions()->delete(); | $wallet->transactions()->delete(); | ||||
$mollie = PaymentProvider::factory('mollie'); | $mollie = PaymentProvider::factory('mollie'); | ||||
// Create a paid payment | // Create a paid payment | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'tr_123456', | 'id' => 'tr_123456', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => Payment::STATUS_PAID, | ||||
'amount' => 1234, | 'amount' => 1234, | ||||
'credit_amount' => 1234, | 'credit_amount' => 1234, | ||||
'currency_amount' => 1117, | 'currency_amount' => 1117, | ||||
'currency' => 'EUR', | 'currency' => 'EUR', | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => Payment::TYPE_ONEOFF, | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'mollie', | 'provider' => 'mollie', | ||||
'description' => 'test', | 'description' => 'test', | ||||
]); | ]); | ||||
// Test handling a refund by the webhook | // Test handling a refund by the webhook | ||||
$mollie_response1 = [ | $mollie_response1 = [ | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | public function testListingPayments(): void | ||||
$response = $this->actingAs($user)->get("api/v4/payments/pending"); | $response = $this->actingAs($user)->get("api/v4/payments/pending"); | ||||
$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(Payment::STATUS_OPEN, $json['list'][0]['status']); | ||||
$this->assertSame('CHF', $json['list'][0]['currency']); | $this->assertSame('CHF', $json['list'][0]['currency']); | ||||
$this->assertSame(PaymentProvider::TYPE_ONEOFF, $json['list'][0]['type']); | $this->assertSame(Payment::TYPE_ONEOFF, $json['list'][0]['type']); | ||||
$this->assertSame(1234, $json['list'][0]['amount']); | $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(); | ||||
$this->assertCount(1, $payments); | $this->assertCount(1, $payments); | ||||
$payment = $payments[0]; | $payment = $payments[0]; | ||||
$payment->status = PaymentProvider::STATUS_PAID; | $payment->status = Payment::STATUS_PAID; | ||||
$payment->save(); | $payment->save(); | ||||
// They payment should be gone from the pending list now | // They payment should be gone from the pending list now | ||||
$response = $this->actingAs($user)->get("api/v4/payments/pending"); | $response = $this->actingAs($user)->get("api/v4/payments/pending"); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame(0, $json['count']); | $this->assertSame(0, $json['count']); | ||||
$this->assertCount(0, $json['list']); | $this->assertCount(0, $json['list']); | ||||
Show All 9 Lines | |||||
* @group mollie | * @group mollie | ||||
*/ | */ | ||||
public function testListingPaymentMethods(): void | public function testListingPaymentMethods(): void | ||||
{ | { | ||||
Bus::fake(); | Bus::fake(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_ONEOFF); | $response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . Payment::TYPE_ONEOFF); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$hasCoinbase = !empty(\config('services.coinbase.key')); | $hasCoinbase = !empty(\config('services.coinbase.key')); | ||||
$this->assertCount(3 + intval($hasCoinbase), $json); | $this->assertCount(3 + intval($hasCoinbase), $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[0]['currency']); | ||||
$this->assertSame('CHF', $json[1]['currency']); | $this->assertSame('CHF', $json[1]['currency']); | ||||
$this->assertSame('EUR', $json[2]['currency']); | $this->assertSame('EUR', $json[2]['currency']); | ||||
if ($hasCoinbase) { | if ($hasCoinbase) { | ||||
$this->assertSame('bitcoin', $json[3]['id']); | $this->assertSame('bitcoin', $json[3]['id']); | ||||
$this->assertSame('BTC', $json[3]['currency']); | $this->assertSame('BTC', $json[3]['currency']); | ||||
} | } | ||||
$response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . PaymentProvider::TYPE_RECURRING); | $response = $this->actingAs($user)->get('api/v4/payments/methods?type=' . Payment::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']); | $this->assertSame('CHF', $json[0]['currency']); | ||||
} | } | ||||
} | } |