How to Use PayPal Credit Card Payment in PHP

PayPal, Credit Card Payment API (means PayPal PHP merchant SDK) deals to process a credit card payment or DoDirect Payment on your website.

PayPal Credit Card Payment works in a few steps in the merchant’s website rather than going to the actual PayPal page and then logging in and returning back to the same.

The key thing is, using PayPal Credit Card, the payment process is done on your web page only. As the name also depicts it is a direct payment.

In this blog post, we are going to explain how we can use PayPal credit card payment in PHP for Direct payment.

Watch the live demo or download code from the link given below

This is image title

Project Integration

For configuration of PayPal PHP merchant SDK, add your account credentials in the configuration.php.

You can find this file in downloaded project “root folder”.

// Demo Signature Credential
"acct1.UserName" => "Demo-facilitator_api1.outlook.com",
"acct1.Password" => "PDRdd9FTWWU6FDBNKY",
"acct1.Signature" => "ANGx9dddfhOMduIxwcbkuUqPMh-9L15RAO6JJD8BDCZSxcx8nbBWeDOIbzW1",

Then you will be ready to run the project. You can also refer the install.txt file given in the download code folder.

Note: In demo we have used Sandbox and demo VISA card for testing, for making it live you have to edit configuration.php config array mode, sandbox to live as shown below.

 $config = array(
// values: 'sandbox' for testing
// 'live' for production
"mode" => "sandbox",
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE'
);

Tutorial Scripts in detail

Below are the details of the code used in this tutorial with proper explanation.

Index.php

In index.php contain code for showing product details. Here we demonstrate simple Bag seller site. When buyers click on the Buy now button it posts product information data to getcreditcard.php page.

<html>
<head>
<title>paypal payments via credit card</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>

<div id="main">
<center><h1>PayPal Payments via Credit Card</h1></center>
<div id="main_wrapper">
<div id="container">
<h2>BEST SELLER</h2>
<hr/>
<form action="getcreditcard.php" method="POST">
<div id="product">
<img src="images/bag2.jpg"/>
<p>Tas Ransel Orange bag</p>
<h3>$21.10</h3>
<input type="hidden" value="<?php echo base64_encode(1); ?>" name="id">
<!-- <a href="#" id="buynow"> Buy Now </a> -->
<center><input type="submit" id="buynow" value="Buy Now"></center>
</div>
</form>
<form action="getcreditcard.php" method="POST">
<div id="product">
<img src="images/bag.jpg"/>
<p>Tas Ransel Jeans bag</p>
<h3>$15.20</h3>
<input type="hidden" value="<?php echo base64_encode(2); ?>" name="id">
<!-- <a href="#" id="buynow"> Buy Now </a> -->
<center><input type="submit" id="buynow" value="Buy Now"></center>
</div>
</form>
<form action="getcreditcard.php" method="POST">
<div id="product">
<img src="images/bag4.jpg"/>
<p>Tas Ransel grey bag</p>
<h3>$11.10</h3>
<input type="hidden" value="<?php echo base64_encode(3); ?>" name="id">
<!-- <a href="#" id="buynow"> Buy Now </a> -->
<center><input type="submit" id="buynow" value="Buy Now"></center>
</div>
</form>
</div>
</div>
<img id="paypal_logo" style="float:right; margin: -30px -42px 0 0;" src="images/secure-paypal-logo.jpg">
</div>
</body>
</html>

Getcreditcard.php

Getcreditcard.php page get credit card details and billing address and post all information to DoDirectPayment.php.

<?php
//Decode product id
//If you want to use Database fetch product data by id here
if (base64_decode($_POST['id']) == 1) {
$p_price = 21.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel Orange bag';
} else if (base64_decode($_POST['id']) == 2) {
$p_price = 15.20;
$p_currency = 'USD';
$p_name = 'Tas Ransel Jeans bag';
} else if (base64_decode($_POST['id']) == 3) {
$p_price = 11.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel grey bag';
}
?>
<html>
<head>
<title>paypal payments via credit card</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/loadding.css">
<link rel="stylesheet" type="text/css" href="css/popup-style.css">
</head>
<body>

<div id="main">
<center><h1>PayPal Payments via Credit Card</h1></center>
<form action="DoDirectPayment.php" method="POST">
<div id="container">
<h2>Pay with my debit or credit card</h2>
<hr/>
<center> <h3>Billing Information</h3></center>
<input type="hidden" name="paymentType" value="Sale"/>
<input type="hidden" name="id" value="<?php echo $_POST['id']; ?>"/>
<table style="width:100%">
<tr>
<td id="td-label">First name : </td>
<td><input type="text" name="firstName" id="name" placeholder="enter first name"></td>

</tr>
<tr>
<td id="td-label">Last name : </td>
<td><input type="text" name="lastName" id="name" placeholder="enter last name"></td>

