A PHP library for generating encrypted PayPal buttons (EWP)

v1.0.1 2018-01-06 14:43 UTC

This package is auto-updated.

Last update: 2023-09-22 18:26:08 UTC


Build Status Maintainability Test Coverage PHP 7.1 Packagist


A PHP library for generating encrypted PayPal buttons (EWP)


To use this library you should first follow the instructions given by PayPal on generating a merchant certificate and key pair and obtaining PayPal's public certificate.

You'll need the following data to generate a button:

  • Your Certificate ID issued by PayPal after you uploaded your certificate
  • The path to your certificate in PEM format on disk
  • The path to your private key in PEM format on disk
  • The passphrase for your private key (if you set one)
  • The path to PayPal's public certificate in PEM format on disk
  • The HTML Variables you wish to add to your button


The recommended way to install this library is via Composer:

composer require pkerrigan/paypal-ewp ^1


Below is a complete example which generates an encrypted button for submitting a shopping cart:

use Pkerrigan\PaypalEwp\PaypalCertificate;
use Pkerrigan\PaypalEwp\MerchantCertificate;
use Pkerrigan\PaypalEwp\ButtonGenerator;
$buttonGenerator = new ButtonGenerator();
$paypalCert = new PaypalCertificate('/path/to/certs/paypal-cert.pem');
$merchantCert = new MerchantCertificate(
    'MY_KEY_PASSPHRASE' //This argument can be omitted if you have no passphrase
$buttonVariables = [
    'cmd' => '_cart',
    'upload' => '1',
    'amount_1' => '1.00',
    'item_name_1' => 'Test Item',
    'business' => '',
    'currency_code' => 'GBP'
$encryptedCart = $buttonGenerator->encrypt($paypalCert, $merchantCert, $buttonVariables);
<form action="" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="encrypted" value="<?= $encryptedCart; ?>">
    <input type="submit" value="Proceed to checkout">