In this Post i am going to explain the sample code from paypal to make DoDirectPayment integration very easy. You can download the code for dodirectpayment here Getting Api signature To integrate dodirectpayment api we need a api signature from paypal, So create a paypal buisness account and verify it by adding your credit card and bank account. to grant api signature login to paypal account and navigate to profile> Api access> add or edit api permissions. After you granted the api permission edit that permssion to allow for dodirect payments. Code Section of paypal api ===== $environment = 'sandbox'; // or 'beta-sandbox' or 'live' if you are testing the paypal dodirect integration enter sanbox in $environment otherwise enter live, get a sanbox test paypal account here. ===== understanding the function PPhttppost in smaple code enter the api details you recieved from granting the api permission here $API_UserName = urlencode('my_api_username'); $API_Password = urlencode('my_api_password'); $API_Signature = urlencode('my_api_signature'); $API_Endpoint is the endpoint where the data is sent and requested for response. ===== The main thing in this code is excuting the curl sessions where the people face lot of problems in thier server support, so please ask your server administrators to enable curl support for your server. $ch = curl_init(); this line starts the curl session $ch = curl_init(); we use curl_setopt function to set an option for transfer curl_setopt($ch, CURLOPT_URL, $API_Endpoint); curl_setopt($ch, CURLOPT_VERBOSE, 1); this makes the curl session execute to specific url that is the end point curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); make true if you are using ssl certificates or false. You dont need to have ssl certificates to test the account in sandbox. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); CURLOPT_RETURNTRANSFER is used to get response true(1) or false(0) from the server that we are executing the curl sessions CURLOPT_POST is used to specify the method for data transfer which is collected from the html form. ===== $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_"; here we set the API operation, version, and API signature in the request. curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); Set the request as a POST FIELD for curl. ===== $httpResponse = curl_exec($ch); here is the line that we get response from paypal api server that the api information we sent is correct or not. Curl_exec($ch) is used to execute the curlsession finally and get response. ===== if(!$httpResponse) { exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); } If the api operation fails this code displays the error caused for failure. ===== $httpResponseAr = explode("&", $httpResponse); $httpParsedResponseAr = array(); foreach ($httpResponseAr as $i => $value) { $tmpAr = explode("=", $value); if(sizeof($tmpAr) > 1) { $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; } } this code extract the details from the response array ===== if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) { exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); } The response returned from paypal api server is equal to 0 or ACK == false you get a failure response ===== return $httpParsedResponseAr; Whether the response from api server is true or false you get a response while this code executes. ===== $paymentType = urlencode('Authorization'); two types of payment methods are authorization and sale, If you set your code to authorization the buyers credit card will be captured for certain amount you specified later you can accept the payment. If you set your code to sale the buyers credit card will be charged at that instant. $firstName = urlencode('customer_first_name'); $lastName = urlencode('customer_last_name'); $creditCardType = urlencode('customer_credit_card_type'); $creditCardNumber = urlencode('customer_credit_card_number'); $expDateMonth = 'cc_expiration_month'; // Month must be padded with leading zero $padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT)); $expDateYear = urlencode('cc_expiration_year'); $cvv2Number = urlencode('cc_cvv2_number'); $address1 = urlencode('customer_address1'); $address2 = urlencode('customer_address2'); $city = urlencode('customer_city'); $state = urlencode('customer_state'); $zip = urlencode('customer_zip'); $country = urlencode('customer_country'); // US or other valid country code $amount = urlencode('example_payment_amuont'); $currencyID = urlencode('USD'); this are the fields which you need to post the information from your html form ====== $nvpStr = "&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber". "&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName"."& STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID"; this code is used to send the collected information from your html form for specific predeifined parameters from paypal. ===== $httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr); here we apply the function PPHttpPost builted above. ===== if("Success" == $httpParsedResponseAr["ACK"]) { exit('Direct Payment Completed Successfully: '.print_r($httpParsedResponseAr, true)); } else { exit('DoDirectPayment failed: ' . print_r($httpParsedResponseAr, true)); } the last and important step that gives the information about the transaction is approved or declined.
You are wright, this content is from paypal school, but i am the admin of the paypal school, due to the certification problems for using the brand name paypal in my domain i got some problem, so that why i been moving my site to another domain, untile that i just moved the site to a blogspot server www(dot)seelswebschool(dot)blogspot(dot)com