free hit counter

How to Process Credit Cards with PayPal Payments Pro Using PHP

Process Credit Cards with PayPal Payments Pro Using PHP

Process Credit Cards with PayPal Payments Pro Using PHP

What is paypal pro?

Paypal pro is the Direct Credit Card processing API that allows you to checkout with credit card payments via PayPal directly on your site. The customer enters their credit card details on your site, never has to leave your site and PayPal handles the payment.

Direct Payment API Introduction (By Paypal)

Source : https://www.paypal.com/cgi-bin/webscr?cmd=_dcc_hub-outside

Direct Payment API offers you direct credit card payment processing capability through PayPal. For credit card transactions, customers stay on your website as PayPal processes the payment in the background.

By integrating Direct Payment API with Express Checkout, as part of the Website Payments Pro solution, you can accept all major payment types, including PayPal, while working with a single provider that processes and manages all your online payments for you.

Direct Payment API is:

Customizable

  • Direct Payment API lets you design and host your own checkout pages
  • You keep your customers on your site instead of having them pay on PayPal; PayPal remains invisible
  • PayPal authorizes transactions in a real-time process

Easy to implement

  • Direct Payment API is already integrated with many leading shopping carts
  • The API is built using the Name-Value Pair infrastructure, an industry standard that utilizes web services
  • PayPal’s SDK toolkit lets you easily integrate the PayPal API into your website

Secure

  • Transactions are sent over the internet using Secure Socket Layer (SSL)
  • Direct Payment API lets you flag potentially fraudulent transactions, and provides you with industry-standard AVS and CVV2 responses for each transaction
  • You use an API certificate, provided by PayPal, to make calls to the API through a secure connection

How it works

For each payment, Direct Payment API takes the billing address, transaction amount, credit card information, and item information as inputs. Within seconds, the API returns a confirmation that the transaction has been processed.

Please note: Direct Payment API is not a stand-alone product. You are required to use Direct Payment API and Express Checkout together as part of the Website Payments Pro solution.

Here is the code:

Click here to download this code

paypal component for cakephp

  1. <?php  
  2. echo “<pre>”;  
  3. $environment = ‘sandbox’;   // ‘sandbox’ or ‘beta-sandbox’ or ‘live’  
  4. function PPHttpPost($methodName_$nvpStr_) {  
  5.     global $environment;  
  6.    
  7.     // Set up your API credentials, PayPal end point, and API version.  
  8.     $API_UserName = urlencode(‘API User Name here’); // set your spi username  
  9.     $API_Password = urlencode(‘API Passwrd Here ‘); // set your spi password  
  10.     $API_Signature = urlencode(‘API Signature here’); // set your spi Signature  
  11.       
  12.     $API_Endpoint = “https://api-3t.paypal.com/nvp”;  
  13.     if(“sandbox” === $environment || “beta-sandbox” === $environment) {  
  14.         $API_Endpoint = “https://api-3t.$environment.paypal.com/nvp”;  
  15.     }  
  16.     $version = urlencode(‘51.0’);  
  17.    
  18.     // Set the curl parameters.  
  19.     $ch = curl_init();  
  20.     curl_setopt($ch, CURLOPT_URL, $API_Endpoint);  
  21.     curl_setopt($ch, CURLOPT_VERBOSE, 1);  
  22.    
  23.     // Turn off the server and peer verification (TrustManager Concept).  
  24.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  
  25.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  
  26.    
  27.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  28.     curl_setopt($ch, CURLOPT_POST, 1);  
  29.    
  30.     // Set the API operation, version, and API signature in the request.  
  31.     $nvpreq = “METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_”;  
  32.    
  33.     // Set the request as a POST FIELD for curl.  
  34.     curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);  
  35.    
  36.     // Get response from the server.  
  37.     $httpResponse = curl_exec($ch);  
  38.    
  39.     if(!$httpResponse) {  
  40.         exit(“$methodName_ failed: “.curl_error($ch).‘(‘.curl_errno($ch).‘)’);  
  41.     }  
  42.    
  43.     // Extract the response details.  
  44.     $httpResponseAr = explode(“&”$httpResponse);  
  45.    
  46.     $httpParsedResponseAr = array();  
  47.     foreach ($httpResponseAr as $i => $value) {  
  48.         $tmpAr = explode(“=”$value);  
  49.         if(sizeof($tmpAr) > 1) {  
  50.             $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];  
  51.         }  
  52.     }  
  53.    
  54.     if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists(‘ACK’$httpParsedResponseAr)) {  
  55.         exit(“Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.”);  
  56.     }  
  57.    
  58.     return $httpParsedResponseAr;  
  59. }  
  60.    
  61. // Set request-specific fields.  
  62. $paymentType = urlencode(‘Sale’);               // ‘Authorization’ or ‘Sale’  
  63. $firstName = urlencode($_POST[‘customer_first_name’]);  
  64. $lastName = urlencode($_POST[‘customer_last_name’]);  
  65. $creditCardType = urlencode($_POST[‘customer_credit_card_type’]);  
  66. $creditCardNumber = urlencode($_POST[‘customer_credit_card_number’]);  
  67. $expDateMonth = $_POST[‘cc_expiration_month’];  
  68. // Month must be padded with leading zero  
  69. $padDateMonth = urlencode(str_pad($expDateMonth, 2, ‘0’, STR_PAD_LEFT));  
  70.    
  71. $expDateYear = urlencode($_POST[‘cc_expiration_year’]);  
  72. $cvv2Number = urlencode($_POST[‘cc_cvv2_number’]);  
  73. $address1 = urlencode($_POST[‘customer_address1’]);  
  74. $address2 = urlencode($_POST[‘customer_address2’]);  
  75. $city = urlencode($_POST[‘customer_city’]);  
  76. $state = urlencode($_POST[‘customer_state’]);  
  77. $zip = urlencode($_POST[‘customer_zip’]);  
  78. $country = urlencode($_POST[‘customer_country’]);               // US or other valid country code  
  79. $amount = urlencode($_POST[‘example_payment_amuont’]);  
  80. $currencyID = urlencode(‘USD’);                         // or other currency (‘GBP’, ‘EUR’, ‘JPY’, ‘CAD’, ‘AUD’)  
  81.    
  82. // Add request-specific fields to the request string.  
  83. $nvpStr =   “&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber”.  
  84.             “&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName”.  
  85.             “&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID”;  
  86.    
  87. // Execute the API operation; see the PPHttpPost function above.  
  88. $httpParsedResponseAr = PPHttpPost(‘DoDirectPayment’$nvpStr);  
  89.    
  90. if(“SUCCESS” == strtoupper($httpParsedResponseAr[“ACK”]) || “SUCCESSWITHWARNING” == strtoupper($httpParsedResponseAr[“ACK”])) {  
  91.     exit(‘Direct Payment Completed Successfully: ‘.print_r($httpParsedResponseAr, true));  
  92. else  {  
  93.     exit(‘DoDirectPayment failed: ‘ . print_r($httpParsedResponseAr, true));  
  94. }  
  95.    
  96. ?>  

Source : paypal.com ,mmtutorialvault.com, google search

Leave a Reply