Port 443 will need to be enabled for secure transactions to go through because it is the default port for HTTPS which is the transfer protocol for secure communication.
This way your credit card transactions will be encrypted to ensure protection from those who would seek to steal your data and your money.
Following are attached images that will help you understand the complete code. The code is tested with different variables and different outputs are obtained. All the necessary description is given in the form o comments inside the code.