Maša Pavićević
Maša Pavićević

Reputation: 31

Using Omnipay in Laravel project

I have to implement Omnipay library for online paymant system in PHP. I've read Omnipay documentation, but I don't get how it works exactly.

// Setup payment gateway
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey('abc123');

What should pass on to create() method, and what is the purpose of setApiKey.

Where I should call these methods?

Upvotes: 2

Views: 1136

Answers (1)

cfreear
cfreear

Reputation: 1875

Omnipay is a gateway agnostic library so when creating your gateway object using Omnipay::create() you need to specify the payment gateway you would like to use, in your example's case the gateway is Stripe (omnipay-stripe) so you pass the gateway name into the create('Stripe') method.

You can find a list of the supported gateways on the php league website (official/third party).

Each payment gateway has different credential requirements, Stripe require an API key that you can find in your Stripe account settings and pass in to Omnipay via the gateway object's setApiKey() method as per your example.

As another example Paypal (omnipay-paypal) require a username, password, signature and paypal account ID which you need to set on the gateway object:

$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername(USERNAME);
$gateway->setPassword(PASSWORD);
$gateway->setSignature(SIGNATURE);
$gateway->setSellerPaypalAccountId(SELLERPAYPALACCOUNTID);

An easy way to find out what methods are available for a particular gateway is to look at it's Gateway.php file; Omnipay\Stripe\Gateway, Omnipay\PayPal\ProGateway

Upvotes: 4

Related Questions