Developer forum

Forum » Development » Accessing gateway template values from code

Accessing gateway template values from code


Reply

Hi guys,

 

I'm trying to make a gateway, and i ran into a problem when i needed to access the value from the standard tag <!-@Ecom:Order.Gateway.Page.CallBack-> in my code.

 

I can't seem to find a property that contains the content of that tag, in any of the Objects my gateway inherits from GatewayProvider.

 

Anyone got an idea to how it's done?

 

Regards

  Martin

 

 

 


Replies

 
Reply
mn@co3.dk wrote:

Hi guys,

 

I'm trying to make a gateway, and i ran into a problem when i needed to access the value from the standard tag <!-@Ecom:Order.Gateway.Page.CallBack-> in my code.

 

I can't seem to find a property that contains the content of that tag, in any of the Objects my gateway inherits from GatewayProvider.

 

Anyone got an idea to how it's done?

 

Regards

  Martin

 

 

 

There are no properties containing the urls from the gateway template. Do you need to simply read the value or do you need to overwrite it?

 
Reply
mn@co3.dk wrote:

Hi guys,

 

I'm trying to make a gateway, and i ran into a problem when i needed to access the value from the standard tag <!-@Ecom:Order.Gateway.Page.CallBack-> in my code.

 

I can't seem to find a property that contains the content of that tag, in any of the Objects my gateway inherits from GatewayProvider.

 

Anyone got an idea to how it's done?

 

Regards

  Martin

 

 

 

There are no properties containing the urls from the gateway template. Do you need to simply read the value or do you need to overwrite it?

 
Reply
ldedw wrote:
mn@co3.dk wrote:

Hi guys,

 

I'm trying to make a gateway, and i ran into a problem when i needed to access the value from the standard tag <!-@Ecom:Order.Gateway.Page.CallBack-> in my code.

 

I can't seem to find a property that contains the content of that tag, in any of the Objects my gateway inherits from GatewayProvider.

 

Anyone got an idea to how it's done?

 

Regards

  Martin

 

 

 

There are no properties containing the urls from the gateway template. Do you need to simply read the value or do you need to overwrite it?

I just need to read it, since i have to encode the Callback url with some other stuff into an MD5.
 

 

I could generate the url from the Callback tag my self.

But that would give problems if DW ever changed the callback url structure.

 
Reply
mn@co3.dk wrote:
ldedw wrote:
mn@co3.dk wrote:

Hi guys,

 

I'm trying to make a gateway, and i ran into a problem when i needed to access the value from the standard tag <!-@Ecom:Order.Gateway.Page.CallBack-> in my code.

 

I can't seem to find a property that contains the content of that tag, in any of the Objects my gateway inherits from GatewayProvider.

 

Anyone got an idea to how it's done?

 

Regards

  Martin

 

 

 

There are no properties containing the urls from the gateway template. Do you need to simply read the value or do you need to overwrite it?

I just need to read it, since i have to encode the Callback url with some other stuff into an MD5.
 

 

I could generate the url from the Callback tag my self.

But that would give problems if DW ever changed the callback url structure.

I get your point. I have requested this as a new feature.
 

In the meantime I think the only workaround is to make a template and render the gateway tags to that template, and read the values.

 

Something like:

Frontend.Cart.Renderer renderer = new Frontend.Cart.Renderer(PageView.Current);

Templatev2.Template template = new Templatev2.Template();

template.Html = "<!--@Ecom:Order.Gateway.Page.Callback-->"

Order order = Common.Context.Cart;

Payment payment = New Payment(order.PaymentMethodID);

renderer.RenderGatewaySettings(template, order, payment);

string callbackUrl = template.Output();

 

Please note: I haven't tested this code, it might need adjustments. Also, the PageView given to the renderer should be the pageview of the cart page.

 
Reply

I've tried your code, and i had to tweak it a bit, but i think i got it right.

 

Problem is, that i kills me gateway. he's my code.

 

