Skip to content

Commit

Permalink
Merge pull request #1 from kotrakrishna/master
Browse files Browse the repository at this point in the history
Restructure config to support multiple instances of gateway with different configuration parameters
  • Loading branch information
anush committed Jul 1, 2014
2 parents 71b4e39 + d0615d3 commit 11d6fa7
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 493 deletions.
265 changes: 0 additions & 265 deletions DependencyInjection/Configuration.php

This file was deleted.

7 changes: 1 addition & 6 deletions DependencyInjection/OmnipayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ class OmnipayExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('omnipay', $config);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,43 @@ it's possible to configure these parameters in your Symfony config files.

```yaml
# app/config/password_dev.yml
omnipay:
parameters:
# Custom gateway
omnipay.my_custom_name.apiKey: myGatewayKey
omnipay.my_custom_name.gateway: MyGateway

# Authorize.NET AIM
authorize_net_aim:
apiLoginId: myLoginId
transactionKey: myTransactionKey
# Default Stripe gateway
omnipay.stripe_default.apiKey: myApiKey
omnipay.stripe_default.gateway: Stripe

# Gateway for Stripe Canada account
omnipay.stripe_canada.apiKey: myStripeCanadaApiKey
omnipay.stripe_canada.gateway: Stripe

# Stripe
stripe:
apiKey: myApiKey
# Authorize.NET AIM
omnipay.authorize_net_aim.transactionKey: myTransactionKey
omnipay.authorize_net_aim.gateway: AuthorizeNet_AIM
```
In the sample configuration above, `my_custom_name` is a unique name you define for each of your gateways. `omnipay.my_custom_name.gateway` is the class name for a Omnipay gateway driver (eg `Stripe`). You may choose to define multiple names for the same Omnipay gateway with different credentials. Eg. we have configured two gateway definitions for Stripe, both use the same Omnipay driver, however, they use different sets of credentials.

In the configuration file, you'll need to "underscore" the names of the gateways, but their parameters should be left
intact i.e. the gateway name "AuthorizeNet_AIM" becomes "authorize_net_aim", however all it's parameters remain
unchanged and remain in camel case.

Usage
-----
Use the new `omnipay` service to create gateway classes:
Use the new `omnipay` service to create gateway object:

```php
// From within a controller
$gateway = $this->get('omnipay')->create('Stripe');
// From within a controller. This will return an instance `\Omnipay\Stripe`. `stripe_default` is the key as specified in the config.
$gateway = $this->get('omnipay')->get('stripe_default');


// From within a controller. This will return an instance of `\Omnipay\MyGateway` as specified in `omnipay.my_custom_name.gateway`
$gateway = $this->get('omnipay')->get('my_custom_name');
```

// The rest is identical to how you would normally use Omnipay

The rest is identical to how you would normally use Omnipay

```php
$formData = ['number' => '4242424242424242', 'expiryMonth' => '11', 'expiryYear' => '2018', 'cvv' => '123'];
$response = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'card' => $formData])->send();

Expand All @@ -64,4 +75,4 @@ if ($response->isSuccessful()) {
echo $response->getMessage();
}
```
The gateway classes which are returned are already initialized with the parameters defined in the config files.
The gateway classes which are returned are already initialized with the parameters defined in the config files.
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ parameters:
services:
omnipay:
class: %omnipay.service.class%
arguments: [ %omnipay% ]
arguments: [ @service_container ]
Loading

0 comments on commit 11d6fa7

Please sign in to comment.