Vendr - Is it possible to add a custom property to a paymentmethod
One of our payment-providers that we use in Vendr calculates the paymentcosts as a percentage of the total order amount, instead of fixed costs. We would like to calculate this ourselves so we can charge these costs to the customer and present the costs before they choose the definitive paymentmethod.
At the moment paymentproviders only accept an absolute Default Pricing, not a percentage. Is there a way for us to add it ourselves to the paymentmethod and adapt the Vendr backoffice so we can enter a value there?
Not exactly. The best I could think to do is just use the price field on the payment method, but use it as a percentage, then override the default IPaymentCalculator to apply it as a percentage rather than a fixed amount.
I made a custom IPaymentCalculator with a CalculatePaymentMethodPrice like this:
public Price CalculatePaymentMethodPrice(PaymentMethodReadOnly paymentMethod, Guid currencyId, Guid? countryId, Guid? regionId, TaxRate taxRate, PaymentCalculatorContext context)
{
if (paymentMethod.PaymentProviderAlias == Constants.PaymentProviders.Mollie)
{
var mollieSetting = // get my custom setting
if (mollieSetting != null
&& mollieSetting.UsePercentage
&& mollieSetting.Percentage > 0)
{
// make a price of the percentage of the order
var price = context.Order.SubtotalPrice.Value.WithoutTax / 100 * mollieSetting.Percentage;
return new Price(price, 0, currencyId);
}
}
// otherwise: use the standard
return CalculatePaymentMethodPrice(paymentMethod, currencyId, countryId, regionId, taxRate);
}
And I can see it used a lot of the time, but not always: on certain views the payment costs are shown on the ordersummary, on other views they are not.
And the worst problem: the paymentcosts are not passed to Mollie when they are a percentage, only when they are fixed price.
Did I make a mistake in the calculator, or is it not always called in the right place?
Vendr - Is it possible to add a custom property to a paymentmethod
One of our payment-providers that we use in Vendr calculates the paymentcosts as a percentage of the total order amount, instead of fixed costs. We would like to calculate this ourselves so we can charge these costs to the customer and present the costs before they choose the definitive paymentmethod.
At the moment paymentproviders only accept an absolute Default Pricing, not a percentage. Is there a way for us to add it ourselves to the paymentmethod and adapt the Vendr backoffice so we can enter a value there?
Hmm,
Not exactly. The best I could think to do is just use the price field on the payment method, but use it as a percentage, then override the default
IPaymentCalculator
to apply it as a percentage rather than a fixed amount.https://vendr.net/docs/core/3.0.0/key-concepts/calculators/
Hope this helps
Hi Matt,
I made a custom IPaymentCalculator with a CalculatePaymentMethodPrice like this:
And I can see it used a lot of the time, but not always: on certain views the payment costs are shown on the ordersummary, on other views they are not.
And the worst problem: the paymentcosts are not passed to Mollie when they are a percentage, only when they are fixed price.
Did I make a mistake in the calculator, or is it not always called in the right place?
Hi Matt,
I will look into the IPaymentCalculator.
Thanks!
is working on a reply...