If you need to change your transaction type (i.e. Payment Type) for Copy and Pay - typical case would be allowing a user to store a credit card, then you would need to generate a new token for a transaction from Peach Payments.
You can easily generate a new token using a server to server call without impacting UX.
Now once you have generated new token you would need some javascript code in order to remove the old COPYandPAY widget an replace it by the new one.
Simple reloading of the widget is not possible.
You can implement the following suggested flow:
- Merchants calls a function which generate a new token
- COPYandPAY Widget needs to be removed using JavaScript: $("div.cardPayment").remove();
- A new COPYandPAY form needs to be appeneded somewhere, in this case to a container "payment": $("#payment").append('<form action="...." id="{new token}">visa master.....</form>');
- COPYandPAY JavaScript needs to embedded again: $.getScript('https://test.ctpe.net/frontend/widget/v3/widget.js?language=en&style=card');
You must complete all of these steps using JavaScript.
A working example is attached below in the HTML file.