Pay. driver for the Omnipay payment processing library
- Description
- Available payment methods
- Requirements
- Installation
- Update instructions
- Usage
- Tests
- Support
Bank Payments | Creditcards | Gift cards & Vouchers | Pay by invoice | Others |
---|---|---|---|---|
iDEAL + QR | Visa | VVV Cadeaukaart | AfterPay | PayPal |
Bancontact + QR | Mastercard | Webshop Giftcard | Achteraf betalen via Billink | WeChatPay |
Giropay | American Express | FashionCheque | Focum AchterafBetalen.nl | AmazonPay |
MyBank | Carte Bancaire | Podium Cadeaukaart | Capayable Achteraf Betalen | Cashly |
SOFORT | PostePay | Gezondheidsbon | in3 keer betalen, 0% rente | Pay Fixed Price (phone) |
Maestro | Dankort | Fashion Giftcard | Klarna | Instore Payments (POS) |
Bank Transfer | Cartasi | GivaCard | SprayPay | Przelewy24 |
Tikkie | De Cadeaukaart | YourGift | Creditclick | Apple Pay |
Multibanco | Paysafecard | Payconiq | ||
Huis en Tuin Cadeau |
Before running the tests, make sure you have:
- PHP installed (7.4 or higher recommended)
- Composer installed
- A Pay.nl account with API credentials
In command line, navigate to the installation directory of Omnipay
Enter the following command:
composer require league/omnipay:^3 paynl/omnipay-paynl-v3
The plugin is now installed
- Create a new php file
- Use the following code:
# require autoloader
require_once('vendor/autoload.php');
use Omnipay\Omnipay;
# Setup payment gateway
$gateway = Omnipay::create('PaynlV3');
$gateway->setApiSecret('****************************************');
$gateway->setTokenCode('AT-####-####');
$gateway->setServiceId('SL-####-####');
- Enter the TokenCode, API token, ServiceId (these can be found in the Pay. My Pay Panel --> https://my.pay.nl/
Go to the Settings / Sales locations tab in the Pay. Scroll down to the sales location and there copy the SL code and the secret.
In command line, navigate to the installation directory of Omnipay
Enter the following command:
composer update league/omnipay:^3 paynl/omnipay-paynl-v3
The plugin has now been updated
$response = $gateway->fetchPaymentMethods()->send();
$response->getPaymentMethods();
$paymentMethods = array();
foreach ($response->getPaymentMethods() as $paymentMethod) {
$paymentMethods[] = [
'id' => $paymentMethod->getId(),
'name' => $paymentMethod->getName(),
];
}
$response = $gateway->fetchIssuers()->send();
$response->getIssuers();
$issuers = array();
foreach ($response->getIssuers() as $issuer) {
$issuers[] = [
'name' => $issuer->getName(),
'id' => $issuer->getId(),
'paymentMethod' => $issuer->getPaymentMethod(),
];
}
# Use Pay. Item class
use Omnipay\Paynl\Common\Item;
# Add items to transaction
$arrItems = array();
$item = new Item();
$item->setProductId('SKU01')
->setProductType('ARTICLE')
->setVatPercentage(21)
->setDescription('Description')
->setPrice('10')
->setQuantity(4);
$arrItems[] = $item;
$item = new Item();
$item->setProductId('SHIP01')
->setProductType('SHIPPING')
->setVatPercentage(21)
->setDescription('Description')
->setPrice('5')
->setQuantity(1);
$arrItems[] = $item;
$item = new Item();
$item->setProductId('SKU02')
->setProductType('DISCOUNT')
->setVatPercentage(21)
->setDescription('Description')
->setPrice('1')
->setQuantity(1);
$arrItems[] = $item;
# Send purchase request
$response = $gateway->purchase(
[
'amount' => '46.00',
'currency' => 'EUR',
'transactionReference' => 'referenceID1',
'clientIp' => '192.168.192.12',
'returnUrl' => 'http://www.yourdomain.com/return_from_pay',
'items' => $arrItems,
'card' => array(
'firstName' => 'Example',
'lastName' => 'User',
'gender' => 'M',
'birthday' => '01-02-1992',
'phone' => '1111111111111111',
'email' => '[email protected]',
'country' => 'NL',
'shippingAddress1' => 'Shippingstreet 1B',
'shippingAddress2' => '',
'shippingCity' => 'Shipingtown',
'shippingPostcode' => '1234AB',
'shippingState' => '',
'shippingCountry' => 'NL',
'billingFirstName' => 'Billingexample',
'billingLastName' => 'Billinguser',
'billingAddress1' => 'Billingstreet 1B',
'billingAddress2' => '',
'billingCity' => 'Billingtown',
'billingPostcode' => '1234AB',
'billingState' => '',
'billingCountry' => 'NL'
)
]
)->send();
# Process response
if ($response->isSuccessful()) {
# Get the url for fetching the Transaction
$statusUrl = $response->getStatusUrl();
$voidUrl = $response->getVoidUrl();
$redirectUrl = $response->getRedirectUrl();
$givenCaptureUrl = $response->getCaptureUrl();
$givenCaptureAmountUrl = $response->getCaptureAmountUrl();
$givenCaptureProductsUrl = $response->getCaptureProductsUrl();
$abortUrl = $response->getAbortUrl();
$approveUrl = $response->getApproveUrl();
$declineUrl = $response->getDeclineUrl();
$debugUrl = $response->getDebugUrl();
$checkoutUrl = $response->getCheckoutUrl();
}
# Payment was successful
var_dump($response);
} elseif ($response->isRedirect()) {
# Get the url for fetching the Transaction
$redirectUrl = $response->getRedirectUrl();
} else {
# Payment failed
echo $response->getMessage();
}
$response = $gateway->fetchTransaction(['stateUrl' => $statusUrl])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$response = $gateway->approve(['approveUrl' => $approveUrl])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$response = $gateway->decline(['declineUrl' => $declineUrl])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$response = $gateway->capture(['captureUrl' => $captureUrl])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$response = $gateway->captureAmount([
'captureAmountUrl' => $captureAmountUrl,
'amount' => '14.00'
])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$arrItems = array();
$item = new Item();
$item->setProductId('SKU01')
->setProductType('ARTICLE')
->setVatPercentage(21)
->setDescription('Description')
->setPrice('10')
->setQuantity(4);
$arrItems[] = $item;
$response = $gateway->captureProducts([
'captureAmountUrl' => $captureProductsUrl,
'items' => $arrItems
])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$response = $gateway->abort([
'abortUrl' => $abortUrl
])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
$response = $gateway->void(['voidUrl' => $voidUrl])->send();
if ($response->isSuccessful()) {
# Get was successful
print_r($response);
} else {
# Get failed
echo $response->getMessage();
}
Before running the tests, make sure you have:
- PHP installed (7.4 or higher recommended)
- Composer installed
- A Pay.nl account with API credentials
- Install dependencies:
composer install
- Create a copy of the phpunit configuration file:
cp phpunit.xml.dist phpunit.xml
- Configure environment variables in your
phpunit.xml
:
Replace the empty values with your Pay.nl credentials:
Note: Never commit your actual API credentials to version control. The
phpunit.xml
file should be in your.gitignore
.
To run all the tests:
./vendor/bin/phpunit --testsuite "Omni pay v3 tests"
Variable | Description |
---|---|
PAYNL_SERVICE_CODE |
Your Pay.nl service location code (SL-xxxx-xxxx) |
PAYNL_API_SECRET |
Your Pay.nl API token |
Contact us: [email protected]