</tr>
<tr>
<td id="td-label">Card type : </td>
<td>
<select name="creditCardType">
<option value="Visa" selected="selected">Visa</option>
<option value="MasterCard">MasterCard</option>
<option value="Discover">Discover</option>
<option value="Amex">American Express</option>
</select>
</td>

</tr>
<tr>

<td id="td-label">Card number : </td>
<td><input type="text" name="creditCardNumber" id="cardno" placeholder="enter card number" required="true"></td>

</tr>

<tr>

<td id="td-label">Expiry date : </td>
<td><div id="date-div"><select name="expDateMonth">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select></div>
<div id="year-div">
<select name="expDateYear">
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div></td>
</tr>
<tr>
<td id="td-label">CVV : </td>
<td><div id="date-div"><input type="text" name="cvv2Number" id="cvv" placeholder="cvv" required="true"></div></td>
</tr>
<tr>
<td id="td-label">Amount( USD ) : </td>
<td><input type="text" name="amount" id="name" placeholder="enter amount " value="<?php echo $p_price; ?>" disabled="true"></td>

</tr>
</table>
<center> <h3>Billing address</h3></center>
<table style="width:100%">
<tr>
<td id="td-label">Address 1 : </td>
<td><input type="text" name="address1" id="name" placeholder="enter address "></td>

</tr>
<tr>
<td id="td-label">Address 2 : </td>
<td><input type="text" name="address2" id="name" placeholder="enter address"></td>

</tr>
<tr>
<td id="td-label">City : </td>
<td><input type="text" name="city" id="name" placeholder="enter city name"></td>

</tr>
<tr>
<td id="td-label">State : </td>
<td>
<div id="date-div">
<select id="state" name="state">
<option value=""></option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA" selected="">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DC">DC</option>
<option value="DE">DE</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="IA">IA</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="MA">MA</option>
<option value="MD">MD</option>
<option value="ME">ME</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MO">MO</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="NE">NE</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="NY">NY</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VA">VA</option>
<option value="VT">VT</option>
<option value="WA">WA</option>
<option value="WI">WI</option>
<option value="WV">WV</option>
<option value="WY">WY</option>
<option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AS">AS</option>
<option value="FM">FM</option>
<option value="GU">GU</option>
<option value="MH">MH</option>
<option value="MP">MP</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="VI">VI</option>
</select>

</div>
</td>

</tr>
<tr>
<td id="td-label">Zip code : </td>
<td>
<input type="text" name="zip" id="name" placeholder="enter zip code (5 or 9 digits)">
</td>
</tr>
<tr>
<td id="td-label">Country : </td>
<td><input type="text" name="country" id="name" placeholder="enter country name"></td>
</tr>
<tr>
<td id="td-label">Phone Number : </td>
<td><input type="text" name="phone" id="name" placeholder="enter Phone number "></td>
</tr>
</table><br>
<center><!--<a href="#" id="paynow"> Pay Now </a>--><input style=" width: 20%;"type="submit" id="buynow" name="DoDirectPaymentBtn" value="Pay Now"></center><br>
</div>
</form>
<img id="paypal_logo" style="float:right; margin: -30px -42px 0 0;" src="images/secure-paypal-logo.jpg">
</div>
<div id="pop2" class="simplePopup">
<div id="loader">
<div id="circularG">
<div id="circularG_1" class="circularG">
</div>
<div id="circularG_2" class="circularG">
</div>
<div id="circularG_3" class="circularG">
</div>
<div id="circularG_4" class="circularG">
</div>
<div id="circularG_5" class="circularG">
</div>
<div id="circularG_6" class="circularG">
</div>
<div id="circularG_7" class="circularG">
</div>
<div id="circularG_8" class="circularG">
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.simplePopup.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('input#buynow').click(function() {
if ($('input#cardno').val() != '') {
if ($('input#cvv').val() != '') {
$('#pop2').simplePopup();
}
}

});
});
</script>
</body>
</html>

DoDirectPayment.php

DoDirectPayment.php take all posted data and process to PayPal for payment.

<?php
/* * *********************************************************
DoDirectPayment.php
Submits a credit card transaction to PayPal using a
DoDirectPayment request.
* ********************************************************* */
session_start();
require_once('../PPBootStrap.php');

if (base64_decode($_POST['id']) == 1) {
$p_price = 21.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel Orange bag';
} else if (base64_decode($_POST['id']) == 2) {
$p_price = 15.20;
$p_currency = 'USD';
$p_name = 'Tas Ransel Jeans bag';
} else if (base64_decode($_POST['id']) == 3) {
$p_price = 11.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel grey bag';
}
/**
* Get required parameters from the web form for the request
*/
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];

