2017 © Pedro Peláez
 

library omnipay-bundle

Omnipay bundle for Symfony 2.3+ and 3.0+

image

colinodell/omnipay-bundle

Omnipay bundle for Symfony 2.3+ and 3.0+

  • Sunday, March 18, 2018
  • by colinodell
  • Repository
  • 1 Watchers
  • 7 Stars
  • 13,807 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 4 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

omnipay-bundle

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

Simple bundle for implementing Omnipay in your Symfony application., (*2)

Versions

omnipay-bundle Symfony Omnipay PHP
1.x 2.x or 3.x 2.x 5.4+
2.x 2.x or 3.x 3.x 5.6+

Install

Via Composer, (*3)

``` bash $ composer require colinodell/omnipay-bundle, (*4)


Enable the bundle in your `AppKernel.php`: ```php new ColinODell\OmnipayBundle\OmnipayBundle(),

Usage

This bundle provides a new service called Omnipay. It contains a single method get(), which returns a fully-configured gateway for you to use:, (*5)

``` php $stripe = $this->get('omnipay')->get('Stripe');, (*6)

$paypal = $this->get('omnipay')->get('PayPal_Express');, (*7)


You can then use these gateways like usual. **Note:** Gateways are "cached" - calling `get('Some_Gateway')` multiple times will always return the same object. ## Configuration Gateways can be configured in your `app/config/config.yml` file ``` yml omnipay: methods: # Your config goes here

For example, to configure the Stripe and PayPal Express gateways:, (*8)

``` yml omnipay: methods: Stripe: apiKey: sk_test_BQokikJOvBiI2HlWgH4olfQ2, (*9)

    PayPal_Express:
        username:     test-facilitator_api1.example.com
        password:     3MPI3VB4NVQ3XSVF
        signature:    6fB0XmM3ODhbVdfev2hUXL2x7QWxXlb1dERTKhtWaABmpiCK1wtfcWd.
        testMode:     false
        solutionType: Sole
        landingPage:  Login

**NOTE:** You should probably consider using parameters instead of storing credentials directly in your `config.yml` like that. The method names should be whatever you'd typically pass into `Omnipay::create()`. The configuration settings vary per gateway - see [Configuring Gateways](http://omnipay.thephpleague.com/gateways/configuring/) in the Omnipay documentation for more details. ## Registering Custom Gateways Custom gateways can be registered via the container by tagging them with `omnipay.gateway`: ```yml # services.yml services: my.test.gateway: class: Path\To\MyTestGateway tags: - { name: omnipay.gateway, alias: MyTest } # config.yml omnipay: methods: # Reference the gateway alias here MyTest: apiKey: abcd1234!@#

You can then obtain the fully-configured gateway by its alias:, (*10)

$this->get('omnipay')->get('MyTest');

Additional configuration and customization

Default gateway

Add default gateway key to your config:, (*11)

# config.yml
omnipay:
    methods:
        MyGateway1:
            apiKey: abcd1234!@#
        MyGateway2:
            apiKey: abcd45678!@#

    default_gateway: MyGateway1

You can now get default gateway instance:, (*12)

$omnipay->getDefaultGateway();

Disabling gateways

If need to disable a gateway but want to keep all the configuration add disabled_gateways key to the config:, (*13)

# config.yml
omnipay:
    methods:
        MyGateway1:
            apiKey: abcd1234!@#
        MyGateway2:
            apiKey: abcd45678!@#

    disabled_gateways: [ MyGateway1 ]

MyGateway1 gateway will be skipped during gateway registration now., (*14)

Customizing Omnipay service

If you need specific gateway selection mechanism or need to get multiple gateways at once consider to extend default Omnipay service. Create your custom Omnipay class, extend it from base class and add custom getters. For example, you might want to get all gateways which implement some interface., (*15)

<?php

// AppBundle/Omnipay/Omnipay.php

namespace AppBundle\Omnipay;

use AppBundle\Payment\Processing\Gateway\VaultAwareGateway;
use ColinODell\OmnipayBundle\Service\Omnipay as BaseOmnipay;
use Omnipay\Common\GatewayInterface;

class Omnipay extends BaseOmnipay
{
    /**
     * @return VaultAwareGateway[]
     */
    public function getVaultAwareGateways()
    {
        return array_filter($this->registeredGateways, function (GatewayInterface $gateway) {
            return $gateway instanceof VaultAwareGateway;
        });
    }
}
#services.yml
parameters:
    omnipay.class: AppBundle\Omnipay\Omnipay

Now you should be able to get vault-aware gateways in your application:, (*16)

foreach ($omnipay->getVaultAwareGateways() as $gateway) {
    $gateway->saveCreditCard($creditCard); // assuming saveCreditCard is a part of VaultAwareGateway interface
}

Initialize gateways on registration

By default gateway is initialized only when you call get() method. If you use custom getters (like getVaultAwareGateways from example above) with $this->registeredGateways inside you might want to initialize them automatically during registration. Simply add appropriate config key:, (*17)

# config.yml
omnipay:
    methods:
        MyGateway1:
            apiKey: abcd1234!@#

    initialize_gateway_on_registration: true

Testing

bash $ phpunit, (*18)

Contributing

Please see CONTRIBUTING for details., (*19)

Security

If you discover any security related issues, please email colinodell@gmail.com instead of using the issue tracker., (*20)

Credits

License

The MIT License (MIT). Please see License File for more information., (*21)

The Versions

18/03 2018

dev-master

9999999-dev https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony 2.3+ and 3.0+

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay symfony2 bundle symfony3 symfony

18/03 2018

v1.0.0

1.0.0.0 https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony 2.3+ and 3.0+

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay symfony2 bundle symfony3 symfony

18/03 2018

dev-fix-errors

dev-fix-errors https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony 2.3+ and 3.0+

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay symfony2 bundle symfony3 symfony

25/01 2017

0.3.1

0.3.1.0 https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay bundle

15/07 2016

0.3.0

0.3.0.0 https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay bundle

01/04 2015

0.2.0

0.2.0.0 https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay bundle

27/03 2015

dev-logging

dev-logging https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay bundle

20/03 2015

0.1.0

0.1.0.0 https://github.com/colinodell/omnipay-bundle

Omnipay bundle for Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

payment omnipay bundle