How can I charge for a subscription immediately?

dragonfiy3dragonfiy3 Member
I am setting up foxycart for a monthly box subscription that ships out on the 15th of every month and charges on the 15th of every month. The charge is for the following month, regardless of the date of initial signup. For example, If someone signs up for a subscription on July 1st they are charged on July 1st upon sign up, their first box is shipped on August 15th, and their next charge is on August 15th where that box is shipped on September 15th; if they sign up for a subscription on July 17th they are charged on July 17th upon initial sign up, their first box is shipped on August 15th, and their next charge is on August 15th where that box is shipped on September 15th. How can I do that? Currently if I set the start date for the 15th then it will not charge for any dates from the 16th-30th/31st. If I set no date then it will charge on the same date as sign up every month.
Comments
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3

    Hi there! Good question. To achieve what you're after there - mixing together a future-dated subscription and an immediate charge, you can make use of 2 products in the cart - one the subscription and the other a normal one-off product. To ensure the customer has to check out with both products, you would also make use of our bundled products functionality - which ties multiple products together so that when one is removed, so is the other.

    As an example, this is what that could look like as a link:
    https://YOURSTORE.foxycart.com/cart?name=Monthly+Box+Subscription&price=15.99&code=boxsub&sub_frequency=1m&sub_startdate=15&2:name=First+Month&2:price=15.99&2:parent_code=boxsub&2:quantity_min=1
    Note how there are two products there, with the second products attributes prepended with 2: to differentiate them from the first. The second one-off product also is linked to the first using the parent_code and then the quantity_min is used to prevent it from being removed on its own.
  • Thank you very much! One more question-if I do it this way and the customer orders before the 15th will they be charged again on the 15th?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Yes they will. Setting the subscription product with a sub_startdate=15 means that the subscription will start on the next 15th of the month. So if they order on the 12th, they'll pay $15.99 today from the one-off product, and $15.99 3 days later on the 15th.

    If someone orders on the 15th - they'll pay for both charges that day for a total of $31.98.
  • Is there any way to prevent it from charging them the second time?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    To confirm - are you referring to if they happen to order on the 15th, that it wouldn't charge both the one-off and the subscription costs? If so - there are two ways you could approach it, both requiring some customisation to your add to cart page.

    One would be to dynamically set the sub_startdate attribute to be an actual full date, that you could calculate serverside or with some javascript. You'd calculate when the next 15th of the month would be, which if it's the 15th today, you'd set it to the 15th of the next month instead.

    The other approach would be similar, but if it's the 15th today, you'd simply not include the second one-off product as part of the add to cart. This would mean the customer would just add the subscription product which would start today.

    Could either of those approaches work?
  • I probably should have mentioned that I use foxyshop for wordpress so I'm not familiar with the customization possibilities with that. Adding a one-off product would work for the end half of the month but then it wouldn't work for the beginning half of the month. Let me see if I can explain what I'd like to do a little better...

    I have a monthly subscription (I'm actually working on migrating it off of cratejoy and onto my own) box that bills on the 15th and ships out on the 15th of every month. All billing and all new subscribers are charged in the previous month, meaning any charges whatsoever (be it brand new customers or customers who have been enrolled for months or years) are for the box shipping out the next month Here is an example using the month of July showing initial first time, new customer enrollment:

    July 1st enrollment pays for the August 15th box shipment
    July 2nd enrollment pays for the August 15th box shipment
    July 3rd enrollment pays for the August 15th box.......
    and so on...July 4th, 5th, 6th.....
    ....July 13th, 14th, 15th....
    ....July 16th, 17th, 18th....
    ....July 29th, 30th, 31st...
    Payment on every single day in July pays for the box shipping out in August.
    I want to somehow charge every single brand new customer for one month's worth of the subscription upon checkout with initial enrollment and then their next billing to be the following month. In this example a payment is collected on the enrollment date and the next payment would be August 15th.

    My problems are:
    Currently anyone who subscribes July 1st-15th will not be paying when they enroll but will be billed on the 15th, which will work fine for my needs. However, if I include a one-off with the enrollment they will be charged the initial payment but will be charged again on the 15th which equals an overcharge...they've paid for August twice.
    Anyone who subscribes July 16th-31st will not be billed until August 15th. This means that while they enroll in July they will not get a box shipped to them in August because they have not paid for it. They won't get a box until September because their first payment won't post until August 15th. I fear I will lose customers because of this due to them not understanding why they have to wait 2 months to receive their first box.

    Now...creating a one-off charge bundled with the subscription will work for anyone who enrolls from July 16th-July 31st but it will not work for anyone who enrolls from July 1st-15th as they will get charged twice but will not receive a July box. The reason why I need a month of prepayment is because the boxes are all customized and different every single month so I need those weeks to procure them. I need that previous month's time to ensure I order enough product to put in the boxes as well as the correct custom products. I can't have someone who enrolls a few days before my shipping date because that is not enough time to prepare their box. I won't have enough inventory to build their box

    Are there any round-about ways to handle this? Is there even a way that I can manually handle it? Would it work to create 2 identical products-one without the one-off charge and one with it, then setting one to private and alternate them according to the 15th of every month? This is the only thing I could think of to do but if there is an easier or better way to handle it I'd prefer that.
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Thanks so much for laying that all out - I better understand now what you're wanting to achieve. So with that in mind, what I'd recommend would be to have the add to cart with a bundled one-time product and a subscription product, but rather than have the subscription start date specified as just 15 to be the next 15th of the month, specify a full date that represents the 15th of the following month. In other words - a subscription would never start in the same month that the customer orders in. Instead the payment for that month would be covered by the one-off payment.

    As an example, any orders placed in July would have a subscription which starts the 15th of August along with a one-off product that charges straight away.

    By taking that approach - your orders will all be consistent in how the customer is charged.

    In terms of how to handle that with FoxyShop - it will require adding a variation for a text input for the sub_startdate. This will be visible on the page in the add to cart, but you can hide it with CSS like this:
    .variation-sub_startdate { display:none; }
    With a blank input for the sub_startdate - the subscription would start straight away. To set the subscription to be the 15th of the next month - you would achieve that with some custom javascript. That could look like this:
    <script>
    jQuery(document).ready(function() {
    var d = new Date();
    d.setDate(15);
    d.setMonth(d.getMonth() + 1);
    jQuery("[name^='sub_startdate']").val(d.getFullYear() + "" + ("0" + (d.getMonth() + 1)).slice(-2) + "" + d.getDate());
    });
    </script>
    This javascript gets todays date (based on the customers computer), sets the day to the 15th, adds a month to it and finally updates that text input with the date. This will get the subscription starting on the 15th of the next month.

    With that set up - paired with the product in FoxyShop that is bundled with the one-time charge, that should hopefully get you the setup you needed. There are a couple parts to it - but should hopefully be easy to set up. Let us know if anything needs clarification.
  • Great! That looks like it may work. We will implement it and post our results here. Thank you very much for your help!
  • I've run into some problems that I need help with because I'm using foxyshop with wordpress...

    You said that I would need to add a variation to the product for the sub-startdate. I assume that can be added on the variations page with all the other product variations, right? Then I need to make it not show on the page with the javascript snippet. Where exactly do I put javascript code to affect variations? I couldn't find a place in the Foxyshop dashboard for "page javascript."

    Then you showed me some sample code for custom javascript to dynamically set the sub-startdate. My question is again -- where does this code actually go?

    Finally, you mention that this will pair with the product bundled with the 1-time charge. That is referring to your code earlier in the thread that shows a product link. With this change, I would remove the sub-startdate from that link -- since it is not being set dynamically. But -- since I'm using the Wordpress plugin FoxyShop, products are set up in the admin panel rather than with custom links.
    Is there a separate place to bundle the products? Or can I still use such a custom link?
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    Sorry for the confusion there.

    Let's start off with the product first - you will want to create that within the FoxyShop interface, and you'll need to create two products. The first product will be for the 1 time charge - so create the product for that. You don't want people to be able to purchase this one on it's own, so you'll want to check the "Hide This Product From List View" checkbox in the "Product Details" panel in the right hand sidebar.

    Next you'll create the subscription product in FoxyShop as well - configuring it as needed. Within Product Variations when creating the product, you'll create a "Single Line Of Text" field, and give it a name of "sub_startdate". Although FoxyShop's native subscription functionality does support specifying a start date - as there isn't a native way to set it to always be the 15th of next month, we'll use a custom open field.

    Finally - you'll also want to link your 1 time charge product to the subscription product, which you'll do with the bundled products functionality. If you don't see the "Bundled Products" option towards the bottom of the product page, you'll need to enable it from the "Settings" page of the FoxyShop plugin. Under "Product Relation" on the settings page, check "Enable Bundled Products" and save. Then on the product page, within the "Bundled Products" input, start typing the name of your 1 time charge product and select that.

    At this point, you'll have a subscription product that has the 1 time charge attached - but the subscription will be starting instantly, and you'll see the text input for the start date.

    You'll want to hide the text input with the CSS I provided earlier. This would be best included within a stylesheet as part of your theme. If you don't have access to the files that make up your website, or a way to upload changes to your server, you could also edit the stylesheet using the "Appearance > Editor" option within your Wordpress administration. For reference, this is the style you'll need to include:
    .variation-sub_startdate { display:none; }
    The javascript is similar again - you'll want to include that within your website files as a javascript file, and include that as part of your theme. If you don't have access to your website's files - you can use the "Appearance > Editor" option again to edit the files. For the javascript, you could place that within the "footer.php" file of your theme and right before the closing </body> tag, paste the javascript - included again for your reference here:
    <script>
    jQuery(document).ready(function() {
    var d = new Date();
    d.setDate(15);
    d.setMonth(d.getMonth() + 1);
    jQuery("[name^='sub_startdate']").val(d.getFullYear() + "" + ("0" + (d.getMonth() + 1)).slice(-2) + "" + d.getDate());
    });
    </script>
    With all of that completed - your subscription product page should then not show the start date input, and it would be pre-filled with the date for the 15th of next month.

    I hope that helps clear up any confusion! Let us know if you have any further questions.
  • I put in the changes as you said. The bundle, the text field, and the javascript to hide it all work.
    But the javascript to change the date doesn't do anything. The date is always set for today's date.
    I put the <script> section in the footer.html file just above the close body tag.
    I even tried changing the value of the variable to a hardcoded value -- "16"
    jQuery("[name^='sub_startdate']").val("16");
    No change.
    I did try putting an alert at the end of the code just to verify that it was being run. I could get that to show up.
    I also double-checked to make sure that the variable name I made in the variation was sub_startdate -- just like in the javascript.

    Do you have any suggestions to make it work?
  • brettbrett FoxyCart Team
    Hey @dragonfiy3
    Could you whisper us a URL we can take a look? That might make it a lot easier to figure out what's gone wrong.
  • My website is live but the foxycart is not, it's set to private and I can't set it to public right now because it will cause confusion on the live site. The only way to see it is to log in as admin so that won't work. I can post screenshots.
  • fc_adamfc_adam FoxyCart Team
    @dragonfiy3,

    While screenshots are generally helpful - in this case it'll be best for us to see the code in action. Would it be possible to add us temporarily as a user for your Wordpress set up? I'll whisper the email address you can use for that if that would be ok.
Sign In or Register to comment.