/*
* shipping adress
*/
$address = new AddressType();
$address->Name = "$firstName $lastName";
$address->Street1 = $_POST['address1'];
$address->Street2 = $_POST['address2'];
$address->CityName = $_POST['city'];
$address->StateOrProvince = $_POST['state'];
$address->PostalCode = $_POST['zip'];
$address->Country = $_POST['country'];
$address->Phone = $_POST['phone'];
$orderTotal = new BasicAmountType();
$orderTotal->currencyID = $p_currency;
$orderTotal->value = $p_price;

$paymentDetails = new PaymentDetailsType();
$paymentDetails->ShipToAddress = $address;

$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $p_name;

$itemDetails->Amount = $orderTotal;
/*
* Item quantity. This field is required when you pass a value for ItemCategory.
*/
$itemDetails->Quantity = '1';
/*
* Indicates whether an item is digital or physical.
*/
$itemDetails->ItemCategory = 'Physical';

$paymentDetails->PaymentDetailsItem[0] = $itemDetails;
$paymentDetails->OrderTotal = $orderTotal;
if (isset($_REQUEST['notifyURL'])) {
$paymentDetails->NotifyURL = $_REQUEST['notifyURL'];
}

$personName = new PersonNameType();
$personName->FirstName = $firstName;
$personName->LastName = $lastName;

//information about the payer
$payer = new PayerInfoType();
$payer->PayerName = $personName;
$payer->Address = $address;
$payer->PayerCountry = $_POST['country'];

$cardDetails = new CreditCardDetailsType();
$cardDetails->CreditCardNumber = $_POST['creditCardNumber'];
/*
*
Type of credit card. For UK, only Maestro, MasterCard, Discover, and
Visa are allowable. For Canada, only MasterCard and Visa are
allowable and Interac debit cards are not supported. It is one of the
following values:

* Visa
* MasterCard
* Discover
* Amex
* Solo
* Switch
* Maestro: See note.
`Note:
If the credit card type is Maestro, you must set currencyId to GBP.
In addition, you must specify either StartMonth and StartYear or
IssueNumber.`
*/
$cardDetails->CreditCardType = $_POST['creditCardType'];
$cardDetails->ExpMonth = $_POST['expDateMonth'];
$cardDetails->ExpYear = $_POST['expDateYear'];
$cardDetails->CVV2 = $_POST['cvv2Number'];
$cardDetails->CardOwner = $payer;

$ddReqDetails = new DoDirectPaymentRequestDetailsType();
$ddReqDetails->CreditCard = $cardDetails;
$ddReqDetails->PaymentDetails = $paymentDetails;
$ddReqDetails->PaymentAction = $_REQUEST['paymentType'];

$doDirectPaymentReq = new DoDirectPaymentReq();
$doDirectPaymentReq->DoDirectPaymentRequest = new DoDirectPaymentRequestType($ddReqDetails);

/*
* ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Configuration::getAcctAndConfig() returns array that contains credential and config parameters
*/
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
try {
/* wrap API method calls on the service object with a try catch */
$doDirectPaymentResponse = $paypalService->DoDirectPayment($doDirectPaymentReq);
} catch (Exception $ex) {
include_once("../Error.php");
exit;
}
if (isset($doDirectPaymentResponse)) {
?>
<html>
<head>
<title>paypal payments via credit card</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>

<div id="main">
<div class="success_main_heading">
<center><h1>PayPal Payments via Credit Card</h1></center>
</div>
<div id="return">
<h2>Refund Status</h2>
<hr/>
<?php
//Rechecking the product price and currency details
if ($doDirectPaymentResponse->Ack == 'Success') {
echo "<h3 id='success'>Payment Successful</h3>";
echo "<P>Amount -" . $doDirectPaymentResponse->Amount->value . " (" . $doDirectPaymentResponse->Amount->currencyID . ")</P>";
echo "<P>Transaction ID -" . $doDirectPaymentResponse->TransactionID . "</P>";
echo "<div class='back_btn'><a href='index.php' id= 'btn'><< Back </a></div>";
} else {
echo "<h3 id='fail'>Payment - Failed</h3>";
echo '<p>Error msg - This transaction cannot be processed. <br>Please enter a valid credit card number and type.</p>';
echo "<div class='back_btn'><a href='index.php' id= 'btn'><< Back </a></div>";
}
?>
</div>
</div>
</body>
</html>
<?php
}
?>

Style.css

Includes basic styling of HTML elements.

