Use PHP Curl for Remote API Integration, Payment Gateway Integration

PHP has been gifted with a CURL library. But most of the php developers new in the community are not aware of the power of CURL.

Before I show you with some code for which you must be very anxious about, let us go through with some of the benefits whch are provided by CURL to php community.

1. You can easily get file content form a Remote Host.

2. Seamlessly integrate you script with an API and fetch values/result from API.

3. Send / Post values to most popular CRM system like Salesforce

4. Payment Gateway integration. Integrate with most popular gateway Authorize.Net

5. And may more…

So what is the code for CURL-

In the code below I have taken a case that a user login is required to be authenticated from a remote website.

Our PHP code has a username and password filled in by a user and posted to a file where our CURL code will authenticate the username and password.

<?php
//Check user login through a remote API

$api_url = “https://ssl.somedomain.com/sserv/login.jsp”;

$post_values    = array
(
“Id”                => “110063”,
“login_user”        => “user@mydomain.com”,
“login_password”    => “userpass”

);

$fields = “”;
foreach( $post_values as $key => $value ) $fields .= “$key=” . urlencode( $value ) . “&”;

$ch = curl_init($sf_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, “& ” ));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$api_reponse = curl_exec($ch);
curl_close ($ch);

//Debug Response
print_r($api_reponse);

?>

Similarly you can send values to the payment gateway and receive a response form the gateway for the user transaction.

Simple. Were you expecting something more?

Happy Curling…

Bookmark and Share
Both comments and pings are currently closed.

3 Responses to “Use PHP Curl for Remote API Integration, Payment Gateway Integration”

  1. Sid Clock says:

    Reading this article UncleCode.Com – Technology Blog | Use PHP Curl for Remote API Integration, Payment Gateway Integration reminds me of my old roommate! He always kept speaking about this. I will forward this post to him. Pretty sure he will have a superb read. Thanks for the information you post.

  2. This is such an excellent resource that you’re providing and also you give it away for free. I really like seeing websites that understand the worth of providing a high quality resource for free. Great work!

  3. Thanks for sharing the link, but argg it seems to be down… Does anybody have a mirror or another source? Please answer to my message if you do!

    I would appreciate if someone here at http://www.unclecode.com could repost it.

    Thanks,
    Thomas

n