For invoice templates created before the Lightning interface was introduced, the online payment link may not work when the invoice was emailed using Lightning (it will still work when emailed using Classic). To make it work with Lightning, please follow the steps below:

Go to Payment Center Settings and click Customize Invoice button. Click Edit Template next to Invoice Template field to edit your template.

Search for the following:

<apex:outputLink rendered="{!Relatedto.Domain_Name__c != null}" value="https://{!Relatedto.Domain_Name__c}/fw1__Payment?invoiceId={!Relatedto.Id}&showInvoiceLines=true" >Click here to pay online</apex:outputLink>

And replace with:

<!-- credit card/echeck -->
 <apex:outputPanel rendered="{!Relatedto.Domain_Name__c != null}">
 <a href="https://{!Relatedto.Domain_Name__c}/fw1__Payment?invoiceId={!Relatedto.Id}&showInvoiceLines=true" >Click here to pay online</a>
 </apex:outputPanel>

Save your template.

Go to an invoice and click Email / Print Invoice PDF button:

On the next page, click “Your invoice template may have changed. Click here to update your template.“:

Test your template and make sure that the link is now working.