Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117747702
D1786.1775176302.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
17 KB
Referenced Files
None
Subscribers
None
D1786.1775176302.diff
View Options
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 @@
<div class="form-group row" v-if="wallet.mandate && wallet.mandate.id">
<label class="col-sm-4 col-form-label">Auto-payment</label>
<div class="col-sm-8">
- <span class="form-control-plaintext" id="autopayment">
+ <span id="autopayment" :class="'form-control-plaintext' + (wallet.mandateState ? ' text-danger' : '')">
Fill up by <b>{{ wallet.mandate.amount }} CHF</b>
when under <b>{{ wallet.mandate.balance }} CHF</b>
- using {{ wallet.mandate.method }}<span v-if="wallet.mandate.isDisabled"> (disabled)</span>.
+ using {{ wallet.mandate.method }}
+ <span v-if="wallet.mandateState">({{ wallet.mandateState }})</span>.
</span>
</div>
</div>
@@ -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 @@
</div>
</form>
<div class="form-separator"><hr><span>or</span></div>
- <div id="mandate-form" v-if="!mandate.id">
+ <div id="mandate-form" v-if="!mandate.isValid && !mandate.isPending">
<p>Add auto-payment, so you never run out.</p>
+ <div v-if="mandate.id && !mandate.isValid" class="alert alert-danger">
+ The setup of automatic payments failed. Restart the process to enable automatic top-ups.
+ </div>
<div class="w-100 text-center">
<button type="button" class="btn btn-primary" @click="autoPaymentForm">Set up auto-payment</button>
</div>
</div>
- <div id="mandate-info" v-if="mandate.id">
- <p>Auto-payment is set to fill up your account by <b>{{ mandate.amount }} CHF</b>
+ <div id="mandate-info" v-else>
+ <p>
+ Auto-payment is set to fill up your account by <b>{{ mandate.amount }} CHF</b>
every time your account balance gets under <b>{{ mandate.balance }} CHF</b>.
You will be charged via {{ mandate.method }}.
</p>
- <p v-if="mandate.isDisabled" class="disabled-mandate text-danger">
+ <div v-if="mandate.isPending" class="alert alert-warning">
+ The setup of the automatic payment is still in progress.
+ </div>
+ <div v-else-if="mandate.isDisabled" class="disabled-mandate alert alert-danger">
The configured auto-payment has been disabled. Top up your wallet or
raise the auto-payment amount.
- </p>
+ </div>
<p>You can cancel or change the auto-payment at any time.</p>
<div class="form-group d-flex justify-content-around">
<button type="button" class="btn btn-danger" @click="autoPaymentDelete">Cancel auto-payment</button>
@@ -107,7 +114,8 @@
</div>
<div id="auto-payment" v-if="paymentForm == 'auto'">
<form data-validation-prefix="mandate_">
- <p>Here is how it works: Every time your account runs low,
+ <p>
+ 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.
</p>
@@ -131,23 +139,29 @@
</div>
</div>
</div>
- <p v-if="!mandate.id">
+ <p v-if="!mandate.isValid">
Next, you will be redirected to the checkout page, where you can provide
your credit card details.
</p>
- <p v-if="mandate.isDisabled" class="disabled-mandate text-danger">
+ <div v-if="mandate.isValid && mandate.isDisabled" class="disabled-mandate alert alert-danger">
The auto-payment is disabled. Immediately after you submit new settings we'll
- attempt to top up your wallet.
- </p>
+ enable it and attempt to top up your wallet.
+ </div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary modal-cancel" data-dismiss="modal">Cancel</button>
- <button type="button" class="btn btn-primary modal-action" v-if="paymentForm == 'auto' && mandate.id" @click="autoPayment">
+ <button type="button" class="btn btn-primary modal-action"
+ v-if="paymentForm == 'auto' && (mandate.isValid || mandate.isPending)"
+ @click="autoPayment"
+ >
<svg-icon icon="check"></svg-icon> Submit
</button>
- <button type="button" class="btn btn-primary modal-action" v-if="paymentForm == 'auto' && !mandate.id" @click="autoPayment">
+ <button type="button" class="btn btn-primary modal-action"
+ v-if="paymentForm == 'auto' && !mandate.isValid && !mandate.isPending"
+ @click="autoPayment"
+ >
<svg-icon :icon="['far', 'credit-card']"></svg-icon> Continue
</button>
</div>
@@ -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');
});
});
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 12:31 AM (2 d, 9 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18821566
Default Alt Text
D1786.1775176302.diff (17 KB)
Attached To
Mode
D1786: Fix presenting auto-payment mandate state
Attached
Detach File
Event Timeline