Вы находитесь на странице: 1из 16

PHP Script for Paypal Website Standard Payment method opensourceprogrammer.

in
0 1 year ago by admin in Open Source, Paypal, PHP Paypal Webstie Standard Payment Method for website When we use Paypal website standard payment method for shopping cart with multiple buy item. On this method customer complete its shopping on website and the time of payment he completely move to paypal website with complete detail of his buy item name, item qty , item amount and with Total Amount. On paypal site all detail will display as display on his shopping cart. here all necessary field that is will on site like first name, address,etc. will automatically filled and here customer need to just fill their credit card and its related fields to complete the process. When customer complete the payment process then one url of success payment is also send form the site to paypal (in return input type) site will appear in form button on click on that button customer will reach to success page of website. There is on link of fail on cancel for not to complete the process. Paypal Require Code:?
<form id="form1" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="business" value="{$merchantId}" />

<!--merchant paypal id in which payment will go--> <input type="hidden" name="cmd" value="_xcart" /> <input type="hidden" name="paymentaction" value="sale" /> < ?php // $itemresult result set of customer buy item fetch form order_item table and table where final order item is store $i=1; while($row = mysql_fetch_array($itemresult)) { $amountinrupee = $row[1]; $amount = round(intval($amountinrupee)/46.180,2); ?> <input type="hidden" name="item_name_<?= $i;?/>" value="< ?= $row[0];?>" /> <input type="hidden" name="amount_<?= $i;?/>" value="< ?= $amount;?>" /> <input type="hidden" name="quantity_<?= $i;?/>" value="< ?= $row[2];?>" /> < ?php $i++;

} ?> <input type="hidden" name="first_name" value="<?=$customerfristname;?/>" /><!--customer first name --> <input type="hidden" name="last_name" value="<?= $customerlastname;?/>" /><!-customer last name --> <input type="hidden" name="address1" value="<?= $customeraddress;?/>" /><!-customer address 1 name --> <input type="hidden" name="address2" value="<?= $address2;?/>" /><!--customer add2 name --> <input type="hidden" name="email" value="<?= $cutomeremailid;?/>" /><!-customer email name --> <input type="hidden" name="city" value="<?= $customercity;?/>" /><!--customer city name --> <input type="hidden" name="state" value="<?= $customerstate;?/>" /><!-customer state name --> <input type="hidden" name="country" value="<?= $cutomercountry;?/>" /><!-customer country name --> <input type="hidden" name="zip" value="<?= $customerzipcode;?/>" /><!-customer zip name --> <input type="hidden" name="currency_code" value="USD" /><!--currrecy in which payment u need--> <input type="hidden" name="upload" value="1" /><!--paypal parameter--> <input type="hidden" name="return" value="http://www.example.com/shopcomplete.php" /> <input type="hidden" name="cancel_return" value="http://www.example.com/shopfail.php" /> </form>

1104 website standard

PHP Script For Implement PayPal Pro Method for Payment opensourceprogrammer.in
0 1 year ago by admin in Payment Gateway, Paypal, PHP Today Paypal payment gateway provide a 2 method for payment using payapal gateway service. 1. Paypal Pro Method 2. Website Standard Method Paypal Pro Method Paypal pro is most popular method of payment using paypal payment gateway. This method provide payeer not to go any anyware all payment process took place at website end user not need to move any other site or paypal site.

In this method we send all detail using CURL Service to paypal server and server verify all receive detail and verify it and send serponse in true or false means accept or error. we get that reseponse and tell user what is happen with payment. Server also return error code that tell what type of error occure at server end so pay is fail. Php Script for Using Paypa Pro Requirement for Paypal Pro 1. 2. 3. 4. 5. Curl Service should start or on apache server Magic qoutes should enable API_USERNAME :- This is provided by Papyal to register user who want that service. API_PASSWORD :- Api password is also provide by papal API_SIGNATURE :- Unique Key that identify the transaction which provide by papal

