A PHP client library for creating payments with Paytrail Form Interface (E2).
Install via composer
composer require paytrail/e2-module
Paytrail official documentation can be found here.
use Paytrail\E2Module\Merchant;
use Paytrail\E2Module\E2Payment;
$merchant = Merchant::create($merchantId, $merchantSecret);
$e2Payment = new E2Payment($merchant);
echo $e2Payment->addAmount($orderAmount)
->createPayment($orderNumber)
->getPaymentForm();
Include customer information, discounted product and custom return urls. Payment, customer and product properties can be found from documentation
use Paytrail\E2Module\Merchant;
use Paytrail\E2Module\E2Payment;
use Paytrail\E2Module\Product;
use Paytrail\E2Module\Customer;
$merchant = Merchant::create($merchantId, $merchantSecret);
$e2Payment = new E2Payment($merchant);
$customer = Customer::create([
'PAYER_PERSON_FIRSTNAME' => 'Test',
'PAYER_PERSON_LASTNAME' => 'Customer',
'PAYER_PERSON_EMAIL' => '[email protected]',
'PAYER_PERSON_ADDR_STREET' => 'Test street 1',
'PAYER_PERSON_ADDR_POSTAL_CODE' => '100200',
'PAYER_PERSON_ADDR_TOWN' => 'Helsinki',
'PAYER_PERSON_ADDR_COUNTRY' => 'FI',
'PAYER_PERSON_PHONE' => '040123456',
]);
$paymentData = [
'URL_SUCCESS' => 'https://url/to/shop/successUrl',
'URL_CANCEL' => 'https://url/to/shop/cancelUrl',
'URL_NOTIFY' => 'https://url/to/shop/notifyUrl',
];
$product = Product::create([
'ITEM_TITLE' => 'Test Product',
'ITEM_ID' => '1234',
'ITEM_UNIT_PRICE' => 50,
'ITEM_QUANTITY' => 2,
'ITEM_DISCOUNT_PERCENT' => 10,
]);
$shipping = Product::create([
'ITEM_TITLE' => 'Shipping',
'ITEM_ID' => '001',
'ITEM_UNIT_PRICE' => 5,
'ITEM_TYPE' => Product::TYPE_SHIPMENT_COST,
]);
echo $e2Payment->addCustomer($customer)
->createPayment($orderNumber, $paymentData)
->addProducts([$product, $shipping])
->getPaymentWidget();
After returning from payment, whether success or cancelled, validate return authcode. Same validation applies to notify url.
$isValidPayment = $e2Payment->returnAuthcodeIsValid($_GET);
You can also send return parameters as array instead of using $_GET
superglobal.
If return code is not valid, you can get validation errors.
$errorReasons = $e2Payment->getErrors();
This return array of all error reasons in return authcode validation.
To get status of payment, paid or not.
$isPaid = $e2Payment->isPaid($_GET);
If customer doesn't return back after payment, status can be verified from capturing payment data from notify url. Return authcode validation is similar than success and cancelled payment, but you also need determine payment status.
$isValidPayment = $e2Payment->returnAuthcodeIsValid($_GET);
if (!$isValidPayment) {
// code to handle invalid validation.
}
$isPaid = $e2Payment->isPaid($_GET);
// Code to handle paid/cancelled status for order.
You should save payment id from payment to order details. This id is used for making refunds, and is always unique. Paytrail customer care can also use payment id to track order in case of any problems. Payment id can be also used to get payment details from Merchant Panel.
$paymentId = $_GET['PAYMENT_ID'];