php-omnipayHow can I use PHP Omnipay Gateways?
PHP Omnipay is a payment processing library for PHP. It provides a consistent interface for talking to payment gateways. To use PHP Omnipay Gateways, you need to install the library and then create a gateway instance.
Here is an example of using PHP Omnipay to process a credit card payment:
// Create a gateway for the PayPal ExpressGateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('PayPal_Express');
// Initialise the gateway
$gateway->initialize(array(
'username' => 'YOUR_USERNAME',
'password' => 'YOUR_PASSWORD',
'signature' => 'YOUR_SIGNATURE',
'testMode' => true, // Or false when you are ready for live transactions
));
// Create a credit card object
// This card can be used for testing.
$card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '01',
'expiryYear' => '2020',
'cvv' => '123',
));
// Do a purchase transaction on the gateway
$transaction = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'USD',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Purchase transaction was successful!\n";
$sale_id = $response->getTransactionReference();
echo "Transaction reference = " . $sale_id . "\n";
}
The code above will output:
Purchase transaction was successful!
Transaction reference = 4XW06843KJ7446042
The code above consists of the following parts:
- Create a gateway instance with
Omnipay::create
- Initialise the gateway with credentials
- Create a credit card object
- Do a purchase transaction on the gateway
- Send the transaction
- Check if the transaction was successful
- Get the transaction reference
For more information about using PHP Omnipay, please refer to the official documentation.
More of Php Omnipay
- How do I use Omnipay with PHP to process zero-dollar transactions?
- How can I use PHP Omnipay to process Yandex payments?
- How do I use the PHP Omnipay Validator?
- How do I use Omnipay with PHP?
- How can I use Omnipay with PHP to get the value of a payment?
- How can I use PHP Omnipay to process a billing transaction?
- How do I update my Omnipay library in PHP?
- How can I use Omnipay Qiwi to process payments in my PHP application?
- How do I set up and use the Omnipay PHP package?
- How can I use Omnipay in PHP?
See more codes...