Giter VIP home page Giter VIP logo

lib-wallet-php-client's Introduction

PHP client for Paysera.com Wallet API

This is repository for PHP client, used with Paysera.com Wallet API.

OAuth example

<?php

// setup autoloader for Paysera Wallet API library
require_once '../../lib-wallet-php-client/src/Paysera/WalletApi/Autoloader.php';
Paysera_WalletApi_Autoloader::register();

// credentials for API
$clientId = 'CLIENT_ID';
// $secret - shared secret to use in MAC auth
$secret = 'SECRET';
// or information about certificate to use in SSL auth
//$secret = Paysera_WalletApi_Http_ClientCertificate::create()
//    ->setCertificatePath('/path/to/cert.crt')
//    ->setPrivateKeyPath('/path/to/private.key');

// create main object to use for all functionality
$api = new Paysera_WalletApi($clientId, $secret);

// for sandbox environment, use the following code instead:
// $api = new Paysera_WalletApi($clientId, $secret, Paysera_WalletApi_Util_Router::createForSandbox());

// get service, responsible for OAuth code grant type integration
$oauth = $api->oauthConsumer();

// example how to get ask and get information about paysera.com user
session_start();
try {
    if (!isset($_SESSION['token'])) {           // no token in session - let's get the token
        $token = $oauth->getOAuthAccessToken(); // this gets code query parameter if available and exchanges for token
        if ($token === null) {                  // no code parameter - redirect user to authentication endpoint
            $redirectUri = null;                // URL of this file; it's optional parameter
            header('Location: ' . $oauth->getAuthorizationUri(array(            // scopes are optional, no scope allows to get user ID/wallet ID
                Paysera_WalletApi_OAuth_Consumer::SCOPE_EMAIL,                  // to get user's main email address
                // Paysera_WalletApi_OAuth_Consumer::SCOPE_IDENTITY,            // this scope allows to get personal code, name and surname
                // Paysera_WalletApi_OAuth_Consumer::SCOPE_FULL_NAME,           // use this scope if only name and surname is needed
                // Paysera_WalletApi_OAuth_Consumer::SCOPE_IDENTITY_OFFLINE,    // this allows to get identity by user ID, after token has expired, using API, not related to token
            ), $redirectUri));
        } else {
            $_SESSION['token'] = $token;
        }
    }

    if (isset($_SESSION['token'])) {
        $tokenRelatedClient = $api->walletClientWithToken($_SESSION['token']);
        echo '<pre>';
        $user = $tokenRelatedClient->getUser();
        var_dump($user);
        // $user->getId();                                            // you can save user ID (on paysera.com), user's email etc.
        // var_dump($api->walletClient()->getUserIdentity($userId));  // if you have offline scope, you can get info by user ID later
        echo '</pre>';
        $_SESSION['token'] = $tokenRelatedClient->getCurrentAccessToken();     // this could be refreshed, re-save
    }

} catch (Exception $e) {
    echo '<pre>', $e, '</pre>';
}

Contacts

If you have any further questions feel free to contact us:

„Paysera LT“, UAB
Mėnulio g. 7
LT-04326 Vilnius
Email: [email protected]
Tel. +370 (5) 2 07 15 58

lib-wallet-php-client's People

Contributors

krauzand avatar mariusbalcytis avatar notrix avatar pelanis avatar romasnavasinskas avatar stagniunas avatar tomas7777 avatar vbartusevicius avatar velser avatar vytautasgimbutas 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.