Process File:? 00 1 $paymentType = $_POST['paymentType']; 00 2 $creditCardType= $_POST['creditCardType']; //Contain information 00 about card type 3 $creditCardNumber = $_POST['creditCardNumber']; //contain 00 information about no of card 4 00 $expDateMonth = $_POST['expDateMonth']; //contain information 5 about expire month of card 00 6 $expDateYear = $_POST['expDateYear']; //contain information about 00 expire year of card 7 $cvv2Number = $_POST['cvv2Number']; //contain security code of 00 card which is card dependent 8 00 $firstname =$_POST['user_fname']; //customer first name 9 01 $lastname= $_POST['user_lname']; //customer last name 0 $addr= $_POST['address']; //customer postal address 1 01 1 $addr1= $_POST['address1']; //customer postal address 2 01 2 $city = $_POST['city']; //customer postal address city 01 3 $state = $_POST['state']; 01 4
<?php

$zipcode = $_POST['user_postalcode']; //customer postal code 01 5 $phone = $_POST['phone']; //customer phone no 01 6 $email= $_POST['user_email']; //customer Email address 01 7 $package= $_POST['pack']; //customer pack information if 01 needed 8 $a=explode('-',$package); 01 9 $cochid = $a[0]; 02 0 $amount = $a[1]; //amount to pay 02 1 $address1=$addr.$addr1; 02 2 02 define('API_USERNAME', 'paypal_pro_user name'); 3 02 define('API_PASSWORD', 'paypal_pro_user password'); 4 define('API_SIGNATURE', 'paypal given id'); 02 5 define('API_ENDPOINT', 'https://api-3t.sandbox.paypal.com/nvp'); 02 6 define('USE_PROXY',FALSE); 02 7 define('PROXY_HOST', '127.0.0.1'); 02 8 define('PROXY_PORT', '808'); 02 define('PAYPAL_URL', 9 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token='); 03 0 define('VERSION', '53.0'); 03 1 03 session_start(); 2 03 /** 3 03 * hash_call: Function to perform the API call to PayPal using API 4 signature 03 * @methodName is name of API method. 5 03 * @nvpStr is nvp string. 6 03 * returns an associtive array containing the response from the server. 7

*/ 03 8 function hash_call($methodName,$nvpStr) 03 9 { 04 0 ini_set('max_execution_time', 300); 04 1 //declaring of global variables 04 2 04 global 3 $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Head 04 4 er; 04 $API_UserName=API_USERNAME; 5 04 $API_Password=API_PASSWORD; 6 04 $API_Signature=API_SIGNATURE; 7 $API_Endpoint =API_ENDPOINT; 04 8 $version=VERSION; 04 9 //setting the curl parameters. 05 0 $ch = curl_init(); 05 1 curl_setopt($ch, CURLOPT_URL,$API_Endpoint); 05 curl_setopt($ch, CURLOPT_VERBOSE, 1); 2 05 //turning off the server and peer verification(TrustManager 3 Concept). 05 4 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 05 5 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 05 6 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 05 curl_setopt($ch, CURLOPT_POST, 1); 7 05 //if USE_PROXY constant set to TRUE in Constants.php, then only 8 proxy will be enabled. 05 9 //Set proxy name to PROXY_HOST and port number to PROXY_PORT in 06 constants.php 0

if(USE_PROXY) 06 1 //echo CURLOPT_PROXY; 06 2 curl_setopt ($ch, CURLOPT_PROXY, PROXY_HOST.":".PROXY_PORT); 06 3 //NVPRequest for submitting to server 06 4 $nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode($ver 06 sion)."&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."& 5 SIGNATURE=".urlencode($API_Signature).$nvpStr; 06 //setting the nvpreq as POST FIELD to curl 6 06 //CURLOPT_POSTFIELDS; 7 06 curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq); 8 06 //getting response from server 9 $response = curl_exec($ch); 07 0 07 //convrting NVPResponse to an Associative Array 1 07 $nvpResArray=deformatNVP($response); 2 07 $nvpReqArray=deformatNVP($nvpreq); 3 07 $_SESSION['nvpReqArray']=$nvpReqArray; 4 if (curl_errno($ch)) { 07 5 // moving to display page to display curl errors 07 6 echo $_SESSION['curl_error_no']=curl_errno($ch) ; 07 7 echo $_SESSION['curl_error_msg']=curl_error($ch); die; 07 8 $location = "APIError.php"; 07 9 header("Location: $location"); 08 } else { 0 08 //closing the curl 1 08 curl_close($ch); 2 08 } 3

08 4 return $nvpResArray; 08 5 } 08 6 08 /** This function will take NVPString and convert it to an Associative 7 Array and it will decode the response. 08 8 * It is usefull to search for a particular key and displaying arrays. 08 * @nvpstr is NVPString. 9 09 * @nvpArray is Associative Array. 0 09 */ 1 09 2 function deformatNVP($nvpstr) 09 3 { 09 4 09 5 $intial=0; 09 $nvpArray = array(); 6 09 while(strlen($nvpstr)){ 7 09 //postion of Key 8 09 $keypos= strpos($nvpstr,'='); 9 10 //position of value 0 $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): 10 strlen($nvpstr); 1 10 2 10 /*getting the Key and Value values and storing in a Associative 3 Array*/ 10 4 $keyval=substr($nvpstr,$intial,$keypos); 10 5 $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1); 10 //decoding the respose 6

10 7 10 8 10 9 11 0 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 12 0 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12 9

$nvpArray[urldecode($keyval)] =urldecode( $valval); $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr)); } return $nvpArray; }