/*----------------------------------------------
css settings for HTML div exactCenter
------------------------------------------------*/
@import url(http://fonts.googleapis.com/css?family=Raleway);
#main{
width:960px;
margin:50px auto;
font-family:raleway;
}
span{
color:red;
}
h2{
background-color: #FEFFED;
text-align:center;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px;
}
hr{
border:0;
border-bottom:1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px;
}
#main_wrapper{
width: 100%;
}
#container{
width: 100%;
float: left;
border-radius: 10px;
font-family:raleway;
border: 2px solid #ccc;
padding: 10px 40px 25px;
margin-top: 22px;
margin-bottom: 40px;
margin-left: -42px;
}
input[type=text],input[type=password],select{
width: 50.5%;
padding: 10px;
margin-top: 8px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
font-family:raleway;
}
#buynow{
width: 50%;
background-color:#FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 10px;
font-size:20px;
cursor:pointer;
border-radius: 5px;
margin-bottom: 15px;
}
a#paynow{
/* width: 72%; */
background-color:#FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 15px 60px;
font-size:20px;
cursor:pointer;
border-radius: 5px;
/* margin: 0 0 0 394px; */
}
#profile{
padding:50px;
border:1px dashed grey;
font-size:20px;
background-color:#DCE6F7;
}

a{
text-decoration:none;
color: cornflowerblue;
}

i{
color: cornflowerblue;
}
#product{

width: 272px;
height: 500px;
border:1px solid #E7E7E5;
float: left;
margin-left: 34px;
}
#product p{
text-align: center;
margin-top: 30px;
}
#product h3{
text-align: center;
margin-top: -12px;
margin-bottom: 25px;
}
#product a{
text-align: center;
margin: 0 0 0 80px;
}
#td-label{
text-align: right;
font-weight: bold;
}
#date-div{
width: 28%;
/* height: 20px; */
/* border: 1px solid red; */
float: left;
}
#year-div{
width: 30%;
/* height: 31px; */
/* border: 1px solid red; */
float: left;
margin-left: -59px;
}
#product input[type=submit]{
text-align: center;
}
#return {
width: 492px;
height: 350px;
float: left;
border-radius: 10px;
font-family: raleway;
border: 2px solid #ccc;
padding: 10px 40px 11px;
}
#return h3#success {
text-align: center;
font-size: 24px;
margin-top: 50px;
color: green;
}
#return P {
text-align: center;
}
#return .back_btn {
margin-top: 51px;
text-align: center;
}
#btn {
width: 100%;
background-color: #FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 10px 70px;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
margin-bottom: 15px;
margin: 0 auto;
}
a{
text-decoration:none;
color: cornflowerblue;
}
img#paypal_logo {
float: right;
margin-right: 20px;
margin-top: 1%;
padding-bottom: 15px;
}
.success_main_heading{
margin-left: -32%;
margin-bottom: 7%;

}
#return h3#fail{
text-align: center;
font-size: 24px;
margin-top: 50px;
color: red;
}
.red{
color:red;
font-weight: bold;
}

Conclusion :

Using the script will help you to collect the online payment using credit card via Paypal. Hope you will be benefited with that. Please share your feedback in the space provided below.

Thank you !

#PHP #PayPal #Payment #Webdev

What is GEEK

Buddha Community

How to Use PayPal Credit Card Payment in PHP

Credit card fraud and technical solutions

Credit card fraud is an increasingly expensive problem. Technology offers solutions to help combat the problem and gain control.
How to prevent fraudulent transactions in credit cards is a common question plaguing the credit card user today. The credit card brings convenience and security to the users, but the same can become a cause of agony if the user is a victim of any credit card fraud. Smart systems are coming to the aid of credit card users and empowering them against cybercriminals. Using fraud detection tools and following some simple precautions, the users can protect themselves against credit card fraud.

#credit card fraud detection #types of credit card fraud #contactless payment systems #technological challenges in credit card fraud #prevent fraudulent transactions in credit cards

How to Use PayPal Credit Card Payment in PHP

PayPal, Credit Card Payment API (means PayPal PHP merchant SDK) deals to process a credit card payment or DoDirect Payment on your website.

PayPal Credit Card Payment works in a few steps in the merchant’s website rather than going to the actual PayPal page and then logging in and returning back to the same.

The key thing is, using PayPal Credit Card, the payment process is done on your web page only. As the name also depicts it is a direct payment.

In this blog post, we are going to explain how we can use PayPal credit card payment in PHP for Direct payment.

Watch the live demo or download code from the link given below

This is image title

Project Integration

For configuration of PayPal PHP merchant SDK, add your account credentials in the configuration.php.

You can find this file in downloaded project “root folder”.

// Demo Signature Credential
"acct1.UserName" => "Demo-facilitator_api1.outlook.com",
"acct1.Password" => "PDRdd9FTWWU6FDBNKY",
"acct1.Signature" => "ANGx9dddfhOMduIxwcbkuUqPMh-9L15RAO6JJD8BDCZSxcx8nbBWeDOIbzW1",

Then you will be ready to run the project. You can also refer the install.txt file given in the download code folder.

Note: In demo we have used Sandbox and demo VISA card for testing, for making it live you have to edit configuration.php config array mode, sandbox to live as shown below.

 $config = array(
// values: 'sandbox' for testing
// 'live' for production
"mode" => "sandbox",
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE'
);

