0

Im trying to make a redirection plugin on jquery. It should redirect twice, first to a "thank you for purchase, you gonna be redirected now" and then to an external page where you made the actual purchase.

Everything works fine when I redirect but I can't get the item_id or amount of the product that im posting. Is a wordpress page and im posting a product to display in an external page where you made the actual purchase. This is my code which redirects you you to a "/success" page after clicking the button "continue", after the success page is displayed, it will show the message for 5 seconds and then it must redirect you to the actual purchase page:

function addToListAndRedirect(item_id){
var email = jQuery("[name='your-email']").val();
var amount = jQuery("[name='vinbrevet-contact-amount']").val();
var subscription = {
    ListIds: [
        "beeb2f48-5265-443e-960f-4f995d8c2942"
    ],

    ConfirmationIssue: { IssueId: "cd081857-4f30-4da1-ab5c-a7883f62d99c" },

    Contact: {
        Email: email
    }
}
window.location.href = "http://vinbrevet.se/success?items="+ item_id + ":" + amount; }

the code in /success page:

function redirectToExternal(item_id, amount) {
var item_id;
var amount = jQuery("[name='vinbrevet-contact-amount']").val();;
    jQuery.post("http://ui.admlo.se/Api/Subscriptions/c03a4119-f6a8-4d86-b34f-f16177ec7912").always(function() {
    window.location.replace("https://www.systembolaget.se/dryckeslista?items=" + item_id+":" + amount);
});
    }
    setTimeout("redirectToExternal()", 5000);

I understand that it should be a better way... but iis it possible to get the item_id and amount from the browser bar? or how should I get the item_id and amount after the first redirect? In the page /success i can display the item_id and amount but in the second redirect I get undefined:undefined.

URL example:

http://vinbrevet.se/success/?items=7487101:1 (the success page).

https://www.systembolaget.se/delat?items=undefined:undefined (the redirect after success page)

Fernando Lopez
  • 31
  • 1
  • 10

1 Answers1

0

I found a much easier way to do this. Not the same solution but I think is quite better so I dont need to redirect twice. Here is the code, I hope it helps someone someday. The code must have improvments. Alot of improvments, but it works :)

function addToListAndRedirect(item_id){
var email = jQuery("[name='your-email']").val();
var amount = jQuery("[name='xxxxxx-contact-amount']").val();
var subscription = {
    ListIds: [
        "xxxxx-5265-xxxx-960f-4f995d8c2942"
    ],

    ConfirmationIssue: { IssueId: "xxxxxx-4f30-4da1-ab5c-a7883f62d99c" },
    SubscriptionConfirmedUrl: "http://xxxxxxx.se/success/",

    Contact: {
        Email: email
    }
}
setTimeout(function() {
    jQuery('#av_section_1').css('background-color', '#fff');

    jQuery('#av_section_1').html('<div style="padding: 30px; border: 1px solid #b1b2b3; margin: 50px; text-align: center; border-raius: 6px; background-color: #eee;"><h1>You are being redirected!</h1><p>Here is going to be a good text</p><br><button id="toThePage" class="btn button">Link</button></div>'); },4000);
    jQuery.post("http://ui.xxxx.se/Api/Subscriptions/xxxxxx-f6a8-4d86-b34f-f16177ec7912", subscription).always(function() {

    window.location.replace("https://www.xxxxxx.se/xxxxxxx?items="+item_id+":" + amount);
}); }
Fernando Lopez
  • 31
  • 1
  • 10