// Access Callback url since it's not in the API yet
Dynamicweb.eCommerce.Frontend.Cart.Renderer renderer = new Dynamicweb.eCommerce.Frontend.Cart.Renderer( PageView );
Dynamicweb.Templatev2.Template templatev2 = new Dynamicweb.Templatev2.Template();
templatev2.Html = "<--@Ecom:Order.Gateway.Page.Callback-->"; // change so editor doens't render it at a comment
Dynamicweb.eCommerce.Orders.Payment payment = new Dynamicweb.eCommerce.Orders.Payment( Order.PaymentMethodID );
renderer.RenderGatewaySettings( templatev2, Order, payment );
string callbackUrl = templatev2.Output();

 

template.SetTag( TagPreFix + ".DwCallbackURL", callbackUrl );

 

 

The code is executed in the Render method of my gateway provider. and as soon as the above code is used, my gateways times out.

 

Is my code wrong?

 

 

 

 

 

 
Reply
mn@co3.dk wrote:

I've tried your code, and i had to tweak it a bit, but i think i got it right.

 

Problem is, that i kills me gateway. he's my code.

 

// Access Callback url since it's not in the API yet
Dynamicweb.eCommerce.Frontend.Cart.Renderer renderer = new Dynamicweb.eCommerce.Frontend.Cart.Renderer( PageView );
Dynamicweb.Templatev2.Template templatev2 = new Dynamicweb.Templatev2.Template();
templatev2.Html = "<--@Ecom:Order.Gateway.Page.Callback-->"; // change so editor doens't render it at a comment
Dynamicweb.eCommerce.Orders.Payment payment = new Dynamicweb.eCommerce.Orders.Payment( Order.PaymentMethodID );
renderer.RenderGatewaySettings( templatev2, Order, payment );
string callbackUrl = templatev2.Output();

 

template.SetTag( TagPreFix + ".DwCallbackURL", callbackUrl );

 

 

The code is executed in the Render method of my gateway provider. and as soon as the above code is used, my gateways times out.

 

Is my code wrong?

 

 

 

 

 

The timeout may be caused by RenderGateWaySettings also rendering the Gateway itself (calling the Gateway.Render method) which creates an infinite loop.
 

You could use a static field to identify if you called the Gateway.Render method from within the Gateway.Render method.

Like:

 

myStaticBool = true;

do the above stuff

myStaticBool = false;

 

And then check myStaticBool at the start of the Render method:

if (myStaticBool)

    return;

 
Reply

Okay, it doesn't time out now, but now my custom attributes aren't rendered to my frontend.

 

My code looks like this:

 

---

 

static bool hasRun = false;

public override void Render( Dynamicweb.Templatev2.Template template, string TagPreFix )
{
  if ( !hasRun ) {
 base.Render( template, TagPreFix );

 // Access Callback url since it's not in the API yet
 Dynamicweb.eCommerce.Frontend.Cart.Renderer renderer = new Dynamicweb.eCommerce.Frontend.Cart.Renderer( PageView );
 Dynamicweb.Templatev2.Template templatev2 = new Dynamicweb.Templatev2.Template();
 templatev2.Html = "<--@Ecom:Order.Gateway.Page.Callback-->";
 Dynamicweb.eCommerce.Orders.Payment payment = new Dynamicweb.eCommerce.Orders.Payment( Order.PaymentMethodID );
 renderer.RenderGatewaySettings( templatev2, Order, payment );
 string callbackUrl = templatev2.Output();


 template.SetTag( TagPreFix + ".DwCallbackURL", callbackUrl );

 hasRun = true;
  }
}

 

---

 

Any ideas?

 
Reply
mn@co3.dk wrote:

Okay, it doesn't time out now, but now my custom attributes aren't rendered to my frontend.

 

My code looks like this:

 

---

 

static bool hasRun = false;