Tutorial Scripts in detail

Below are the details of the code used in this tutorial with proper explanation.

Index.php

In index.php contain code for showing product details. Here we demonstrate simple Bag seller site. When buyers click on the Buy now button it posts product information data to getcreditcard.php page.

<html>
<head>
<title>paypal payments via credit card</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>

<div id="main">
<center><h1>PayPal Payments via Credit Card</h1></center>
<div id="main_wrapper">
<div id="container">
<h2>BEST SELLER</h2>
<hr/>
<form action="getcreditcard.php" method="POST">
<div id="product">
<img src="images/bag2.jpg"/>
<p>Tas Ransel Orange bag</p>
<h3>$21.10</h3>
<input type="hidden" value="<?php echo base64_encode(1); ?>" name="id">
<!-- <a href="#" id="buynow"> Buy Now </a> -->
<center><input type="submit" id="buynow" value="Buy Now"></center>
</div>
</form>
<form action="getcreditcard.php" method="POST">
<div id="product">
<img src="images/bag.jpg"/>
<p>Tas Ransel Jeans bag</p>
<h3>$15.20</h3>
<input type="hidden" value="<?php echo base64_encode(2); ?>" name="id">
<!-- <a href="#" id="buynow"> Buy Now </a> -->
<center><input type="submit" id="buynow" value="Buy Now"></center>
</div>
</form>
<form action="getcreditcard.php" method="POST">
<div id="product">
<img src="images/bag4.jpg"/>
<p>Tas Ransel grey bag</p>
<h3>$11.10</h3>
<input type="hidden" value="<?php echo base64_encode(3); ?>" name="id">
<!-- <a href="#" id="buynow"> Buy Now </a> -->
<center><input type="submit" id="buynow" value="Buy Now"></center>
</div>
</form>
</div>
</div>
<img id="paypal_logo" style="float:right; margin: -30px -42px 0 0;" src="images/secure-paypal-logo.jpg">
</div>
</body>
</html>

Getcreditcard.php

Getcreditcard.php page get credit card details and billing address and post all information to DoDirectPayment.php.

<?php
//Decode product id
//If you want to use Database fetch product data by id here
if (base64_decode($_POST['id']) == 1) {
$p_price = 21.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel Orange bag';
} else if (base64_decode($_POST['id']) == 2) {
$p_price = 15.20;
$p_currency = 'USD';
$p_name = 'Tas Ransel Jeans bag';
} else if (base64_decode($_POST['id']) == 3) {
$p_price = 11.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel grey bag';
}
?>
<html>
<head>
<title>paypal payments via credit card</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/loadding.css">
<link rel="stylesheet" type="text/css" href="css/popup-style.css">
</head>
<body>

<div id="main">
<center><h1>PayPal Payments via Credit Card</h1></center>
<form action="DoDirectPayment.php" method="POST">
<div id="container">
<h2>Pay with my debit or credit card</h2>
<hr/>
<center> <h3>Billing Information</h3></center>
<input type="hidden" name="paymentType" value="Sale"/>
<input type="hidden" name="id" value="<?php echo $_POST['id']; ?>"/>
<table style="width:100%">
<tr>
<td id="td-label">First name : </td>
<td><input type="text" name="firstName" id="name" placeholder="enter first name"></td>

</tr>
<tr>
<td id="td-label">Last name : </td>
<td><input type="text" name="lastName" id="name" placeholder="enter last name"></td>

</tr>
<tr>
<td id="td-label">Card type : </td>
<td>
<select name="creditCardType">
<option value="Visa" selected="selected">Visa</option>
<option value="MasterCard">MasterCard</option>
<option value="Discover">Discover</option>
<option value="Amex">American Express</option>
</select>
</td>

</tr>
<tr>

<td id="td-label">Card number : </td>
<td><input type="text" name="creditCardNumber" id="cardno" placeholder="enter card number" required="true"></td>

</tr>

<tr>

<td id="td-label">Expiry date : </td>
<td><div id="date-div"><select name="expDateMonth">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select></div>
<div id="year-div">
<select name="expDateYear">
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div></td>
</tr>
<tr>
<td id="td-label">CVV : </td>
<td><div id="date-div"><input type="text" name="cvv2Number" id="cvv" placeholder="cvv" required="true"></div></td>
</tr>
<tr>
<td id="td-label">Amount( USD ) : </td>
<td><input type="text" name="amount" id="name" placeholder="enter amount " value="<?php echo $p_price; ?>" disabled="true"></td>

</tr>
</table>
<center> <h3>Billing address</h3></center>
<table style="width:100%">
<tr>
<td id="td-label">Address 1 : </td>
<td><input type="text" name="address1" id="name" placeholder="enter address "></td>