$paymentType =urlencode( $_POST['paymentType']); $firstname =urlencode($firstname); $lastName =urlencode($lastname); $creditCardType =urlencode($creditCardType); $creditCardNumber = urlencode($creditCardNumber); $expDateMonth =urlencode( $_POST['expDateMonth']);

// Month must be padded with leading zero $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT); $expDateYear =urlencode( $_POST['expDateYear']); $cvv2Number = urlencode($_POST['cvv2Number']); $address1 = urlencode($address1);

$city = urlencode($city); $state =urlencode($state); $zipcode = urlencode($zipcode); $amount = urlencode($amount);

$currencyCode="USD"; $paymentType=urlencode($_POST['paymentType']); $nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$credit CardType&ACCT=$creditCardNumber&EXPDATE=".$padDateMonth.$expDateYear."&CVV2

13 =$cvv2Number&FIRSTNAME=$firstname&LASTNAME=$lastname&STREET=$address1&CITY= 0 $city&STATE=$state&ZIP=$zipcode&COUNTRYCODE=US&CURRENCYCODE=$currencyCode"; 13 1 /* Make the API call to PayPal, using API signature. 13 2 The API response is stored in an associative array called $resArray */ 13 3 $resArray=hash_call("doDirectPayment",$nvpstr); 13 4 /* Display the API response back to the browser. 13 5 If the response from PayPal was a success, display the response 13 parameters' 6 13 If the response was an error, display the errors received using 7 APIError.php. 13 8 */ 13 9 $ack = strtoupper($resArray["ACK"]); 14 if($ack=='FAILURE'){ 0 header("Location: errorpage.php"); 14 } 1 else{ 14 header("Location: success.php"); } 2 14 3 ?> 14 4 14 5 14 6 14 7 14 8 14 9 15 0 15 1 15 2

15 3 15 4 15 5 15 6 15 7 15 8 15 9 16 0 16 1 16 2 16 3 16 4 16 5 16 6 16 7 16 8 16 9 17 0 17 1 17 2 17 3 17 4 17 5

17 6 17 7 17 8 17 9 18 0 18 1 18 2 18 3 18 4 18 5 18 6 18 7 18 8 18 9 19 0 19 1 19 2 19 3 19 4 19 5 19 6 19 7 19 8

19 9 20 0 20 1 20 2 20 3 20 4 20 5 20 6 20 7 20 8 20 9 21 0 21 1 21 2 21 3 21 4 21 5 21 6 21 7 21 8 21 9 22 0 22 1

22 2 22 3 22 4 22 5 22 6 22 7 22 8 22 9 23 0 23 1 23 2 23 3 23 4 23 5 23 6 23 7 23 8 23 9 24 0 24 1 24 2 24 3 24 4

24 5 24 6 24 7 24 8 24 9 25 0 25 1 25 2 25 3 25 4 25 5 25 6 25 7 25 8 25 9 26 0 26 1 26 2 26 3 26 4 26 5 26 6 26 7

26 8 26 9 27 0 27 1 27 2 27 3 27 4 27 5 27 6 27 7 27 8 27 9 28 0 28 1 28 2 28 3 28 4 28 5 28 6 28 7 28 8 28 9 29 0

29 1 29 2 29 3 29 4 29 5

Вам также может понравиться