DescriptionText from PaymentMethode (Plugin) in email

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anos atrás
Hi,

I have made several changes to nopCommerce without a problem. But now I am more or less stucked.

What I like to do is: When the customer places an order, an email is sent to the customer (standard nopCommerce feature). In that email I would like to add "DescriptionText" from the selected PaymentMethod.  I made my own plugin based on "Nop.Plugin.Payments.CashOnDelivery" mine is called Nop.Plugin.Payments.ByBank.

In the DescriptionText is information about bankaccountno. (IBAN) to which te customer has to subscribe the money.
This information must also be available in the email to the customer, when he makes an order.

I am able to add extra tokens for the email. But I am not able te retrieve the DescriptionText. What I miss is a methode like "GetAdditionalHandlingFee()" but then for DescriptionText.

I can add a similar function (GetDescriptiontext) to the IPaymentMethode Interface en then to ByBank-Plugin, but than I have to add the method to all the other Payment-Plugins, that is not what I want!

I am using v2.5. Is there somebody, who can help me in the right direction ?
11 anos atrás
I'm sorry, but the whole point of using Interfaces is to have a consistent way of referring to similar things, so if neither the IPlugin interface nor the IPaymentMethod one exposes some properties or methods that you can use to do your things i'm afraid you will have to add them.

I would personally vote for a facility on IPlugin for allowing every kind of metadata to be added or retrieved on demand, if availble.

You could, however, do a little trick/workaround to achieve this without touching the interfaces.

Be sure to define the DescriptionText in the PaymentMethod Settings, like so:


    public class ByBankPaymentSettings : ISettings
    {
        public string DescriptionText { get; set; }
    }


Then, in your ByBankOrderPaymentProcessor (the thingy that inherit from IPaymentMethod), you will have the Install() method save those settings, like so:


            var settings = new ByBankPaymentSettings()
            _settingService.SaveSetting(settings);


Then, when you've have the DescriptionText saved as Settings (in the Setting table), you can retrieve it like this in the MessageTokenProvider:


// We are in MessageTokenProvider#AddOrderTokens method
            var paymentDescriptionSetting = _settingService.GetSettingByKey(paymentMethodName + "setting.descriptiontext");
            if (paymentDescriptionSetting != null)
                tokens.Add(new Token("Order.PaymentMethodDescription", paymentDescriptionSetting.Value));
            else
                tokens.Add(new Token("Order.PaymentMethodDescription", ""));


(You'll need to inject the ISettingService interface onto MessageTokenProvider constructor)

Doing like this, any payment plugin that have a DescriptionText in the settings, will have the token replaced by the setting value.

You may want to play around with the string key, i'm not absolutely sure of what i wrote, you know, MAGIC STRINGS we hate.

That's how i will go for it, if i were on a hurry and unable to add proper facilities to perform that kind of things.

Hope this helps
11 anos atrás
Many thanks for your useful answer. I am gonna implemented it next weekend.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.