Developer forum

Forum » Integration » GetCustomerStatementPDF

GetCustomerStatementPDF

Tomas Gomez
Reply

Hi,

To get a customer statement PDF from BC, I created a button inside a template to download the PDF by a javascript function. This function has to do a GetCustomerStatementPDF request according the doc at https://doc.dynamicweb.com/documentation-9/integration/integration-framework/erp-plug-in-units/live-integration-requests-and-responses#sideNavTitle1-1-2

Inside the javascript function, which call should be used to send this request? May I create an endpoint? is there any other way? 

Regards,
Tomas


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Tomas,
the problem is that this request is not implemented in the Live integration by default so you will need to implement its handling by yourself using the Integration customer center
Live integration notification subscriber.
For triggering the pdf request from the Live integration it is needed to call the page with the url like that:
http://yourSiteName/Admin/public/CustomerCenter/RequestExternalPdf.aspx?customerID=123&startdate=&enddate=&shopid=SHOP1&generateCustomerStatement=true
Then in the custom implemented "Live integration" project you need to subscribe to:
DynamicwebLiveIntegration.Notifications.IntegrationCustomerCenter.OnAfterGenerateRetrievePdfXml
and override the Document xml with yours one when there is a "generateCustomerStatement=true" parameter in the Request,
so you do not broke the standard Integration customer center pdf functionality.
Then in your subscriber you need to override/update the Document xml so it suits the needed request xml for the GetCustomerStatementPDF request,
read the values from the Request query string: customerID, dates and produce the xml like this:
<GetCustomerStatementPDF customerID="20000" startDate="2009-12-30" endDate="2020-12-30"></GetCustomerStatementPDF>
Then you should be able to get the pdf file after visiting this url.
Also you can include the query string parameter: "&forceDownload=true" to directly download the file from the browser (instead of displaying it)

Here is a sample code:


 

using Dynamicweb.Extensibility.Notifications;

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples.Notifications.IntegrationCustomerCenter
{
    /// <summary>
    /// Class RetrievePdfAfterGenerateXmlSubscriber.
    /// </summary>
    /// <seealso cref="NotificationSubscriber" />
    [Subscribe(DynamicwebLiveIntegration.Notifications.IntegrationCustomerCenter.OnAfterGenerateRetrievePdfXml)]

    public class RetrievePdfAfterGenerateXmlSubscriber : NotificationSubscriber
    {
        /// <summary>
        /// Call to invoke observer.
        /// </summary>
        /// <param name="notification">The notification.</param>
        /// <param name="args">The args.</param>
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var myArgs = (DynamicwebLiveIntegration.Notifications.IntegrationCustomerCenter.OnAfterGenerateRetrievePdfXmlArgs)args;

            // TODO: Add code here
            if (myArgs?.Document != null && Core.Converter.ToBoolean(Dynamicweb.Context.Current?.Request["generateCustomerStatement"]))
            {
                var newDoc = new System.Xml.XmlDocument();
                //Update the xml with your values from the Dynamicweb.Context.Current.Request:
                newDoc.LoadXml("<GetCustomerStatementPDF customerID=\"20000\" startDate=\"2009-12-30\" endDate=\"2020-12-30\"></GetCustomerStatementPDF>");
                myArgs.Document.InnerXml = newDoc.InnerXml;
            }
        }
    }
}



BR, Dmitrij

Votes for this answer: 1
 
Tomas Gomez
Reply

Hi Dmitrij,

I tried your code and it works great :-)

Thanks a lot!
Tomas

 

You must be logged in to post in the forum