redirect to different page with success message after payment - Vue JS

2.5k views Asked by At

I have a payment modal that opens up, once the user fills it out, and if the payment is successful, I want to redirect to a different page, with a success message. Im using Laravel 5.3 and Vue JS.

Right now, this is how it looks like, and I got it to redirect to a different page, but how would I attach some sort of success message?

this.$http.post('/cropkit/public/subscriptions', this.$data).then(
    window.location.replace('/cropkit/public/profile/dashboard'),
    response => this.status = response.body.status
);

/******** EDIT *********/

Here is the solution to check if is successful, or error occurred:

swal is a alert message plugin

                    this.$http.post('/mysite/subscriptions', this.$data).then((response) => {
                        swal({
                           title: "Success!",
                           text: "Payment has been processed!",
                           type: "success",
                           showConfirmButton: false,
                           allowEscapeKey: false,
                           allowOutsideClick: false,
                           timer: 5000,
                        }),
                        setTimeout(function(){
                            window.location.replace('/mysite/profile/dashboard');
                        }, 4000)
                    }, (response) => {
                        this.status = response.body.status
                    });
1

There are 1 answers

1
AshMenhennett On BEST ANSWER

You could use the error callback.

return this.$http.post(url, data).then((response) => {
    // success, do success logic
}, (response) => {
    // redirect to error view
});