A generic module for adding PayPal support to a ZF2 application.

dev-master 2015-04-30 13:27 UTC

This package is auto-updated.

Last update: 2020-06-12 16:25:46 UTC


A generic module for adding PayPal Payments support to a ZF2 application.

Build Status


SpeckPaypal is a module that can be utilized outside of Speck Commerce to accept payments via paypal. This module currently supports PayPal Payments Pro and Express Checkout API Operations.

Please see: Paypal API Docs

To integrate with this module you will want to sign up for a sandbox account on Paypal. See the developer website for instructions.

This module currently supports the following calls with API version 95.0:

  • Callback
  • DoAuthorization
  • DoCapture
  • DoDirectPayment
  • DoExpressCheckoutPayment
  • DoVoid
  • GetBalance
  • GetExpressCheckoutDetails
  • GetTransactionDetails
  • RefundTransaction
  • SetExpressCheckout
  • TransactionSearch
  • UpdateRecurringPaymentsProfile
  • ManageRecurringPaymentsProfileStatus
  • CreateRecurringPaymentsProfile


The dependencies for SpeckCommerce are set up as Git submodules so you should not hav

  • PHP 5.4+ (Note: This library should work with PHP 5.3.3+ however official support is no longer provided)
  • Zend Framework 2 (latest master)



Join us on the Freenode IRC network: #speckcommerce. Our numbers are few right now, but we're a dedicated small group working on this project full time.

Example Usage

Create a Paypal Request Object:

//setup config object
$config = array(
    'username'      => 'your_username',
    'password'      => 'your_password',
    'signature'     => 'your_signature',
    'endpoint'      => 'https://api-3t.sandbox.paypal.com/nvp' //this is sandbox endpoint
$paypalConfig = new \SpeckPaypal\Element\Config($config);

//set up http client
$client = new \Zend\Http\Client;
$client->setAdapter(new \Zend\Http\Client\Adapter\Curl);
$paypalRequest = new \SpeckPaypal\Service\Request;

Direct Payment Example (by default the request is sent as "Sale" which is equivalent to Authorize Capture):

$paymentDetails = new \SpeckPaypal\Element\PaymentDetails(array(
    'amt' => '10.00'

$payment = new \SpeckPaypal\Request\DoDirectPayment(array('paymentDetails' => $paymentDetails));

$address = new \SpeckPaypal\Element\Address;
$address->setStreet('27 Your Street');
$address->setStreet2('Apt 23');
$address->setCity('Some City');

$response = $paypalRequest->send($payment);

echo $response->getTransactionId();

Express Checkout Example:

It's important to understand the flow of PayPal's express checkout before attempting to use this API. Paypal Express Checkout Flow

In order to redirect the user to PayPal we first need to get a token.

$paymentDetails = new \SpeckPaypal\Element\PaymentDetails(array(
    'amt' => '20.00'
$express = new \SpeckPaypal\Request\SetExpressCheckout(array('paymentDetails' => $paymentDetails));

$response = $paypalRequest->send($express);

echo $response->isSuccess();

$token = $response->getToken();

Once you have received the token you forward the user to the paypal servers including the token you received. Refer to the documentation for URL. Once the user has completed the checkout process at PayPal they will be redirected to the URL you provided in SetExpressCheckout. When the user lands on this page you will need to make a call back to PayPal including the Token to receive the buyers payment details. You will use the payerId which is included in the response to capture the payment via DoExpressCheckoutPayment.

$details = new \SpeckPaypal\Request\GetExpressCheckoutDetails(array('token' => $token));

$response = $paypalRequest->send($details);

$payerId = $response->getPayerId();

Now that you have the payerId you can capture the payment by calling DoExpressCheckoutPayment.

//To capture express payment
$captureExpress = new \SpeckPaypal\Request\DoExpressCheckoutPayment(array(
    'token'             => $token,
    'payerId'           => $payerId,
    'paymentDetails'    => $paymentDetails
$response = $paypalRequest->send($captureExpress);

echo $response->isSuccess();

Transaction Search Example:

$transactionSearch new \SpeckPaypal\Request\TransactionSearch();

$paypalRequest = $serviceManager->get('SpeckPaypal\Service\Request');
$response = $paypalRequest->send($transactionSearch);



  • better validation based on paypal requirements (currently validation is loose)
  • refactor to relevant exception classes
  • add support for ebay items, survey questions ... and other missing payments pro apis