Skip to content
Tech Shizz Logo

An Engineers Blog

  • TechShizz
  • blog

Setting up PayPal Express Checkout API in PHP

Posted on February 23, 2021 By rich No Comments on Setting up PayPal Express Checkout API in PHP

It took me a while to find out how to do this properly, but the youtube video below is perfect, easy to follow. I have posted my code to assist.  

Start.php

<?php
require ('vendor/autoload.php');
define('SITE_URL', 'http://www.your-domain.com');
$paypal = new PayPalRestApiContext(
new PayPalAuthOAuthtokenCredential(
'AZ50OpZ7uXSt-t_yJJl_ZjkV8-PrZzqqj3bMQDIU-Ni8SxhupHZXcRd4ZRZM922U3HfgGGwP5gTgN5aj',
'EJT_I5lvrv9IxRz-GX-qOH8bagklmservijaieor ghjba[oudYPMGHHvfgfgfgfgfaweqfwe'
	)
);
?>

checkout.php

<?php 
////Global Stuff
	require('config/config.php');
	require('config/connection.php');
	require('config/mail_config.php');
session_start();
$transactionID = $_GET['transactionID'];
if (isset($_SESSION['username'])){
	$username = $_SESSION['username'];
}								
use PayPalApiPayment;
use PayPalApiPaymentExecution;
require ('start.php');
if(isset($_GET['success'], $_GET['paymentId'], $_GET['PayerID'], $_GET['transactionID'])){

if((bool)$_GET['success'] === false) {
	echo "success did not equal TRUE";
die();
}
$paymentId = $_GET['paymentId'];
$payerId = $_GET['PayerID'];
$token = $_GET['token'];
$payment = Payment::get($paymentId, $paypal);
$execute = new PaymentExecution();
$execute->setPayerId($payerId);

try {
	$result = $payment->execute($execute, $paypal);
} catch (Exception $e) {
	$data = json_decode($e->getData());
	var_dump($data);
	die();
}
echo 'Payment Made, Thanks!';
//////Do Data base stuff now.

?>

 

Post navigation

❮ Previous Post: Using PowerShell to Add Drivers / Packages / Install Roles and Features in a .wim file
Next Post: Windows Store is missing in Windows 10 ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Subscribe to our newsletter!

Recent Posts

  • How to implement a lightning-fast ransomware playbook
  • How to achieve defence in depth in your business
  • How to implement a SecOps team phishing response plan
  • How to block an Office 365 Sign-in correctly
  • Microsoft finally patched serious Exchange 0-day over a month old!

Recent Comments

    Archives

    • November 2022
    • July 2021
    • March 2021
    • February 2021

    Categories

    • Cyber Security
    • Uncategorized

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2023 .

    Theme: Oceanly News Dark by ScriptsTown