/omnipay-paypal

Rest API paypal processor for Omnipay

Primary LanguagePHPBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Omnipay: Paypal

Paypal REST driver for the Omnipay PHP payment processing library

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements eMerchantPay support for Omnipay.

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "clippings/omnipay-paypal": "~0.1"
    }
}

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Basic Usage

The following gateways are provided by this package:

  • PaypalRest

For general usage instructions, please see the main Omnipay repository.

In order to use this gateway, you need to provide apiKey and clientId.

$gateway = Omnipay::create('PaypalRest');
$gateway->setClientId('abc123');
$gateway->setSecret('abc123');

For a successful purchase you need to provide amount,currency:

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'description' => 'This is a purchase',
));

Funding methods

You can use 3 different methods for paying for purchases

Paypal Redirect

If you don ot provide any payment methods, purchase() method will generate a redirect response.

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'description' => 'This is a purchase',
    'redirectUrl' => 'http://example.com/completed',
    'cancelUrl' => 'http://example.com/cancel',
));

$response = $purchase->send();

// redirect to $response->getRedirectUrl()
$response->redirect();
$key = $response->getTransactionReference();

// You'll need to pass $key as well as "payerid" query parameter that you'll get from paypal redirecting back to your site

$completePurchase = $gateway->completePurchase(array(
    'transactionReference' => $key,
    'payerId' => $_GET['PAYERID'],
));

$response2 = $completePurchase->send();

Credit card reference

You can store user's credit cards within paypal's vault, and use a reference to that for purchases.

$createCard = $gateway->createCard(array(
    'card' => ...,
    'payerId' => 'payer id',
));

$response = $createCard->send();
$cardId = $response->getTransactionReference();

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'cardReference' => $cardId,
));

$response = $purchase->send();

Directly with a credit card

$purchase = $gateway->purchase(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'card' => ...,
));

$response = $purchase->send();

Authorization

Authorisation, capture and void are supported too. It works the same way as purchase, but you'll need to "capture" or "void" afterwords

$authorise = $gateway->authorise(array(
    'currency' => 'GBP',
    'amount' => '15.00',
    'card' => ...,
));

$response = $authorise->send();
$id = $response->getTransactionReference();

$capture = $gateway->capture(array(
    'transactionReference' => $id,
    'amount' => '15.00',
));

$capture->send();

// Or

$capture = $gateway->void(array(
    'transactionReference' => $id,
));

$capture->send();

Refund

$refund = $gateway->refund(array(
    'transactionReference' => $id,
));

$refund->send();

// If you are refunding a capture
$refund = $gateway->refund(array(
    'transactionReference' => $id,
    'type' => 'capture'
));

$refund->send();

// Partial refund
$refund = $gateway->refund(array(
    'transactionReference' => $id,
    'amount' => '10.00'
    'currency' => 'GBP'
));

$refund->send();

Credit Card Vault

createCard, updateCard and deleteCard are supported too.

$createCard = $gateway->createCard(array(
    'card' => ...,
    'payerId' => '123123' // Optional, if set, will be required when referencing for a purchase later
));

$response = $createCard->send();
$cardReference = $response->getTransactionReference();

$updateCard = $gateway->updateCard(array(
    'card' => ...,
));

$deleteCard = $gateway->deleteCard(array(
    'card' => ...,
));

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release announcements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

License

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin

Under BSD-3-Clause license, read LICENSE file.