Peter Jewicz
Peter Jewicz

Reputation: 666

Looking at paypal API - What is cURL?

I've been looking at several examples of utilizing paypal's API to develop a simple script to be able to use it to checkout, and in each one I keep running across cURL, and I really don't understand it at all. Is it just different PHP functions from a library, or something all together different? More importantly, can I copy and paste cURL commands into my document and it will work, or do I need to download something to get it work on my local server and shared hosting server where my live site will go? Lastly, where can I go to learn this? I've done some searching but haven't found any solid material on it. I really appreciate any help.

Upvotes: 0

Views: 197

Answers (2)

sandy
sandy

Reputation: 1158

You can use a simple form to the checkout. To use via cURL you need to enable cURL and use it in your PHP code.

The following is the simple way.

<form action="https://paypal.com/cgi-bin/webscr" method="post">  
    <input type="hidden" name="business" value="[email protected] ">  
    <input type="hidden" name="cmd" value="_xclick-subscriptions">  
    <input type="hidden" name="item_name" value="sand bag">  
    <input type="hidden" name="item_number" value="1234">  
    <input type="hidden" name="currency_code" value="USD">  
    <input type="hidden" name="notify_url" value="http://abc.com/xyz.php">
    <input type="hidden" name="return" value="http://google.com">

    <!-- Display the payment button. --> 


<input type="image" name="submit" border="0" src="btn_subscribe_LG.gif" alt="PayPal - The safer, easier way to pay online">  
<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >  

Upvotes: 0

A basic understanding of cURL example from PHP Manual

<?php

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

PHP Manual

cURL with PayPal API . [Found it on the internet]

<?php

$ch = curl_init();
$clientId = "myId";
$secret = "mySecret";

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

$result = curl_exec($ch);

if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);
    print_r($json->access_token);
}

curl_close($ch);

?>

Upvotes: 1

Related Questions