</tr>
<tr>
<td id="td-label">Address 2 : </td>
<td><input type="text" name="address2" id="name" placeholder="enter address"></td>

</tr>
<tr>
<td id="td-label">City : </td>
<td><input type="text" name="city" id="name" placeholder="enter city name"></td>

</tr>
<tr>
<td id="td-label">State : </td>
<td>
<div id="date-div">
<select id="state" name="state">
<option value=""></option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA" selected="">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DC">DC</option>
<option value="DE">DE</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="IA">IA</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="MA">MA</option>
<option value="MD">MD</option>
<option value="ME">ME</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MO">MO</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="NE">NE</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="NY">NY</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VA">VA</option>
<option value="VT">VT</option>
<option value="WA">WA</option>
<option value="WI">WI</option>
<option value="WV">WV</option>
<option value="WY">WY</option>
<option value="AA">AA</option>
<option value="AE">AE</option>
<option value="AP">AP</option>
<option value="AS">AS</option>
<option value="FM">FM</option>
<option value="GU">GU</option>
<option value="MH">MH</option>
<option value="MP">MP</option>
<option value="PR">PR</option>
<option value="PW">PW</option>
<option value="VI">VI</option>
</select>

</div>
</td>

</tr>
<tr>
<td id="td-label">Zip code : </td>
<td>
<input type="text" name="zip" id="name" placeholder="enter zip code (5 or 9 digits)">
</td>
</tr>
<tr>
<td id="td-label">Country : </td>
<td><input type="text" name="country" id="name" placeholder="enter country name"></td>
</tr>
<tr>
<td id="td-label">Phone Number : </td>
<td><input type="text" name="phone" id="name" placeholder="enter Phone number "></td>
</tr>
</table><br>
<center><!--<a href="#" id="paynow"> Pay Now </a>--><input style=" width: 20%;"type="submit" id="buynow" name="DoDirectPaymentBtn" value="Pay Now"></center><br>
</div>
</form>
<img id="paypal_logo" style="float:right; margin: -30px -42px 0 0;" src="images/secure-paypal-logo.jpg">
</div>
<div id="pop2" class="simplePopup">
<div id="loader">
<div id="circularG">
<div id="circularG_1" class="circularG">
</div>
<div id="circularG_2" class="circularG">
</div>
<div id="circularG_3" class="circularG">
</div>
<div id="circularG_4" class="circularG">
</div>
<div id="circularG_5" class="circularG">
</div>
<div id="circularG_6" class="circularG">
</div>
<div id="circularG_7" class="circularG">
</div>
<div id="circularG_8" class="circularG">
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.simplePopup.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('input#buynow').click(function() {
if ($('input#cardno').val() != '') {
if ($('input#cvv').val() != '') {
$('#pop2').simplePopup();
}
}

});
});
</script>
</body>
</html>

DoDirectPayment.php

DoDirectPayment.php take all posted data and process to PayPal for payment.

<?php
/* * *********************************************************
DoDirectPayment.php
Submits a credit card transaction to PayPal using a
DoDirectPayment request.
* ********************************************************* */
session_start();
require_once('../PPBootStrap.php');

if (base64_decode($_POST['id']) == 1) {
$p_price = 21.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel Orange bag';
} else if (base64_decode($_POST['id']) == 2) {
$p_price = 15.20;
$p_currency = 'USD';
$p_name = 'Tas Ransel Jeans bag';
} else if (base64_decode($_POST['id']) == 3) {
$p_price = 11.10;
$p_currency = 'USD';
$p_name = 'Tas Ransel grey bag';
}
/**
* Get required parameters from the web form for the request
*/
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];

/*
* shipping adress
*/
$address = new AddressType();
$address->Name = "$firstName $lastName";
$address->Street1 = $_POST['address1'];
$address->Street2 = $_POST['address2'];
$address->CityName = $_POST['city'];
$address->StateOrProvince = $_POST['state'];
$address->PostalCode = $_POST['zip'];
$address->Country = $_POST['country'];
$address->Phone = $_POST['phone'];
$orderTotal = new BasicAmountType();
$orderTotal->currencyID = $p_currency;
$orderTotal->value = $p_price;

$paymentDetails = new PaymentDetailsType();
$paymentDetails->ShipToAddress = $address;

$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $p_name;

$itemDetails->Amount = $orderTotal;
/*
* Item quantity. This field is required when you pass a value for ItemCategory.
*/
$itemDetails->Quantity = '1';
/*
* Indicates whether an item is digital or physical.
*/
$itemDetails->ItemCategory = 'Physical';

$paymentDetails->PaymentDetailsItem[0] = $itemDetails;
$paymentDetails->OrderTotal = $orderTotal;
if (isset($_REQUEST['notifyURL'])) {
$paymentDetails->NotifyURL = $_REQUEST['notifyURL'];
}

$personName = new PersonNameType();
$personName->FirstName = $firstName;
$personName->LastName = $lastName;

