Secured banking systems use SOAP/WSDL to communicate third party systems. It's completely platform independent and secured. This communication uses XML data transfers with secured gateway. cURL library (libcURL) allows PHP developers to develop SOAP transactions features between servers/systems. PHP has a built-in library for SOAP communication. But, nuSOAP is a perfect choice to develop SOAP client/server in PHP.
Download nuSOAP Library: Sourceforge
SOAP Client Development:
1. Include nuSOAP library first
It's like including a php script to other. If the nuSOAP library is stored in a directory "lib" with the filename "nusoap.php", then it could be include as follows:
2. Set Parameters
It is needed to set required parameters to call a wsdl server to communicate. Developer should give parameters based on the subjected WSDL server's specific function's requirement.
Suppose, developer has intended to communicate with a wsdl "https://webservicetest.webserviceurl.com:5555/.wsdl" and calls a function "testConnection". "testConnection" function of this wsdl requires parameters "id", "username" and "password".
Save parameters in a variable
3. Certificate Issue
It also requires specific SSL certificate of .pfx or .p12 format. PHP doesn't process .pfx formatted, so it is needed to convert it into set of files like "key.pem" and "cert.pem" with a pass phrase "pass" and save them in the same directory of the scripts (saving to same directory is not mandatory). (See how to covert .pfx or .p12 SSL into .pem certificate).
Better to store certificate and wsdl information into variables.
$wsdl="https://webservicetest.webserviceurl.com:5555/.wsdl";
$sslkey = getcwd()."/key.pem";
$sslcert = getcwd()."/cert.pem";
$passphrase= "pass";
3. Call soap functions
Now, it is time to initialize a soap call.
$client = new nusoap_client($wsdlurl, 'wsdl', $proxyhost, $proxyport, $proxyusername, $proxypassword);
$client->authtype = 'certificate';
$client->decode_utf8 = 0;
$client->soap_defencoding = 'UTF-8';
$client->setCredentials("","","certificate",
array(
"sslcertfile" => $sslcert,
"sslkeyfile" => $sslkey,
"passphrase" => "pass",
"verifypeer" => 0, //OPTIONAL
"verifyhost" => 0 //OPTIONAL
)
);
After initializing, it's time to call specific function of the wsdl. We are going to call "testConnection" function.
4. Recieve and use response
Now the response from the WSDL is stored in $result variable. It's an array, it's possible to use information from that array as developer need.
Monday, December 26, 2011
Friday, December 2, 2011
How to upload a file to ftp directory using PHP
For some projects, we need to upload a file into another ftp server. In this post we will show a simple procedure and description about uploading a file to a ftp using PHP.
You should have the ftp locations and credentials.
Start PHP script with tag ()
Specify the ftp location in a variable. Location could be a domain like "ftp.domain.com" or also could be a IP address like "121.233.45.12".
Store user name of ftp server in a variable.
Store password of ftp server in a variable.
Store the destination location of the file you want to upload. If you want to store the file into the root directory of the ftp, then just mention the name of uploaded file only. But if you want to upload it to a specific folder then, mention the full path and filename. For example, we will use the "In" directory to upload the file with name "example.txt". (Remember, if you upload two files with same name, then second one will replace the first file.)
Store the source location in a variable. If you want to upload a file which is located at the directory from where the upload script is located, then mention only the file name. But, if your file is in another directory, then you have to mention the full path with file name. For example, We will upload a file situated in "files/example.txt". "files" is the name of the directory where "example.txt" file is located.
Establish the connection, store the information of the connection in a variable. We will use ftp_connect($server) function. As we stored server location in the variable "$server".
Login into the ftp server and store information into a variable.
This is portion is not obligatory. But, I always use this line to my code for successful ftp file transfer. I suggest you to add this line to your script.
Upload the file now. There are two different format of file to upload. They are "FTP_ASCII" and "FTP_BINARY". If you upload a text file, any of them you can use based on your text format "ASCII" or "UTF". But, if you upload a file like "zip" or other, use "FTP_BINARY" format.
Now upload is complete, close the ftp connection if you don't have any other ftp actions. If you have other tasks with this same ftp server just after the upload of the file, then you should not establish connection again.
End the PHP tag.
This is a simple tutorial of ftp file upload. But, you have to extend codes based on the requirements of your project. Every steps show lines of a single script.
Prerequisites
You should have the ftp locations and credentials.
Step 1:
Start PHP script with tag ()
Step 2:
Specify the ftp location in a variable. Location could be a domain like "ftp.domain.com" or also could be a IP address like "121.233.45.12".
Step 3:
Store user name of ftp server in a variable.
Step 4:
Store password of ftp server in a variable.
Step 5:
Store the destination location of the file you want to upload. If you want to store the file into the root directory of the ftp, then just mention the name of uploaded file only. But if you want to upload it to a specific folder then, mention the full path and filename. For example, we will use the "In" directory to upload the file with name "example.txt". (Remember, if you upload two files with same name, then second one will replace the first file.)
Step 6:
Store the source location in a variable. If you want to upload a file which is located at the directory from where the upload script is located, then mention only the file name. But, if your file is in another directory, then you have to mention the full path with file name. For example, We will upload a file situated in "files/example.txt". "files" is the name of the directory where "example.txt" file is located.
Step 7:
Establish the connection, store the information of the connection in a variable. We will use ftp_connect($server) function. As we stored server location in the variable "$server".
Step 8:
Login into the ftp server and store information into a variable.
Step 9:
This is portion is not obligatory. But, I always use this line to my code for successful ftp file transfer. I suggest you to add this line to your script.
Step 10:
Upload the file now. There are two different format of file to upload. They are "FTP_ASCII" and "FTP_BINARY". If you upload a text file, any of them you can use based on your text format "ASCII" or "UTF". But, if you upload a file like "zip" or other, use "FTP_BINARY" format.
Step 11:
Now upload is complete, close the ftp connection if you don't have any other ftp actions. If you have other tasks with this same ftp server just after the upload of the file, then you should not establish connection again.
Step 12:
End the PHP tag.
This is a simple tutorial of ftp file upload. But, you have to extend codes based on the requirements of your project. Every steps show lines of a single script.
Thursday, December 1, 2011
How to Create a Text File Using PHP
Once, before invention of relational database, file (text) were the only way to save information. Now, it is more easier to develop an Information System using database and database is more suitable than using text file. But, still it is needed to use the file for different purposes. For, example, it is needed for ftp based banking API integration. For some projects programmers need to create rewritable php or xml scripts also, for these purposes, files are used. Now, we are going to see how to create a text file using PHP.
Create a php script file and codes will remain inside php tag.
Specify your text and save it to a variable.
Suppose, you want to save the text: "Let's make a text file using php." Then, store it to a variable.
Create a blank text file with your expected name and extension. For this example, we will create a example.txt file. Syntax of this code is fopen("file/pathname","permission"). If you want to store the text file into your current directory from which the script is running then just give the name of the file. But, if you want to store it to a specific location, then you have to give complete path with the name of the creating file. Suppose, your script is located at "root/scripts/file/", then with only the name of file will bd created with location: "root/scripts/file/example.txt", but if you want to store it to root directory then give path like "../../example.txt". Permissions are usually write/read. If you want to just create the file as read only mode, keep permission "r". Or, if you want to keep it in write mode, then keep "w" or "r+". We will keep it "w" (write permission mode) for writing a text into it. And we are going to store the file into the same directory of the script's location.
Store the text into the file. Require php syntax for this action is fwrite("file variable", "Text/ text variable"). As we have created the file and stored it's information in $file variable and already stored the text into the variable into $text variable, our syntax will be like fwrite($file,$text);
Close the file and end php tax.
This is a simple tutorial of creating a text file. You will need to do extended coding for fulfilling additional requirements of your project. It will be great pleasure of mine, if this tutorial helps you.
Step 1:
Create a php script file and codes will remain inside php tag.
Step 2:
Specify your text and save it to a variable.
Suppose, you want to save the text: "Let's make a text file using php." Then, store it to a variable.
Step 3:
Create a blank text file with your expected name and extension. For this example, we will create a example.txt file. Syntax of this code is fopen("file/pathname","permission"). If you want to store the text file into your current directory from which the script is running then just give the name of the file. But, if you want to store it to a specific location, then you have to give complete path with the name of the creating file. Suppose, your script is located at "root/scripts/file/", then with only the name of file will bd created with location: "root/scripts/file/example.txt", but if you want to store it to root directory then give path like "../../example.txt". Permissions are usually write/read. If you want to just create the file as read only mode, keep permission "r". Or, if you want to keep it in write mode, then keep "w" or "r+". We will keep it "w" (write permission mode) for writing a text into it. And we are going to store the file into the same directory of the script's location.
Step 4:
Store the text into the file. Require php syntax for this action is fwrite("file variable", "Text/ text variable"). As we have created the file and stored it's information in $file variable and already stored the text into the variable into $text variable, our syntax will be like fwrite($file,$text);
Step 5:
Close the file and end php tax.
This is a simple tutorial of creating a text file. You will need to do extended coding for fulfilling additional requirements of your project. It will be great pleasure of mine, if this tutorial helps you.
Tuesday, November 29, 2011
ftp Based Banking API Integrations
Lots of financial organizations use ftp as the mean of money transferring gateway to reduce remittance cost. Usually they have a ftp server to which their clients have different user credential to get access. At least two different directories remain as default in every user's ftp directory named as "In" and "Out". Some of these money transferring agencies have their own format of text for getting order of financial activity, some of them doesn't have any, but they usually make contact with their client for understanding each other. For executing a money transfer or any other financial activity client should get access to the ftp directory and add a text order file in ftp "In" directory. Companies simultaneously checks every client's ftp "In" directories for checking new orders manually or automatically and if they find any new file, then they starts to execute the order.
Every text order file has a portion where it saves the current status of the execution of the order. For a new order client keep the status as "Pending" or "0:Pending". When the financial organization, to which this order came, receives the order and starts to execute they changes the status as "Processing" or something like that. After the completion of the order, they copy the file and saves it to ftp "Out" directory with status changed to "Successfully transferred" or something like that.
The client also simultaneously checks the ftp "Out" directory for knowing if the order is completed. They check files manually or by their server's CRON job of script which automatically checks the ftp directory. When they find a new text file at "Out" directory, they checks relevant order text files name to check which order is completed. Ordered organization usually keeps the name same to the text "order" file when they completes the specific order and save a completion text file to "Out" folder.
1. How to create Text File using PHP
2. How to upload a file to ftp directory using PHP
This is the rough procedure of ftp based banking. I will share some codes that is needed to configure a ftp based banking API integration to a client's system next.
Every text order file has a portion where it saves the current status of the execution of the order. For a new order client keep the status as "Pending" or "0:Pending". When the financial organization, to which this order came, receives the order and starts to execute they changes the status as "Processing" or something like that. After the completion of the order, they copy the file and saves it to ftp "Out" directory with status changed to "Successfully transferred" or something like that.
The client also simultaneously checks the ftp "Out" directory for knowing if the order is completed. They check files manually or by their server's CRON job of script which automatically checks the ftp directory. When they find a new text file at "Out" directory, they checks relevant order text files name to check which order is completed. Ordered organization usually keeps the name same to the text "order" file when they completes the specific order and save a completion text file to "Out" folder.
Please See Also:
1. How to create Text File using PHP
2. How to upload a file to ftp directory using PHP
This is the rough procedure of ftp based banking. I will share some codes that is needed to configure a ftp based banking API integration to a client's system next.
Monday, November 28, 2011
Use of Object Oriented Programming Style
Suppose, you have planned to join a big software development team where multiple programmers are working. Object Oriented Programming style is preferable in this project from you. There are very simple difference between structured programming and object oriented programming.
In structured programming style, the software have some functions to call for different purposes multiple times. In object oriented programming style, the software also have some functions those are grouped by some objects to call multiple time for different purposes.
For smaller software with few functions, structured programming is the best for development. It will reduce lines of code and processing time. But for bigger project with multiple programmers and huge number of functions, object oriented programming is must.
Same function name mustn't be exist in a same software if it is developed in structured programming way. Programmers have to make sure that the newer function is added with a completely unique name. Repeat of same function name could make the software completely malfunctioned. But in object oriented style of programming, programmers have to make sure that the added new object name is unique for the software, and he have to make sure that the name of a function in a object is unique at it's parent object only. He can repeat the same name of function in different objects.
In structured programming style, the software have some functions to call for different purposes multiple times. In object oriented programming style, the software also have some functions those are grouped by some objects to call multiple time for different purposes.
For smaller software with few functions, structured programming is the best for development. It will reduce lines of code and processing time. But for bigger project with multiple programmers and huge number of functions, object oriented programming is must.
Same function name mustn't be exist in a same software if it is developed in structured programming way. Programmers have to make sure that the newer function is added with a completely unique name. Repeat of same function name could make the software completely malfunctioned. But in object oriented style of programming, programmers have to make sure that the added new object name is unique for the software, and he have to make sure that the name of a function in a object is unique at it's parent object only. He can repeat the same name of function in different objects.
Saturday, November 19, 2011
Experience on Banking API Integration
Financial institutes always try to make their system most secured. Banking APIs also need secured environment for development. Just passed a whole month working on some banking API integration work in a system developed in PHP. So, I needed to integrate those APIs using PHP. Most of the banks or money transferring agencies uses webservices for interaction with third parties now-a-days. But, some are still using ftp still now.
When I got involved with that task, I figured out that, this task is about to impossible for me to complete. I never heard about these things "Webservice", "WSDL" or "SOAP". But I was familiar with RPC (Remote Process Call). Thanks to Google, it helped me lot to find articles about these technologies. I started reading from SOAP & WSDL and then studied about available PHP/webservice development tools. That was the first time I used CURL for sending http request over Internet. Slowly assembled required codes for sending a SOAP request and handling the response. Then started work for the assignment. My client wanted to use the service from another International Financial Organization using webservices. Usually admins of webservice server provides the documentation about the standard http request structure and the requirements. It's easier to work with well-documented systems. That organization required predefined ip address from where the SOAP request comes and a SSL certificate which is provided by the admin. They provided me a .p12 SSL, but PHP cannot handle this format of certificate. PHP supports only .pem format of SSL certificate. I had to convert the .p12 SSL into key.pem and cert.pem with a pass key for key.pem. Then added them with the PHP CURL request codes. But, still it was too time consuming to write xml texts for the request. That time I started to use nuSOAP library which made everything easier to do. It generates xml as the requesting webservice function needs.
nuSOAP library is the best tools for handling SOAP/WSDL development using PHP. SOAP/WSDL helps different systems to interact each other.
When I got involved with that task, I figured out that, this task is about to impossible for me to complete. I never heard about these things "Webservice", "WSDL" or "SOAP". But I was familiar with RPC (Remote Process Call). Thanks to Google, it helped me lot to find articles about these technologies. I started reading from SOAP & WSDL and then studied about available PHP/webservice development tools. That was the first time I used CURL for sending http request over Internet. Slowly assembled required codes for sending a SOAP request and handling the response. Then started work for the assignment. My client wanted to use the service from another International Financial Organization using webservices. Usually admins of webservice server provides the documentation about the standard http request structure and the requirements. It's easier to work with well-documented systems. That organization required predefined ip address from where the SOAP request comes and a SSL certificate which is provided by the admin. They provided me a .p12 SSL, but PHP cannot handle this format of certificate. PHP supports only .pem format of SSL certificate. I had to convert the .p12 SSL into key.pem and cert.pem with a pass key for key.pem. Then added them with the PHP CURL request codes. But, still it was too time consuming to write xml texts for the request. That time I started to use nuSOAP library which made everything easier to do. It generates xml as the requesting webservice function needs.
nuSOAP library is the best tools for handling SOAP/WSDL development using PHP. SOAP/WSDL helps different systems to interact each other.
Saturday, October 15, 2011
Make plan first, then write codes
A project starts with an idea. And an expert coder knows well how to implement an idea. But writing codes is not the major part of a project. It's a part and very essential, but before starting this, a coder must pay some time for gathering prerequisites of coding. Programming is not so different than other things of our real life. In everything, everyone makes plan first and then they do it. When someone does something without thinking, he could be failed. In programming like web application development a programmer should pay lots of time for planning. Because it's easier to make something almost same as one thought and would think in future if there is a good plan before coding.
There are some phases of planning. Firstly, one should to make sure that he knows everything of the project for which he is going to work. Who is going to use this, what will be it's use and how will it work, these question's answers must be known to the coder before he starts coding.
After the clear view about a project's user-end structure, then the second phase of planning could be started. Second phase stands on the platform of first phase planning. A programmer needs to make the data structure and design the procedure (algorithm) for the project based on it's user-end/physical structure. He have to design the database and design the structure of coding based on it's future potential. Then the final stage "programming/coding" will be started.
We know, a program is completely untouchable, but as we use these programs everyday as non replaceable materials, we can mention the part of a program which directly interacts with us is physical part of the program. And the part which works behind it, is non-physical part. programmers and database designers usually make the whole non-physical part and the basic gateway of physical part like forms/buttons without any graphical ornaments. And front-end/UI designers make the basic user interface into an amazing look. When the phases of planning are finished then the back-end and front-end development could run simultaneously. After the completion of them differently, there are only a single day left to make the project open for it's user.
Developer/coders must not think that the planning period is not the part of his work. Obviously it is a fundamental part of development. Without plan nothing could be developed and usually an expert can make plan so fast, but he shouldn't end planning period so fast. If he thinks that planning is done, then he should to take two or three days break. Sometimes some extra-ordinary ideas come into his mind during this time. Every project is potential, so, a coder should make it flexible to extend in future. And an ill-planned project could to be restarted to change the whole thing when it is almost completed. So, as experts says, coders should plan first and then write codes.
There are some phases of planning. Firstly, one should to make sure that he knows everything of the project for which he is going to work. Who is going to use this, what will be it's use and how will it work, these question's answers must be known to the coder before he starts coding.
After the clear view about a project's user-end structure, then the second phase of planning could be started. Second phase stands on the platform of first phase planning. A programmer needs to make the data structure and design the procedure (algorithm) for the project based on it's user-end/physical structure. He have to design the database and design the structure of coding based on it's future potential. Then the final stage "programming/coding" will be started.
We know, a program is completely untouchable, but as we use these programs everyday as non replaceable materials, we can mention the part of a program which directly interacts with us is physical part of the program. And the part which works behind it, is non-physical part. programmers and database designers usually make the whole non-physical part and the basic gateway of physical part like forms/buttons without any graphical ornaments. And front-end/UI designers make the basic user interface into an amazing look. When the phases of planning are finished then the back-end and front-end development could run simultaneously. After the completion of them differently, there are only a single day left to make the project open for it's user.
Developer/coders must not think that the planning period is not the part of his work. Obviously it is a fundamental part of development. Without plan nothing could be developed and usually an expert can make plan so fast, but he shouldn't end planning period so fast. If he thinks that planning is done, then he should to take two or three days break. Sometimes some extra-ordinary ideas come into his mind during this time. Every project is potential, so, a coder should make it flexible to extend in future. And an ill-planned project could to be restarted to change the whole thing when it is almost completed. So, as experts says, coders should plan first and then write codes.
Tuesday, October 11, 2011
Professional PHP Programming Blog
When people say something so professional about programming, they usually mention C#, Java etc. And they also mention PHP as a web-programming language only. But, I don't believe that PHP only can serve the people who browses some information or be connected using social networks. I don't believe so. PHP is not only a programming language for only web and non-business uses. We can use PHP as corporate business solutions like banking. PHP is smarter than other programming languages and it's becoming richer everyday with new extensions in it's libraries.
This blog is dedicated to all PHP programmers who are working so hard to make PHP more useful. In this blog we will try to find some professional uses of PHP. We will gather information about smarter way of programming.
Subscribe to:
Posts (Atom)