public override void Render( Dynamicweb.Templatev2.Template template, string TagPreFix )
{
  if ( !hasRun ) {
 base.Render( template, TagPreFix );

 // Access Callback url since it's not in the API yet
 Dynamicweb.eCommerce.Frontend.Cart.Renderer renderer = new Dynamicweb.eCommerce.Frontend.Cart.Renderer( PageView );
 Dynamicweb.Templatev2.Template templatev2 = new Dynamicweb.Templatev2.Template();
 templatev2.Html = "<--@Ecom:Order.Gateway.Page.Callback-->";
 Dynamicweb.eCommerce.Orders.Payment payment = new Dynamicweb.eCommerce.Orders.Payment( Order.PaymentMethodID );
 renderer.RenderGatewaySettings( templatev2, Order, payment );
 string callbackUrl = templatev2.Output();


 template.SetTag( TagPreFix + ".DwCallbackURL", callbackUrl );

 hasRun = true;
  }
}

 

---

 

Any ideas?

I think you need to make sure that the Render method is run every time you don't call it via the RenderGatewaySettings method. What you've done is that you make sure it runs the first time and not any more.
 

 

Try do it like this:

Render {

if (hasRun)

    return;

hasRun = true;

do all your stuff including a call to RenderGatewaySettings

hasRun = false;

}

(maybe rename 'hasRun' to something like 'isCalledFromHere' to avoid confusion)

 

You could also add a lock to ensure that hasRun isn't manipulated by more than one process.

 
Reply

That seems to work, i get my tags set, and the page didn't time out, that good :-)

 

Now i see that the code you suggested to get out the CallBack url isn't working as planned.

 

It looks like the code needs a litle something before it can render it correct.

Because my tag 'DwCallbackURL' ends up containing '<--@Ecom:Order.Gateway.Page.Callback-->'. and not the value fx. http://domain.dk/Default.aspx?ID=27&_OID_=ORDER33&step=6 as i need.

 

 

 

 

 

 

 

 
Reply
mn@co3.dk wrote:

That seems to work, i get my tags set, and the page didn't time out, that good :-)

 

Now i see that the code you suggested to get out the CallBack url isn't working as planned.

 

It looks like the code needs a litle something before it can render it correct.

Because my tag 'DwCallbackURL' ends up containing '<--@Ecom:Order.Gateway.Page.Callback-->'. and not the value fx. http://domain.dk/Default.aspx?ID=27&_OID_=ORDER33&step=6 as i need.

 

 

 

 

 

 

 


 

Do you remember to put the '!' in the tag?

!--@Ecom:Order.Gateway.Page.Callback--

 
Reply
ldedw wrote:
mn@co3.dk wrote:

That seems to work, i get my tags set, and the page didn't time out, that good :-)

 

Now i see that the code you suggested to get out the CallBack url isn't working as planned.

 

It looks like the code needs a litle something before it can render it correct.

Because my tag 'DwCallbackURL' ends up containing '<--@Ecom:Order.Gateway.Page.Callback-->'. and not the value fx. http://domain.dk/Default.aspx?ID=27&_OID_=ORDER33&step=6 as i need.

 

 

 

 

 

 

 


 

Do you remember to put the '!' in the tag?

!--@Ecom:Order.Gateway.Page.Callback--

Ofcourse :-)
 

 
Reply
mn@co3.dk wrote:
ldedw wrote:
mn@co3.dk wrote:

That seems to work, i get my tags set, and the page didn't time out, that good :-)

 

Now i see that the code you suggested to get out the CallBack url isn't working as planned.

 

It looks like the code needs a litle something before it can render it correct.

Because my tag 'DwCallbackURL' ends up containing '<--@Ecom:Order.Gateway.Page.Callback-->'. and not the value fx. http://domain.dk/Default.aspx?ID=27&_OID_=ORDER33&step=6 as i need.

 

 

 

 

 

 

 


 

Do you remember to put the '!' in the tag?

!--@Ecom:Order.Gateway.Page.Callback--

Ofcourse :-)
 

Try using 'CallBack' instead of 'Callback' (uppercase 'B')
 

 
Reply

Dohhhh! :-)

 

It works now.

 

Thanks for your help.

 

 

You must be logged in to post in the forum