diff --git a/src/resources/vue/Admin/User.vue b/src/resources/vue/Admin/User.vue --- a/src/resources/vue/Admin/User.vue +++ b/src/resources/vue/Admin/User.vue @@ -127,10 +127,11 @@
- + Fill up by {{ wallet.mandate.amount }} CHF when under {{ wallet.mandate.balance }} CHF - using {{ wallet.mandate.method }} (disabled). + using {{ wallet.mandate.method }} + ({{ wallet.mandateState }}).
@@ -442,6 +443,7 @@ .then(response => { this.$root.removeLoader(financesTab) this.wallet = response.data + this.setMandateState() }) .catch(error => { this.$root.removeLoader(financesTab) @@ -531,6 +533,16 @@ }) .modal() }, + setMandateState() { + let mandate = this.wallet.mandate + if (mandate && mandate.id) { + if (!mandate.isValid) { + this.wallet.mandateState = mandate.isPending ? 'pending' : 'invalid' + } else if (mandate.isDisabled) { + this.wallet.mandateState = 'disabled' + } + } + }, oneOffDialog(negative) { this.oneoff_negative = negative this.dialog = $('#oneoff-dialog').on('shown.bs.modal', event => { diff --git a/src/resources/vue/Wallet.vue b/src/resources/vue/Wallet.vue --- a/src/resources/vue/Wallet.vue +++ b/src/resources/vue/Wallet.vue @@ -83,21 +83,28 @@

or
-
+

Add auto-payment, so you never run out.

+
+ The setup of automatic payments failed. Restart the process to enable automatic top-ups. +
-
-

Auto-payment is set to fill up your account by {{ mandate.amount }} CHF +

+

+ Auto-payment is set to fill up your account by {{ mandate.amount }} CHF every time your account balance gets under {{ mandate.balance }} CHF. You will be charged via {{ mandate.method }}.

-

+

+ The setup of the automatic payment is still in progress. +
+
The configured auto-payment has been disabled. Top up your wallet or raise the auto-payment amount. -

+

You can cancel or change the auto-payment at any time.

@@ -107,7 +114,8 @@
-

Here is how it works: Every time your account runs low, +

+ Here is how it works: Every time your account runs low, we will charge your preferred payment method for an amount you choose. You can cancel or change the auto-payment option at any time.

@@ -131,23 +139,29 @@
-

+

Next, you will be redirected to the checkout page, where you can provide your credit card details.

-

+

The auto-payment is disabled. Immediately after you submit new settings we'll - attempt to top up your wallet. -

+ enable it and attempt to top up your wallet. +
@@ -221,7 +235,7 @@ this.$root.removeLoader(mandate_form) - if (!this.mandate.id) { + if (!this.mandate.id || this.mandate.isPending) { this.$root.addLoader(mandate_form) axios.get('/api/v4/payments/mandate') .then(response => { @@ -253,7 +267,7 @@ }) }, autoPayment() { - const method = this.mandate.id ? 'put' : 'post' + const method = this.mandate.id && (this.mandate.isValid || this.mandate.isPending) ? 'put' : 'post' const post = { amount: this.mandate.amount, balance: this.mandate.balance @@ -264,6 +278,7 @@ axios[method]('/api/v4/payments/mandate', post) .then(response => { if (method == 'post') { + this.mandate.id = null // a new mandate, redirect to the chackout page if (response.data.redirectUrl) { location.href = response.data.redirectUrl diff --git a/src/tests/Browser/Pages/PaymentMollie.php b/src/tests/Browser/Pages/PaymentMollie.php --- a/src/tests/Browser/Pages/PaymentMollie.php +++ b/src/tests/Browser/Pages/PaymentMollie.php @@ -47,18 +47,19 @@ /** * Submit payment form. * - * @param \Laravel\Dusk\Browser $browser The browser object + * @param \Laravel\Dusk\Browser $browser The browser object + * @param string $state Test payment status (paid, open, failed, canceled, expired) * * @return void */ - public function submitValidCreditCard($browser) + public function submitValidCreditCard($browser, $status = 'paid') { if ($browser->element('@methods')) { $browser->click('@methods button.grid-button-creditcard') ->waitFor('button.form__button'); } - $browser->click('input[value="paid"]') + $browser->click('input[value="' . $status . '"]') ->click('button.form__button'); } } diff --git a/src/tests/Browser/PaymentMollieTest.php b/src/tests/Browser/PaymentMollieTest.php --- a/src/tests/Browser/PaymentMollieTest.php +++ b/src/tests/Browser/PaymentMollieTest.php @@ -120,6 +120,8 @@ $browser->assertSeeIn('@title', 'Top up your wallet') ->assertSeeIn('@button-cancel', 'Cancel') ->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') + ->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') + ->assertMissing('@body #mandate-form .alert') ->click('@body #mandate-form button') ->assertSeeIn('@title', 'Add auto-payment') ->assertSeeIn('@body label[for="mandate_amount"]', 'Fill up by') @@ -166,11 +168,12 @@ $browser->assertSeeIn('@title', 'Top up your wallet') ->waitFor('#mandate-info') ->assertSeeIn('#mandate-info p:first-child', $expected) + ->assertMissing('@body .alert') ->click('@button-cancel'); }); }); - // Test updating auto-payment + // Test updating (disabled) auto-payment $this->browse(function (Browser $browser) use ($user) { $wallet = $user->wallets()->first(); $wallet->setSetting('mandate_disabled', 1); @@ -181,14 +184,14 @@ ->with(new Dialog('@payment-dialog'), function (Browser $browser) { $browser->waitFor('@body #mandate-info') ->assertSeeIn( - '@body #mandate-info p.disabled-mandate', + '@body #mandate-info .disabled-mandate', 'The configured auto-payment has been disabled' ) ->assertSeeIn('@body #mandate-info button.btn-primary', 'Change auto-payment') ->click('@body #mandate-info button.btn-primary') ->assertSeeIn('@title', 'Update auto-payment') ->assertSeeIn( - '@body form p.disabled-mandate', + '@body form .disabled-mandate', 'The auto-payment is disabled.' ) ->assertValue('@body #mandate_amount', '100') @@ -210,9 +213,9 @@ // Open the dialog again and make sure the "disabled" text isn't there ->click('@main button') ->with(new Dialog('@payment-dialog'), function (Browser $browser) { - $browser->assertMissing('@body #mandate-info p.disabled-mandate') + $browser->assertMissing('@body #mandate-info .disabled-mandate') ->click('@body #mandate-info button.btn-primary') - ->assertMissing('@body form p.disabled-mandate') + ->assertMissing('@body form .disabled-mandate') ->click('@button-cancel'); }); }); @@ -226,7 +229,78 @@ ->click('@body #mandate-info button.btn-danger') ->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') ->assertVisible('@body #mandate-form') - ->assertMissing('@body #mandate-info'); + ->assertMissing('@body #mandate-info') + ->click('@button-cancel'); + }); + }); + + // Test pending and failed mandate + $this->browse(function (Browser $browser) { + $browser->on(new WalletPage()) + ->click('@main button') + ->with(new Dialog('@payment-dialog'), function (Browser $browser) { + $browser->assertSeeIn('@title', 'Top up your wallet') + ->assertSeeIn('@button-cancel', 'Cancel') + ->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') + ->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') + ->assertMissing('@body #mandate-form .alert') + ->click('@body #mandate-form button') + ->assertSeeIn('@title', 'Add auto-payment') + ->assertMissing('@body .alert') + // Submit valid data + ->type('@body #mandate_amount', '100') + ->type('@body #mandate_balance', '0') + ->click('@button-action'); + }) + ->on(new PaymentMollie()) + ->submitValidCreditCard('open') + ->waitForLocation('/wallet') + ->visit('/wallet?paymentProvider=mollie') + ->on(new WalletPage()) + ->click('@main button') + ->with(new Dialog('@payment-dialog'), function (Browser $browser) { + $expected = 'Auto-payment is set to fill up your account by 100 CHF every' + . ' time your account balance gets under 0 CHF. You will be charged' + . ' via Credit Card.'; + + $browser->assertSeeIn('@title', 'Top up your wallet') + ->waitFor('#mandate-info') + ->assertSeeIn('#mandate-info p:first-child', $expected) + ->assertSeeIn( + '#mandate-info .alert-warning', + 'The setup of the automatic payment is still in progress.' + ) + ->assertSeeIn('@body #mandate-info .btn-danger', 'Cancel auto-payment') + ->assertSeeIn('@body #mandate-info .btn-primary', 'Change auto-payment') + // Delete the mandate + ->click('@body #mandate-info .btn-danger') + ->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') + ->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') + ->assertMissing('@body #mandate-form .alert') + ->click('@body #mandate-form button') + ->assertSeeIn('@title', 'Add auto-payment') + ->assertMissing('@body .alert') + // Submit valid data + ->type('@body #mandate_amount', '100') + ->type('@body #mandate_balance', '0') + ->click('@button-action'); + }) + ->on(new PaymentMollie()) + ->submitValidCreditCard('failed') + ->waitForLocation('/wallet') + ->visit('/wallet?paymentProvider=mollie') + ->on(new WalletPage()) + ->click('@main button') + ->with(new Dialog('@payment-dialog'), function (Browser $browser) { + $browser->waitFor('#mandate-form') + ->assertMissing('#mandate-info') + ->assertSeeIn('#mandate-form p', 'Add auto-payment') + ->waitFor('#mandate-form .alert-danger') + ->assertSeeIn( + '#mandate-form .alert-danger', + 'The setup of automatic payments failed. Restart the process to enable' + ) + ->assertSeeIn('@body #mandate-form .btn-primary', 'Set up auto-payment'); }); }); }