Git Product home page Git Product logo

e2-module's Introduction

Paytrail E2 module

Latest Stable Version PHP Test Suite Total Downloads License

A PHP client library for creating payments with Paytrail Form Interface (E2).

Installation

Install via composer

composer require paytrail/e2-module

Documentation

Paytrail official documentation can be found here.

Usage

Payment without customer and product information

use Paytrail\E2Module\Merchant;
use Paytrail\E2Module\E2Payment;

$merchant = Merchant::create($merchantId, $merchantSecret);
$e2Payment = new E2Payment($merchant);

echo $e2Payment->addAmount($orderAmount)
    ->createPayment($orderNumber)
    ->getPaymentForm();

Payment widget with customer, product information and custom return urls

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();

Validating completed payment

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);

Validating payment from notification

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.

Getting payment id

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'];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.