Paypal API

For everything that's not in any way related to PureBasic. General chat etc...
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Paypal API

Post by Xombie »

Has anyone messed with the Paypal API at all? Are there any examples out there for querying something like total amount in the account or people that donated and their amounts?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Paypal API

Post by srod »

Hi Xombie,

I'd be interested in any progress you might make on this score as, at some point, I will also need to start working with Paypal's APIs etc. Sorry that I cannot help at this point.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Paypal API

Post by netmaestro »

I'm lurking on this one too hehe. For once I'm not the one that's going to charge in and dig out its secrets, I just don't have the time.
BERESHEIT
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Paypal API

Post by Mistrel »

I'm pretty familiar with the PayPal IPN API. But I don't think that's what you're looking for. :|

There is a GetBalance function for the "Website Payments Pro and Express Checkout API Operations". I don't know if these APIs are free though.

https://cms.paypal.com/us/cgi-bin/?&cmd ... _reference

See here also:

https://cms.paypal.com/us/cgi-bin/?&cmd ... brary_code

There are links there for querying for your balance information with sample code. I believe these APIs are free but I haven't actually tried them.

Here is a PHP example using cURL:

Code: Select all

<?php

$environment = 'sandbox';    // or 'beta-sandbox' or 'live'

/**
 * Send HTTP POST Request
 *
 * @param    string    The API method name
 * @param    string    The POST Message fields in &name=value pair format
 * @return    array    Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_) {
    global $environment;

    $API_UserName = urlencode('my_api_username');
    $API_Password = urlencode('my_api_password');
    $API_Signature = urlencode('my_api_signature');
    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {
        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }
    $version = urlencode('51.0');

    // setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    // turning off the server and peer verification(TrustManager Concept).
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);

    // NVPRequest for submitting to server
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

    // setting the nvpreq as POST FIELD to curl
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    // getting response from server
    $httpResponse = curl_exec($ch);

    if(!$httpResponse) {
        exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
    }

    // Extract the RefundTransaction response details
    $httpResponseAr = explode("&", $httpResponse);

    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
        }
    }

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    }

    return $httpParsedResponseAr;
}

$nvpStr="";

$httpParsedResponseAr = PPHttpPost('GetBalance', $nvpStr);

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    exit('GetBalance Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else  {
    exit('GetBalance failed: ' . print_r($httpParsedResponseAr, true));
}

?>
Post Reply