GithubHelp home page GithubHelp logo

sdk's Introduction

Latest Stable Version Total Downloads Latest Unstable Version Build Status Coverage Status

Pay.nl PHP SDK



Installation

This SDK uses composer.

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

For more information on how to use/install composer, please visit: https://github.com/composer/composer

To install the Pay.nl PHP sdk into your project, simply

$ composer require paynl/sdk

Installation without composer

If you don't have experience with composer, it is possible to use the SDK without using composer.

You can download the zip on the projects releases page.

  1. Download the package zip (SDKvx.x.x.zip).
  2. Unzip the contents of the zip, and upload the vendor directory to your server.
  3. In your project, require the file vendor/autoload.php
  4. You can now use the SDK in your project

Requirements

The Pay.nl PHP SDK works on php versions 5.6 or higher, and requires the php curl extension.

Quick start and examples

Set the configuration

require __DIR__ . '/vendor/autoload.php';

// Replace tokenCode apitoken and serviceId with your own.
\Paynl\Config::setTokenCode('AT-1234-5678');
\Paynl\Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab');
\Paynl\Config::setServiceId('SL-3490-4320');

Get available payment methods

require __DIR__ . '/vendor/autoload.php';

\Paynl\Config::setTokenCode('AT-1234-5678');
\Paynl\Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab');
\Paynl\Config::setServiceId('SL-3490-4320');

$paymentMethods = \Paynl\Paymentmethods::getList();
var_dump($paymentMethods);

Start a transaction

require __DIR__ . '/vendor/autoload.php';

\Paynl\Config::setTokenCode('AT-1234-5678');
\Paynl\Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab');
\Paynl\Config::setServiceId('SL-3490-4320');

$result = \Paynl\Transaction::start(array(
    // required
        'amount' => 10.00,
        'returnUrl' => Paynl\Helper::getBaseUrl().'/return.php',

    // optional
    	'currency' => 'EUR',
        'exchangeUrl' => Paynl\Helper::getBaseUrl().'/exchange.php',
        'paymentMethod' => 10,
        'bank' => 1,
        'description' => 'demo betaling',
        'testmode' => 1,
        'extra1' => 'ext1',
        'extra2' => 'ext2',
        'extra3' => 'ext3',
        'products' => array(
            array(
                'id' => 1,
                'name' => 'een product',
                'price' => 5.00,
                'tax' => 0.87,
                'qty' => 1,
            ),
            array(
                'id' => 2,
                'name' => 'ander product',
                'price' => 5.00,
                'tax' => 0.87,
                'qty' => 1,
            )
        ),
        'language' => 'EN',
        'ipaddress' => '127.0.0.1',
        'invoiceDate' => new DateTime('2016-02-16'),
        'deliveryDate' => new DateTime('2016-06-06'), // in case of tickets for an event, use the event date here
        'enduser' => array(
            'initials' => 'T',
            'lastName' => 'Test',
            'gender' => 'M',
            'birthDate' => new DateTime('1990-01-10'),
            'phoneNumber' => '0612345678',
            'emailAddress' => '[email protected]',
        ),
        'address' => array(
            'streetName' => 'Test',
            'houseNumber' => '10',
            'zipCode' => '1234AB',
            'city' => 'Test',
            'country' => 'NL',
        ),
        'invoiceAddress' => array(
            'initials' => 'IT',
            'lastName' => 'ITEST',
            'streetName' => 'Istreet',
            'houseNumber' => '70',
            'zipCode' => '5678CD',
            'city' => 'ITest',
            'country' => 'NL',
        ),
    ));

// Save this transactionid and link it to your order
$transactionId = $result->getTransactionId();

// Redirect the customer to this url to complete the payment
$redirect = $result->getRedirectUrl();

On the return page, redirect the user to the thank you page or back to checkout

require __DIR__ . '/vendor/autoload.php';

\Paynl\Config::setTokenCode('AT-1234-5678');
\Paynl\Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab');

$transaction = \Paynl\Transaction::getForReturn();

//manual transfer transactions are always pending when the user is returned
if( $transaction->isPaid() || $transaction->isPending()){
    // redirect to thank you page
    
} elseif($transaction->isCanceled()) {
    // redirect back to checkout
   
}

On the exchange script, process the order

require __DIR__ . '/vendor/autoload.php';

\Paynl\Config::setTokenCode('AT-1234-5678');
\Paynl\Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab');

$transaction = \Paynl\Transaction::getForExchange();

if($transaction->isPaid() || $transaction->isAuthorized()){
    // process the payment
} elseif($transaction->isCanceled()){
    // payment canceled, restock items
}

// always start your response with TRUE|
echo "TRUE| ";

// Optionally you can send a message after TRUE|, you can view these messages in the logs.
// https://admin.pay.nl/logs/payment_state
echo ($transaction->isPaid() || $transaction->isAuthorized())?'Paid':'Not paid';

Testing

Please run vendor/bin/phpunit --bootstrap vendor/autoload.php tests/ to test the application

sdk's People

Contributors

andypieters avatar woutse avatar kevinverschoor avatar annevelden avatar jstjanssens avatar backendtea avatar jornbakery avatar marcelschoolenberg avatar ivowams avatar marius-123 avatar daan-pay avatar bbrunekreeft avatar chris-kruining avatar grisgruis avatar rapid0o avatar grendel7 avatar jamalo avatar villhaber avatar curry684 avatar patrickkivits avatar fruitl00p avatar

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.