//information about the payer
$payer = new PayerInfoType();
$payer->PayerName = $personName;
$payer->Address = $address;
$payer->PayerCountry = $_POST['country'];

$cardDetails = new CreditCardDetailsType();
$cardDetails->CreditCardNumber = $_POST['creditCardNumber'];
/*
*
Type of credit card. For UK, only Maestro, MasterCard, Discover, and
Visa are allowable. For Canada, only MasterCard and Visa are
allowable and Interac debit cards are not supported. It is one of the
following values:

* Visa
* MasterCard
* Discover
* Amex
* Solo
* Switch
* Maestro: See note.
`Note:
If the credit card type is Maestro, you must set currencyId to GBP.
In addition, you must specify either StartMonth and StartYear or
IssueNumber.`
*/
$cardDetails->CreditCardType = $_POST['creditCardType'];
$cardDetails->ExpMonth = $_POST['expDateMonth'];
$cardDetails->ExpYear = $_POST['expDateYear'];
$cardDetails->CVV2 = $_POST['cvv2Number'];
$cardDetails->CardOwner = $payer;

$ddReqDetails = new DoDirectPaymentRequestDetailsType();
$ddReqDetails->CreditCard = $cardDetails;
$ddReqDetails->PaymentDetails = $paymentDetails;
$ddReqDetails->PaymentAction = $_REQUEST['paymentType'];

$doDirectPaymentReq = new DoDirectPaymentReq();
$doDirectPaymentReq->DoDirectPaymentRequest = new DoDirectPaymentRequestType($ddReqDetails);

/*
* ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Configuration::getAcctAndConfig() returns array that contains credential and config parameters
*/
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
try {
/* wrap API method calls on the service object with a try catch */
$doDirectPaymentResponse = $paypalService->DoDirectPayment($doDirectPaymentReq);
} catch (Exception $ex) {
include_once("../Error.php");
exit;
}
if (isset($doDirectPaymentResponse)) {
?>
<html>
<head>
<title>paypal payments via credit card</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>

<div id="main">
<div class="success_main_heading">
<center><h1>PayPal Payments via Credit Card</h1></center>
</div>
<div id="return">
<h2>Refund Status</h2>
<hr/>
<?php
//Rechecking the product price and currency details
if ($doDirectPaymentResponse->Ack == 'Success') {
echo "<h3 id='success'>Payment Successful</h3>";
echo "<P>Amount -" . $doDirectPaymentResponse->Amount->value . " (" . $doDirectPaymentResponse->Amount->currencyID . ")</P>";
echo "<P>Transaction ID -" . $doDirectPaymentResponse->TransactionID . "</P>";
echo "<div class='back_btn'><a href='index.php' id= 'btn'><< Back </a></div>";
} else {
echo "<h3 id='fail'>Payment - Failed</h3>";
echo '<p>Error msg - This transaction cannot be processed. <br>Please enter a valid credit card number and type.</p>';
echo "<div class='back_btn'><a href='index.php' id= 'btn'><< Back </a></div>";
}
?>
</div>
</div>
</body>
</html>
<?php
}
?>

Style.css

Includes basic styling of HTML elements.

/*----------------------------------------------
css settings for HTML div exactCenter
------------------------------------------------*/
@import url(http://fonts.googleapis.com/css?family=Raleway);
#main{
width:960px;
margin:50px auto;
font-family:raleway;
}
span{
color:red;
}
h2{
background-color: #FEFFED;
text-align:center;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px;
}
hr{
border:0;
border-bottom:1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px;
}
#main_wrapper{
width: 100%;
}
#container{
width: 100%;
float: left;
border-radius: 10px;
font-family:raleway;
border: 2px solid #ccc;
padding: 10px 40px 25px;
margin-top: 22px;
margin-bottom: 40px;
margin-left: -42px;
}
input[type=text],input[type=password],select{
width: 50.5%;
padding: 10px;
margin-top: 8px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
font-family:raleway;
}
#buynow{
width: 50%;
background-color:#FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 10px;
font-size:20px;
cursor:pointer;
border-radius: 5px;
margin-bottom: 15px;
}
a#paynow{
/* width: 72%; */
background-color:#FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 15px 60px;
font-size:20px;
cursor:pointer;
border-radius: 5px;
/* margin: 0 0 0 394px; */
}
#profile{
padding:50px;
border:1px dashed grey;
font-size:20px;
background-color:#DCE6F7;
}

a{
text-decoration:none;
color: cornflowerblue;
}

i{
color: cornflowerblue;
}
#product{

