I created a new stuff on how to put an online credit card payment on your codeigniter website using Paypal Website payment Pro DoDirectPayment and would like to share this to you, hope it helps!.
1. You need to have a paypal account and then apply for a website payment pro, just visit paypal.com (www.paypal.com) for more info.
2. You should have the paypal API Username, Password and Signature, this is important in order for the payment will be credited in your paypal account.
3. On your model, create a new file paypal.php and use my code below:
< ? php class paypal extends Model { function paypal() { // Call the Model constructor parent::Model(); } function PPHttpPost($methodName_, $nvpStr_) { // Set up your API credentials, PayPal end point, and API version. $environment = 'live'; //live or sandbox $API_UserName = urlencode('myemail.myemail.com'); //paypal api username $API_Password = urlencode('ABCDEFGHIJKLMNOP'); //paypal api password $API_Signature = urlencode('AbcdEfghijkLmNoPqrStuVwXYz'); //paypal api signature if ($environment == 'live') $subenvi = ''; else $subenvi = $environment.'.'; $API_Endpoint = 'https://api-3t.'.$subenvi.'paypal.com/nvp'; $version = urlencode('51.0'); //paypal version // Set the curl parameters. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $API_Endpoint); curl_setopt($ch, CURLOPT_VERBOSE, 1); // Turn 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); // Set the API operation, version, and API signature in the request. $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_"; // Set the request as a POST FIELD for curl. curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); // Get response from the server. $httpResponse = curl_exec($ch); if(!$httpResponse) { exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); } // Extract the 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; } // end function } //end class /* End of file paypal.php model */ /* Location: ./system/application/models/paypal.php */ /* http://www.archiemercader.com/ */ ? >
4. On your controller, create a new file checkout.php and use my code below:
< ? php class checkout extends Controller { function checkout() { parent::Controller(); } function index() { $this->load->model('paypal'); //////////////////////////////////////////////////////// //start of paypal module//////////////////////////////// //////////////////////////////////////////////////////// // Set request-specific fields. $paymentType = urlencode('Sale'); // or 'Sale' or 'Authorization' $firstName = urlencode('John'); // first name on credit card $lastName = urlencode('Doe'); // last name on credit card $creditCardType = urlencode('Visa'); // credit card type: Visa, Mastercard, American Express etc. $creditCardNumber = urlencode('4444444444444444'); // credit card number $expDateMonth = urlencode('06'); // expiry month $expDateYear = urlencode('2020'); // expiry year $cvv2Number = urlencode('123'); // cvv2 or the last 3/4 digit at the back of credit card $address1 = urlencode('address1'); // billing address1 $address2 = urlencode('address2'); // address2 $city = urlencode('city'); // city $state = 'CA'; // state $zip = urlencode('zipcode'); // zipcode $country = urlencode('country'); // US or other valid country code $currencyID = urlencode('USD'); // USD or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD') $amount = urlencode('amount'); // amount/rate // Add request-specific fields to the request string. $nvpStr = "&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber". "&EXPDATE=$expDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName". "&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID"; // Execute the API operation; see the PPHttpPost function above. $httpParsedResponseAr = $this->paypal->PPHttpPost('DoDirectPayment', $nvpStr); //TURN THIS ON TO MAKE THE PAYMENT LIVE if($httpParsedResponseAr["ACK"] == 'Success') echo 'Payment was successfully made' else echo 'Unable to process your payment '.urldecode($httpParsedResponseAr["L_SHORTMESSAGE0"]); }// end function } //end class /* End of file checkout.php */ /* Location: ./system/application/controllers/checkout.php */ /* http://www.archiemercader.com/ */ ? >
Hope it helps! if you have any questions or clarifications please leave your comments below.
Here state is static.But I need dynamic state how is possible/
will you help me configure my website payments pro for my site, seems like my code is not working.
would love if you try fixing my site so i can accept credit card payment for my site
good to hear that 😉
do you know how to integrate payments pro in php classic?
@jury clark: go ahead and share it!