Developer forum

Forum » Development » Changing payment method via API

Changing payment method via API

Dmitrij Jazel
Reply

Hi Guys,

I am trying to change Payment method in API.

Tried:

[Subscribe(Dynamicweb.Notifications.Standard.Page.Loaded)]
public class PageLoaded : NotificationSubscriber
{
    public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
    {
        if (args == null)
            return;

        Dynamicweb.Notifications.Standard.Page.LoadedArgs loadedArgs = (Dynamicweb.Notifications.Standard.Page.LoadedArgs)args;
        
        Dynamicweb.eCommerce.Common.Context.Cart.PaymentMethodID = "PAY3";
    }
}

But getting null-pointer exception as soon as I request PaymentMethodID.

 

/Dmitrij


Replies

 
Morten Snedker
Reply

Hi Dmitrij,

And you are confident that you actually do have a cart in context?

You may try using the AddInOrder overload, like
[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Page.Loaded), AddInOrder(1000)]

This ensures that your subscriber is run lastly.

BR /Snedker

 

You must be logged in to post in the forum