Adding a fee based on payment method
Adding a fee based on payment method
I have added a custom payment method as detailed here.
I'd now like to add a charge for that payment method as a line item on the order. I tried adding a hidden product called 'Wire Transfer Fee', but the cart doesn't seem to like to be modified during checkout. Also, this would show up on the basket page, so it may be manually removed by the customer. I'd like for it to be added similar to a shipping charge.
Is there a way to do this?
I'd now like to add a charge for that payment method as a line item on the order. I tried adding a hidden product called 'Wire Transfer Fee', but the cart doesn't seem to like to be modified during checkout. Also, this would show up on the basket page, so it may be manually removed by the customer. I'd like for it to be added similar to a shipping charge.
Is there a way to do this?
Re: Adding a fee based on payment method
The cart is tricky to manipulate manually, especially with product-type items. But it's easier if you use generic charge/credit type basket items once you understand the flow of things...
The trick is to add it as a "charge" type item to the basket once the payment method is selected and modify the page_init of the checkout page.
Since customers can't modify the basket on the checkout page, they'll have to leave the checkout page and go to the basket page to do it. That's fine - in the page_init of the checkout page, scan the basket contents and remove and "charge"-type line items from it. Then when the payment method is forced to be selected (again), the charge will get added back in again.
so in short terms, modify page_init of the checkout to remove any existing "charges" from the basket. Then add the charge you want once the payment method is selected.
When adding the charge-type basket item, you can specify a name to give it something descriptive but the SKU will get overridden "CHARGE" - sounds like that'll be ok for your purposes but FYI nonetheless.
The trick is to add it as a "charge" type item to the basket once the payment method is selected and modify the page_init of the checkout page.
Since customers can't modify the basket on the checkout page, they'll have to leave the checkout page and go to the basket page to do it. That's fine - in the page_init of the checkout page, scan the basket contents and remove and "charge"-type line items from it. Then when the payment method is forced to be selected (again), the charge will get added back in again.
so in short terms, modify page_init of the checkout to remove any existing "charges" from the basket. Then add the charge you want once the payment method is selected.
When adding the charge-type basket item, you can specify a name to give it something descriptive but the SKU will get overridden "CHARGE" - sounds like that'll be ok for your purposes but FYI nonetheless.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
Re: Adding a fee based on payment method
Hi Joe,
Where do I find the "charge" item type?
EDIT: Found charge as OrderItem.OrderItemType, but can't seem to add OrderItem to the current order. Forgive my ignorance, but does the order exist yet, or only after checkout? If the latter, how do I add the OrderItem to the basket?
Where do I find the "charge" item type?
EDIT: Found charge as OrderItem.OrderItemType, but can't seem to add OrderItem to the current order. Forgive my ignorance, but does the order exist yet, or only after checkout? If the latter, how do I add the OrderItem to the basket?
Re: Adding a fee based on payment method
In the OnePageCheckout control, you have a few steps to perform...
In your case, you're wanting to add a fee to the order when payment method is SELECTED but not entered. So in the individual payment method user controls (probably the credit card one), you're going to have to test for whatever it is you want to determine if the fee is applicable and then add a basket item to the order like below. The rest of the fields should be the self-explanatory.
Remember in the page_init() you'll need to loop through the basket items and delete any existing charge-type basket items. This prevents duplicate charges being added from multiple entries to OnePageCheckout by the visitor. You'll probably want to do this as well in the OnSelected() method for the payment method radio button list. Otherwise you risk duplication when the visitor enters one payment method and then changes their mind and selects/enters a different payment method.
FYI If you want to access the order itself in OnePageCheckout before the receipt page is called, you have to pull in the actual order that resulted from the checkout process. This is done inside the void CheckedOut() function. Once you add the code below to the void CheckedOut() function, the order is now exposed for your use.
In your case, you're wanting to add a fee to the order when payment method is SELECTED but not entered. So in the individual payment method user controls (probably the credit card one), you're going to have to test for whatever it is you want to determine if the fee is applicable and then add a basket item to the order like below. The rest of the fields should be the self-explanatory.
Code: Select all
BasketItem _BasketItem = new BasketItem();
_BasketItem.BasketId = Token.Instance.User.Basket.BasketId;
_BasketItem.OrderItemType = OrderItemType.Charge;
_BasketItem.Price = 3.95;
_BasketItem.Name = "Order Processing Fee";
_BasketItem.Quantity = 1;
_BasketItem.Shippable = CommerceBuilder.Shipping.Shippable.No;
_BasketItem.Save();
Token.Instance.User.Basket.Items.Add(_BasketItem);
Token.Instance.User.Basket.Items.Save();
FYI If you want to access the order itself in OnePageCheckout before the receipt page is called, you have to pull in the actual order that resulted from the checkout process. This is done inside the void CheckedOut() function. Once you add the code below to the void CheckedOut() function, the order is now exposed for your use.
Code: Select all
int _OrderId = e.OrderId;
Order _Order = OrderDataSource.Load(_OrderId);
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
Re: Adding a fee based on payment method
Sorry if this outside the realm of a ablecommerce question and is more of a general programming question, but how do I delete the "charge" basket items in the Page_Init?
What I have is:
But this results in a "Collection was modified; enumeration operation may not execute " error.
What I have is:
Code: Select all
foreach (BasketItem item in _Basket.Items)
{
if (item.OrderItemType == OrderItemType.Charge)
{
Token.Instance.User.Basket.Items.Remove(item);
}
}
Re: Adding a fee based on payment method
You cannot delete a collection item in the midst of looping through the collection itself. You must record the item id value, break out of the foreach and issue a separate remove statement.
A bit inconvenient but that's what is required.
A bit inconvenient but that's what is required.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Ensign (ENS)
- Posts: 10
- Joined: Thu Jan 27, 2011 11:13 pm
Re: Adding a fee based on payment method
Hi,
Thank you for your information. It is useful for me. I need one help. how to set the extra fees for PayPal express checkout. I have included the extra charge (i.e. basket item) to PayPalExpressCheckoutButton user control under the ExpressCheckoutLink_Click() event and i have given the remove option to the page_preRender() event of the same page (Paypalexpresscheckoutbutton) but it was not working for me. The extra charge was not removed. Could you please give me the guidence for how to remove the duplicate record through paypal express checkout.
Thanks in advance.
Thank you for your information. It is useful for me. I need one help. how to set the extra fees for PayPal express checkout. I have included the extra charge (i.e. basket item) to PayPalExpressCheckoutButton user control under the ExpressCheckoutLink_Click() event and i have given the remove option to the page_preRender() event of the same page (Paypalexpresscheckoutbutton) but it was not working for me. The extra charge was not removed. Could you please give me the guidence for how to remove the duplicate record through paypal express checkout.
Thanks in advance.