JMSPaymentPaypalBundle

PayPal Express Checkout plugin for JMSPaymentCoreBundle

Introduction

Payment processing in Symfony projects using PayPal Express Checkout. Implemented as a plugin for JMSPaymentCoreBundle.

Table of Contents

Setup

Requirements

This plugin depends on JMSPaymentCoreBundle so you’ll need to setup it up first. Please follow its setup instructions and come back to this document once you’re done.

Installation

Install with composer:

composer require jms/payment-paypal-bundle

And register the bundle in your AppKernel.php:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new JMS\Payment\CoreBundle\JMSPaymentCoreBundle(),
        new JMS\Payment\PaypalBundle\JMSPaymentPaypalBundle(),
    );
}

Configuration

You need to supply at least the following configuration. See PayPal’s documentation (Create an API signature section) for information on how to obtain the credentials.

# app/config/config.yml

jms_payment_paypal:
    username: your_api_username # not your account username
    password: your_api_password # not your account password
    signature: your_api_signature

Tip

See Available options for information on all configuration options.

Usage

Tip

If you’re not familiar with JMSPaymentCoreBundle, we recommend you follow the Accepting Payments guide, which shows how to integrate the bundle into your application.

// src/AppBundle/Controller/FooController.php

use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType;

$config = [
    'paypal_express_checkout' => [
        'return_url' => 'https://example.com/return-url',
        'cancel_url' => 'https://example.com/cancel-url',
        'useraction' => 'commit',
    ],
];

$form = $this->createForm(ChoosePaymentMethodType::class, null, [
    'amount'          => 10.00,
    'currency'        => 'EUR',
    'predefined_data' => $config,
]);

Note

The return_url and cancel_url options are required but useraction is optional. However, it is usually set to commit. See below for more information on each of these options.

Available options

This section describes all available options. Certain options can be set globally, in the bundle configuration, in which case they apply to all payments:

# app/config/config.yml

jms_payment_paypal:
    foo: bar

However, globally-defined options will be overriden if specified in a certain payment. In the following example, the foo option will have the value baz instead of the globally-defined bar:

$config = [
    'paypal_express_checkout' => [
        'foo' => 'baz',
    ],
];

$form = $this->createForm(ChoosePaymentMethodType::class, null, [
    'amount'          => 10.00,
    'currency'        => 'EUR',
    'predefined_data' => $config,
]);
return_url

Mandatory

The URL to which the user is redirected once they authorize the payment on PayPal’s website.

This is usually the URL of the same controller action that redirected the user to PayPal (see Depositing Money in JMSPaymentCoreBundle’s documentation):

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

$config = [
    'paypal_express_checkout' => [
        'return_url' => $this->generateUrl('app_orders_paymentcreate', [
            'id' => $order->getId(),
        ], UrlGeneratorInterface::ABSOLUTE_URL),
    ],
];

Alternatively, you can set it globally, through the bundle’s configuration:

# app/config/config.yml

jms_payment_paypal:
    return_url: https://example.com/return-url
cancel_url

Mandatory

The URL to which the user is redirected when they cancel the payment on PayPal’s website.

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

$config = [
    'paypal_express_checkout' => [
        'cancel_url' => $this->generateUrl('app_orders_paymentcancel', [
            'id' => $order->getId(),
        ], UrlGeneratorInterface::ABSOLUTE_URL),
    ],
];

Alternatively, you can set it globally, through the bundle’s configuration:

# app/config/config.yml

jms_payment_paypal:
    cancel_url: https://example.com/cancel-url
notify_url

Optional

Default: null

The URL to which Instant Payment Notifications (IPN) will be sent.

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

$config = [
    'paypal_express_checkout' => [
        'notify_url' => $this->generateUrl('app_orders_ipn', [
            'id' => $order->getId(),
        ], UrlGeneratorInterface::ABSOLUTE_URL),
    ],
];

Alternatively, you can set it globally, through the bundle’s configuration:

# app/config/config.yml

jms_payment_paypal:
    notify_url: https://example.com/notify-url
useraction

Optional

Default: null

The useraction option determines whether buyers complete their purchase on PayPal or on your website. See PayPal’s documentation (Allowing buyers to complete their purchases on PayPal section) for more information.

Usually, this option is set to commit:

$config = [
    'paypal_express_checkout' => [
        'useraction' => 'commit',
    ],
];

Since it will usually apply to all payments, you can set it globally:

# app/config/config.yml

jms_payment_paypal:
    useraction: commit
checkout_params

Optional

Default: []

Allows you to pass additional information to PayPal, for example, shipping information. See PayPal’s documentation for all available options.

$config = [
    'paypal_express_checkout' => [
        'checkout_params' => [
            'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe',
        ],
    ],
];
debug

Optional

Default: %kernel.debug%

Whether to use the PayPal’s Sandbox or the Live site. By default this is set to kernel.debug so it will use the Sandbox in development and the Live site in production, which is normally what you want.

If for some reason you need to change this behaviour, you can set it globally:

# app/config/config.yml

jms_payment_paypal:
    debug: true # Use the Sandbox

License