Payment Director - Charge a Fee for Rentals late in the day

Here's one way to charge a fee to "rentals made after 1pm of a rental starting today" 

Note that RentalStartDateUtc  has Utc suffix, but since current nopC only supports Date and not time for rentals, I don't know if it has any impact - my test shows that when I entered item in cart with today's date, that is what was stored in the database, even though I'm UTC - 5 which would have been UTC next day since I entered it at 9pm.   (There is no DateTime.UtcToday, but DateTime.UtcNow.Date should work in its place if you prefer to use  compare.)   Also, below I use DateTime.Now.Hour and not DateTime.UtcNow.Hour, because I'm comparing the current hour to see if it's later than 1pm my time (13:00) - but this time will also depend on the time of your server.

Order

Type

Name

Expression

Fee Expression

105

Boolean

ChargeAFee

DateTime.Now.Hour > 13 and Items.Any(Product.IsRental and RentalStartDateUtc = DateTime.Today)

 

110

Option

Payments.AuthorizeNet

Show

[ChargeAFee] ? 2 : 0

 

Adjust 13 to the hour of the day you need.  Adjust the "2" in [ChargeFee] ? 2 : 0 to be the fee you want to charge.

You need to enter a similar  line & fee expression for each payment method you've enabled.



FYI, you may need to adjust for UTC:

DateTime.Now.Hour is Hour in the local time zone.

DateTime.UtcNow.Hour is Hour in UTC.

DateTime.Today gives you the current date in the local time zone.

DateTime.UtcNow.Date gives you the current date in UTC.


Tags :  PD-FeeDay-of-week
Comments
Leave your comment
:
hoangle@beautyencounter.com
Created on: 11/7/2022 9:46 AM
how can I show the date in the Description Expression? look like this DateTime.Today.ToString("ddd")    
support@nopTools.com
Created on: 11/7/2022 9:58 AM
Note that the cart could contain 0 or multiple rental items, so you need to test for it, and then in this example, only the first rental item's start date is shown:

String
RentalStartDescription
Items.Any(Product.IsRental) ? Items.First(Product.IsRental).RentalStartDateUtc.ToString("ddd") : ""

Then use [RentalStartDescription] in your Option rule's Description Expression.

Also, note that RentalStartDateUtc is UTC, and that "ddd" is just the day of the week.  (Contact us if you need more info.)
hoangle@beautyencounter.com
Created on: 11/7/2022 10:24 AM
how can I display next monday if today is SAT / SUN ?
support@nopTools.com
Created on: 11/9/2022 11:21 AM
Use variables for the calculations:

DateTime
StartDate
Items.Any(Product.IsRental) ? DateTime(Items.First(Product.IsRental).RentalStartDateUtc) : DateTime.MinValue


String
StartDateDOW
[StartDate].ToString("ddd")


String
RentalStartDescription
[StartDate] = DateTime.MinValue ? "" : [StartDate].AddDays([StartDateDOW] == "Sat" ? 2 : [StartDateDOW]== "Sun" ? 1 : 0).ToString("ddd")


Be sure to user set the Order/Line# sequentially, and before you ...
Then use [RentalStartDescription] in your Option rule's Description Expression
sample@email.tst
Created on: 6/26/2023 5:31 PM
1
sample@email.tst
Created on: 6/26/2023 5:31 PM
1