width: 272px;
height: 500px;
border:1px solid #E7E7E5;
float: left;
margin-left: 34px;
}
#product p{
text-align: center;
margin-top: 30px;
}
#product h3{
text-align: center;
margin-top: -12px;
margin-bottom: 25px;
}
#product a{
text-align: center;
margin: 0 0 0 80px;
}
#td-label{
text-align: right;
font-weight: bold;
}
#date-div{
width: 28%;
/* height: 20px; */
/* border: 1px solid red; */
float: left;
}
#year-div{
width: 30%;
/* height: 31px; */
/* border: 1px solid red; */
float: left;
margin-left: -59px;
}
#product input[type=submit]{
text-align: center;
}
#return {
width: 492px;
height: 350px;
float: left;
border-radius: 10px;
font-family: raleway;
border: 2px solid #ccc;
padding: 10px 40px 11px;
}
#return h3#success {
text-align: center;
font-size: 24px;
margin-top: 50px;
color: green;
}
#return P {
text-align: center;
}
#return .back_btn {
margin-top: 51px;
text-align: center;
}
#btn {
width: 100%;
background-color: #FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 10px 70px;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
margin-bottom: 15px;
margin: 0 auto;
}
a{
text-decoration:none;
color: cornflowerblue;
}
img#paypal_logo {
float: right;
margin-right: 20px;
margin-top: 1%;
padding-bottom: 15px;
}
.success_main_heading{
margin-left: -32%;
margin-bottom: 7%;

}
#return h3#fail{
text-align: center;
font-size: 24px;
margin-top: 50px;
color: red;
}
.red{
color:red;
font-weight: bold;
}

Conclusion :

Using the script will help you to collect the online payment using credit card via Paypal. Hope you will be benefited with that. Please share your feedback in the space provided below.

Thank you !

#PHP #PayPal #Payment #Webdev

Christa  Stehr

Christa Stehr

1595288376

How to use highchart in php with example

Highchart provides feature to draw different type of charts in our web application. Here, in this example i will let you know that how to use highchart in php application.

In this example, we will create chart using php and mysql. Actually highchart provides javascript library to create charts. We will only need to implement that library in our application.

We will need some data to generate chart, so here we will use mysql database and database query to fetch data from database.

So basucally here we will leran to implement simple dynamic column chart using highcharts library in php and ofcourse will use mysql database.

For for that, first thing we will need to create a database and tables where we will put some data. So for full example let’s follow the steps as given below.

Step 1: Create Database

Here for example, i will create a database named shopping and under this database we will need to create some tables, here i will create only two table one is to stroe customers information and another to store orders.

So run the following query in your query window.

Create customers table

CREATE TABLE IF NOT EXISTS `customers` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(30) NOT NULL,

  `email` varchar(30) NOT NULL,

  `phone` varchar(15) NOT NULL,

  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

Now you will to put some data into these two tables. You can put any data accoring to the column and your need. After putting data we can be able to show the chart according the the data.

Step 2: Create database configuration

Now we will need to create configuration file. So let’s create a new db configuration file **db_config.php **and put the following code into this file.

db_config.php

<?php
  $dbHost = "localhost";
  $dbDatabase = "shopping";
  $dbUser = "root";
        $dbPassword = ""; 

  $mysqli = mysqli_connect($dbHost, $dbUser, $dbPasswrod, $dbDatabase);
?>

#php #create highchart in php #generate highchart in php #high chart using php and mysql example #highchart example #how to implement high chart in php #how to use highchart

I am Developer

1597487472

Country State City Dropdown list in PHP MySQL PHP

Here, i will show you how to populate country state city in dropdown list in php mysql using ajax.

Country State City Dropdown List in PHP using Ajax

You can use the below given steps to retrieve and display country, state and city in dropdown list in PHP MySQL database using jQuery ajax onchange:

  • Step 1: Create Country State City Table
  • Step 2: Insert Data Into Country State City Table
  • Step 3: Create DB Connection PHP File
  • Step 4: Create Html Form For Display Country, State and City Dropdown
  • Step 5: Get States by Selected Country from MySQL Database in Dropdown List using PHP script
  • Step 6: Get Cities by Selected State from MySQL Database in DropDown List using PHP script

https://www.tutsmake.com/country-state-city-database-in-mysql-php-ajax/

#country state city drop down list in php mysql #country state city database in mysql php #country state city drop down list using ajax in php #country state city drop down list using ajax in php demo #country state city drop down list using ajax php example #country state city drop down list in php mysql ajax

I am Developer

1599190536

How to Store Form Data in Database using PHP -2020

In this php code to insert form data into mysql database. I will show you simple way of how to create an html form that stores data in a mysql database using php.

#How to store form data in database using php

  1. Create html form
  2. Create mysql database connection file
  3. Create php file to insert form data into mysql database

https://www.tutsmake.com/php-code-insert-data-into-mysql-database-from-form/

#php code for inserting data into database from form #how to insert data in mysql using php form #how to insert data into database in php using xampp #how to save data from html form to a database using php #how to save data in database on button click in php