PHPackages                             henshall/php-paypal-wrapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. henshall/php-paypal-wrapper

ActiveLibrary[Payment Processing](/categories/payments)

henshall/php-paypal-wrapper
===========================

Simple Paypal wrapper used to make purchases, with lots of examples

1.0.0(5y ago)08PHP

Since Sep 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Henshall/php-paypal-wrapper)[ Packagist](https://packagist.org/packages/henshall/php-paypal-wrapper)[ RSS](/packages/henshall-php-paypal-wrapper/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP Paypal Wrapper
==================

[](#php-paypal-wrapper)

Version: 1.0.0
--------------

[](#version-100)

This is a wrapper for the Paypals PHP Package 'paypal/rest-api-sdk-php'.

Working with Paypal can be an extremely frustrating experience. Their sandbox doesn't always work, their documentation is outdated or redundant, and they are very quick to ban and freeze your account if they don't like any of the transactions (ex. monetary amount too high).

I want to create a wrapper with some basic documentation so that users can accept payments as soon as possible. The following package lets users send a payment to your Paypal account, and allows parameters to be sent along (such as user id's) so that you can easily track who has paid, so that you can upgrade their account, or send a product to them, or whatever else you need to do.

Installation with Composer:
---------------------------

[](#installation-with-composer)

```
composer require henshall/php-paypal-wrapper
```

Pre-requisites
--------------

[](#pre-requisites)

- Obtain Paypal Client ID / Secret at
- Place the following config file somewhere into your code, and change the settings to match your application.

```
return [

    /**
    * get from https://developer.paypal.com
    */
    'client_id' => 'PAYPAL_CLIENT_ID',
    /**
    * get from https://developer.paypal.com
    */
    'secret' => 'PAYPAL_CLIENT_SECRET',
    /**
    * after a user authorizes the payment, they will be directed to this url. This is where we will place the logic from step 2 below.
    */
    'return_url' => 'RETURN_URL',
    /**
    * // url the user is sent to if they cancel the transaction. Maybe you can bring the user back to your homepage with a message saying they cancelled the transaction.
    */
    'cancel_url' => 'CANCEL_URL',
    /**
    * SDK configuration
    */
    'settings' => array(
        /**
        * Available option 'sandbox' or 'live'
        */
        'mode' => "sandbox",  // make sure to change this to live!
        /**
        * Specify the max request time in seconds
        */
        'http.ConnectionTimeOut' => 1000,
        /**
        * Whether want to log to a file
        */
        'log.LogEnabled' => false,
        /**
        * Specify the file that want to write on
        */
        'log.FileName' => '/logs/paypal.log',
        /**
        * Available option 'FINE', 'INFO', 'WARN' or 'ERROR'
        *
        * Logging is most verbose in the 'FINE' level and decreases as you
        * proceed towards ERROR
        */
        'log.LogLevel' => 'FINE',

    ),
];
```

Usage:
======

[](#usage)

This package is 100% on the back-end - so that you can create your own html/css/js front-end however you like, and when a user wants to make a purchase, simply send a post request to the back-end of your application and use this package.

### Step 1.

[](#step-1)

A user click "pay" on your website, and you send a get/post request to the backend.

```
Pay
```

### Step 2.

[](#step-2)

In the pay.php file, or wherever you redirected them to, you will have the code below. This code will redirect them to paypals website where they will log in, and authorize the payment.

```
// Create the class
$paypalWrapper = new PaypalWrapper;
// Set the config file as shown above in the prerequisites section
$config = config('paypal_conf');
$validate = $paypalWrapper->validateConfigFile($config);
$paypalWrapper->setConfigFile($config);
// Set a Parameter - Here you can set a user_id, name, or email address to track which user has paid.
$paypalWrapper->setParam("useremail@email.com");
// Set the amount and the currency type (currency examples below)
$paypalWrapper->RedirectToPaypal(100, "USD");
if ($paypalWrapper->error) {
    // Where to put your logic if there is an error. (Save error to DB, or log file, or email to yourself etc.)
    // die($paypalWrapper->error);
}

//NOTE you can also check if any of the individual functions fail by see if they return false.
// $setConfig = $paypalWrapper->setConfigFile($config);
// if (!$setConfig) {
//     // LOGIC IF FAILED TO SET CONFIG
// }
```

### Step 3.

[](#step-3)

Once they authorize the payment, they will be redirected back to your website according to the 'redirect\_url' variable you set in the config file. They will pass along two parameters: 1) PayerId 2) paymentID - we will need these parameters in order to execute the payment.

```
// Create the class
$paypalWrapper = new PaypalWrapper;
// Set the config file as shown above in the prerequisites section
$config = config('paypal_conf');
$validate = $paypalWrapper->validateConfigFile($config);
$paypalWrapper->setConfigFile($config);
// Set the payment
$paypalWrapper->setPayment($data["PayerID"], $data["paymentId"] );
// Execute the payment
$executePayment = $paypalWrapper->executePayment();

if ($paypalWrapper->error) {
    // Where to put your logic if there is an error with the wrapper itself, or its config
}

if ($executePayment == true) {
    // write code for when payment is successful
}

if ($executePayment == false) {
    // write code for when payment is NOT successful (ex. insufficient funds, or blocked for some reason)
}
```

### Currency Types Accepted:

[](#currency-types-accepted)

CurrencyCodeAustralian dollarAUDBrazilian real 2BRLCanadian dollarCADChinese Renmenbi 4CNYCzech korunaCZKDanish kroneDKKEuroEURHong Kong dollarHKDHungarian forint 1HUFIndian rupee 3INRIsraeli new shekelILSJapanese yen 1JPYMalaysian ringgit 4MYRMexican pesoMXNNew Taiwan dollar 1TWDNew Zealand dollarNZDNorwegian kroneNOKPhilippine pesoPHPPolish złotyPLNPound sterlingGBPRussian rubleRUBSingapore dollarSGDSwedish kronaSEKSwiss francCHFThai bahtTHBUnited States dollarUSD

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2131d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/90d8f0c734f4da644d2356081c7f4d750a11b42c1ca448091853cbe95bc38d27?d=identicon)[weshenshall](/maintainers/weshenshall)

---

Top Contributors

[![Henshall](https://avatars.githubusercontent.com/u/20879253?v=4)](https://github.com/Henshall "Henshall (15 commits)")

### Embed Badge

![Health badge](/badges/henshall-php-paypal-wrapper/health.svg)

```
[![Health](https://phpackages.com/badges/henshall-php-paypal-wrapper/health.svg)](https://phpackages.com/packages/henshall-php-paypal-wrapper)
```

###  Alternatives

[netshell/paypal

Laravel-Paypal is simple package help you process direct credit card payments, stored credit card payments and PayPal account payments with your Laravel 5 projects using paypal REST API SDK.

159436.1k2](/packages/netshell-paypal)[larabook/gateway

A Laravel package for connecting to all Iraninan payment gateways

24754.1k](/packages/larabook-gateway)[amsgames/laravel-shop-gateway-paypal

PayPal gateway for Laravel Shop package.

1211.6k6](/packages/amsgames-laravel-shop-gateway-paypal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
