Code Paypal Express Checkout Integration with PHP
php code / September 7, 2018
Step By Step
Step 1 : Created header.php this code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css”>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css”>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js”></script>
<script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js”></script>
<!– jQuery –>
Step 2 : Created Footer.php This Code
<div class=”insert-post-ads1″ style=”margin-top:20px;”>
</div>
</div>
</body></html>
Step 3 : Created container.php File This is Code
</head>
<body class=””>
<div role=”navigation” class=”navbar navbar-default navbar-static-top”>
<div class=”container”>
<div class=”navbar-header”>
<button data-target=”.navbar-collapse” data-toggle=”collapse” class=”navbar-toggle” type=”button”>
<span class=”sr-only”>Toggle navigation</span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
</button>
<a href=”https://phpcodeinfomation.blogspot.com/p/php-script.html” class=”navbar-brand”>PHPCODE</a>
</div>
<div class=”navbar-collapse collapse”>
<ul class=”nav navbar-nav”>
<li class=”active”><a href=”https://phpcodeinfomation.blogspot.com/p/php-script.html”>Home</a></li>
</ul>
</div><!–/.nav-collapse –>
</div>
</div>
<div class=”container” style=”min-height:500px;”>
<div class=”>
</div>
Step 4 : Created index.php File This is Code
<?php
include(‘header.php’);
include(‘config.php’);
$productName = “Demo Product”;
$currency = “USD”;
$productPrice = 10;
$productId = 123456;
$orderNumber = 000999;
?>
<title>phpcode : Code Paypal Express Checkout Integration with PHP</title>
<?php include(‘container.php’);?>
<div class=”container”>
<h2>Paypal Express Checkout Demo with PHP</h2>
<br>
<table class=”table”>
<tr>
<td style=”width:150px”><img src=”demo_product.png” style=”width:50px” /></td>
<td style=”width:150px”>$<?php echo $productPrice; ?></td>
<td style=”width:150px”>
<?php include ‘paypalCheckout.php’; ?>
</td>
</tr>
</table>
<div style=”margin:50px 0px 0px 0px;”>
<a class=”btn btn-default read-more” style=”background:#3399ff;color:white” href=”https://phpcodeinfomation.blogspot.com/p/php-script.html”>Back</a>
</div>
</div>
<?php include(‘footer.php’);?>
Step 5 : Created config.php File
<?php
define(‘ProPayPal’, 0);
if(ProPayPal){
define(“PayPalClientId”, “*********************”);/*PayPalClientId Payapl*/
define(“PayPalSecret”, “*********************”);/*PayPalSecret Payapl*
define(“PayPalBaseUrl”, “https://api.paypal.com/v1/”);
define(“PayPalENV”, “production”);
} else {
define(“PayPalClientId”, “ARHUUeNT_WdabZnL3AH6e5WY5sEDlj_wJawH1a7c7PkATfN3ZwyDTo0xOmAVUyDpLtO6skYM3Ooikl71”);
define(“PayPalSecret”, “EChDV9reG_PooeIbETe62ScIBWRl7Tv1HEe6SIk9c33vH8hDkUHXVUoKD3pttcNU2C_9Ho5HRP0f2C1L”);
define(“PayPalBaseUrl”, “https://api.sandbox.paypal.com/v1/”);
define(“PayPalENV”, “sandbox”);
}
?>
Step 6 : Created orderDetails.php File
<?php
include(‘header.php’);
?>
<title>phpcode : Demo Paypal Express Checkout Integration with PHP</title>
<?php include(‘container.php’);?>
<div class=”container”>
<h2>Paypal Express Checkout Demo with PHP</h2>
<?php
$orderNumber = 000999;
if(!empty($_GET[‘paymentID’]) && !empty($_GET[‘payerID’]) && !empty($_GET[‘token’]) && !empty($_GET[‘pid’]) ){
$paymentID = $_GET[‘paymentID’];
$payerID = $_GET[‘payerID’];
$token = $_GET[‘token’];
$pid = $_GET[‘pid’];
?>
<div class=”alert alert-success”>
<strong>Success!</strong> Your order processed successfully.
</div>
<table>
<tr>
<td>Payment Id: <?php echo $paymentID; ?></td>
<td>Payer Id: <?php echo $payerID; ?></td>
<td>product Id: <?php echo $pid; ?></td>
<td><?php echo ; ?></td>
</tr>
</table>
<?php
} else {
header(‘Location:index.php’);
}
?>
<div style=”margin:50px 0px 0px 0px;”>
<a class=”btn btn-default read-more” style=”background:#3399ff;color:white” href=”https://phpcodeinfomation.blogspot.com/p/php-script.html”>Back</a>
</div>
</div>
<?php include(‘footer.php’);?>
Step 7 :- Created paypalCheckout.php File
<div id=”paypal-button-container”></div>
<div id=”paypal-button”></div>
<script src=”https://www.paypalobjects.com/api/checkout.js”></script>
<script>
paypal.Button.render({
env: ‘<?php echo PayPalENV; ?>’,
client: {
<?php if(ProPayPal) { ?>
production: ‘<?php echo PayPalClientId; ?>’
<?php } else { ?>
sandbox: ‘<?php echo PayPalClientId; ?>’
<?php } ?>
},
payment: function (data, actions) {
return actions.payment.create({
transactions: [{
amount: {
total: ‘<?php echo $productPrice; ?>’,
currency: ‘<?php echo $currency; ?>’
}
}]
});
},
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
window.location = “<?php echo PayPalBaseUrl ?>orderDetails.php?paymentID=”+data.paymentID+”&payerID=”+data.payerID+”&token=”+data.paymentToken+”&pid=<?php echo $productId; ?>”;
});
}
}, ‘#paypal-button’);
</script>
Step 8 :- Image Show
Comments
No comments yet, take the initiative.
Leave a Reply