Friday 13 August 2021

Sitecore Commerce - Braintree Online Payment not working

We have been involved in many Sitecore Commerce projects recently, and its time to start blogging about anything I see useful while working though Sitecore commerce, here is one of the issues I faced and the fix was too simple, its related to Sitecore commerce and Braintree payment plugin. excited, keep reading! 



You know that during the Sitecore Commerce installation, the installation guide will ask you to create a Braintree Sandbox, and to get Merchant Id, Public Id, and Private Key to add these to the installation script to be added to your sitecore commerce installation, but what if you missed something or added incorrect values, what if you want to change these values, how to update these values? yes, correct, if you searched online you can see multiple references asking you to do the following:

  • You will need to update the related policy set in all commerce roles, following are the paths:
    • CommerceAuthoring_Sc\wwwroot\data\Environments\PlugIn.Payments.Braintree.PolicySet-1.0.0.json
    • CommerceMinions_Sc\wwwroot\data\Environments\PlugIn.Payments.Braintree.PolicySet-1.0.0.json
    • CommerceOps_Sc\wwwroot\data\Environments\PlugIn.Payments.Braintree.PolicySet-1.0.0.json
    • CommerceShops_Sc\wwwroot\data\Environments\PlugIn.Payments.Braintree.PolicySet-1.0.0.json
  • Then articles will ask you to bootstrap your commerce engine, which you can do using postman. 

When I add products to the cart and go through the checkout and in the billing step, I still can't see the federated payment section where I can enter card information, what I could see is just empty area as you can see in the following screenshot:





    Diving a little more deep into this, reviewing all JSON files, also looking into the global database, specifically the Commerce Entities and Commerce Entity tables and I can see my Braintree policy is updated and the values are updated as well. 

Next, I looked into the log files, and I found entries like the following: 
[00217 00:06:23 ERROR CtxMsg.Error.InvalidClientPolicy: Text=Invalid Braintree Client Policy]

This logging was for the authoring role, so I recycled the app pool for the authoring site and the payment started to work, here are a couple of screenshot: 





Now, I can see transactions in my Braintree account:








So a very important step after you update your JSON files and bootstrap your commerce engine is to recycle app pool for the authoring site (I would also recommend to recycle app pools for all roles you updated). Hope this will help someone! 

No comments:

Post a Comment