PayPal Payment Gateway with PHP MySQL Database

Today, We want to share with you PayPal Payment Gateway with PHP MySQL Database.In this post we will show you wordpress plugin require another plugin, hear for paypal payment gateway integration in php example we will give you demo and example for implement.In this post, we will learn about PayPal Standard Payment Gateway Integration in PHP with paypal payment gateway integration in php source code download.

PayPal Payment Gateway with PHP MySQL Database

There are the Following The simple About PayPal Payment Gateway with PHP MySQL Database Full Information With Example and payment gateway in php source code.

As I will cover this Post with live Working example to develop paypal integration in php with sandbox, so the paypal payment gateway integration in php source code download is used for this example is following below.

Step 1 : MySQL Database structure

Table structure for table `trans_details`

CREATE TABLE `trans_details` (
  `id` int(10) UNSIGNED NOT NULL,
  `broker_id` int(11) NOT NULL,
  `plan_id` varchar(255) NOT NULL,
  `hash` varchar(255) NOT NULL,
  `complete` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Indexes for table `trans_details`

ALTER TABLE `trans_details`
  ADD PRIMARY KEY (`id`);

Table structure for table `users_dtl`

CREATE TABLE `users_dtl` (
  `id` int(10) UNSIGNED NOT NULL,
  `username` varchar(20) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `broker` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Dumping data for table `users_dtl`

INSERT INTO `users_dtl` (`id`, `username`, `email`, `broker`) VALUES
(1, 'modi124', 'modi124@domain_name.com', 0);

Indexes for table `users_dtl`

ALTER TABLE `users_dtl`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for table `users_dtl`
--

ALTER TABLE `users_dtl`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
COMMIT;  

index.php





PayPal PHP Website Integration Tutorial


broker): ?>
	

You are a broker!

You are not a broker! Become a Member

composer.json

{
    "require": {
        "paypal/rest-api-sdk-php": "*"
    }
}

/paypal/broker/payment.php

setPaymentMethod('paypal');


// Details
$details->setShipping('32.00')
->setTax('0.00')
->setSubtotal('21.00');


// Amount
$amount->setCurrency('USD')
->setTotal('22.00')
->setDetails($details);


// Transaction
$transaction->setAmount($amount)
->setDescription('Membership');

// Payment
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions([$transaction]);


// RedirectUrls
$redirectUrls->setReturnUrl('http://localhost/paypal/paypal/pay.php?approved=true')
->setCancelUrl('http://localhost/paypal/paypal/pay.php?approved=false');

$payment->setRedirectUrls($redirectUrls);


try {

	$payment->create($api);

	//Generate and store hash
	$hash = md5($payment->getId());
	$_SESSION['tamil_hash'] = $hash; 

	//transaction storage
	$store = $db->prepare("
		INSERT INTO trans_details (broker_id, payment_id, hash, complete)
		VALUES (:broker_id, :payment_id, :hash, 0)
		");

	$store->execute([
		'broker_id' => $_SESSION['broker_id'],
		'payment_id' => $payment->getId(),
		'hash' => $hash
	]);

} catch(PPConnectionException $e){
	header("Location: ../paypal/error.php");
}

//var_dump($Payment->getLinks());

foreach ($payment->getLinks() as $link) {
	if($link->getRel() == 'approval_url'){
		$redirectUrl = $link->getHref();
	}
}

header("Location: ". $redirectUrl);
?>

/paypal/broker/complete.php



Paypal payment gateway integration code with PHP, Mysql project




 

Payment complete. Go Home

/paypal/paypal/pay.php

prepare("
			SELECT payment_id
			FROM trans_details
			WHERE hash = :hash
			");
		$paymentId->execute([
			'hash' => $_SESSION['tamil_hash']
		]);

		$paymentId = $paymentId->fetchObject()->payment_id;

		// Get The Paypal Payment
		$payment = Payment::get($paymentId, $api);

		$execution = new PaymentExecution();
		$execution->setPayerId($payerId);

		// Execute Paypal Payment (Charge)
		$payment->execute($execution, $api);


		//Update transaction

		$updateTransaction = $db->prepare("
			UPDATE trans_details
			SET complete = 1
			WHERE payment_id = :payment_id
			");

		$updateTransaction->execute([
			'payment_id' => $paymentId
		]);

		// Set the user as broker

		$setMember = $db->prepare("
			UPDATE users_dtl
			SET broker = 1
			WHERE id = :broker_id
			");

		$setMember->execute([
			'broker_id' => $_SESSION['broker_id']
		]);

		//Unset paypal Hash
		unset($_SESSION['tamil_hash']);
		header('Location: ../broker/complete.php');

	} else {
		header('Location: ../paypal/cancelled.php');
	}
}
?>

/paypal/paypal/cancelled.php



paypal payment gateway tutorial


 

You Cancelled.

error.php



PayPal PHP Website Integration Tutorial


 

Something Went Wrong.

/paypal/src/init_model.php

setConfig([
	'mode' => 'sandbox',
	'http.ConnectionTimeOut' => 30,
	'log.LogEnabled' => false,
	'log.FileName' => '',
	'log.LogLevel' => 'FINE',
	'validation.level' => 'log'
]);

$db = new PDO('mysql:host=localhost;dbname=paypal_site', 'root', '');

$user = $db->prepare("select * from users_dtl where id= :broker_id");

$user->execute(['broker_id' => $_SESSION['broker_id']]);
$user = $user->fetchObject();
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about paypal integration in php step by step pdf.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment