Exemple #1
0
if ($_POST) {
    $action_request = true;
    $errors = array();
    $data = array('requestReference' => '', 'clientReference' => '', 'paymentOptions' => '', 'purchaseFlow' => '', 'sellerUserId' => '', 'tag' => '');
    $data = array_filter(array_intersect_key($_POST, $data));
    $items = array(array('name' => $_POST['productName'], 'price' => $_POST['productPrice']));
    $data['items'] = json_encode($items);
    if (!empty($data['sellerUserId'])) {
        $data['type'] = 2;
    } else {
        $data['type'] = 4;
    }
    $hash = $client->createHash($data);
    $data['hash'] = $hash;
    try {
        $result = $client->api("/user/{$_POST['userId']}/charge", 'POST', $data);
    } catch (VGS_Client_Exception $e) {
        $errors = $client->container['meta'] ?: ($client->container['error'] ?: $e->getMessage());
    }
} else {
    if (!empty($_GET['action'])) {
        $action_request = true;
        if ($_GET['action'] == 'capture') {
            try {
                $result = $client->api("/order/{$_GET['orderId']}/capture", 'POST', array());
            } catch (VGS_Client_Exception $e) {
                $errors = $client->container['meta'] ?: ($client->container['error'] ?: $e->getMessage());
            }
        } else {
            if ($_GET['action'] == 'credit') {
                try {
Exemple #2
0
$client->setAccessToken($_SESSION['sdk']['access_token']);
if (empty($_GET['offset'])) {
    $offset = 0;
} else {
    $offset = $_GET['offset'];
}
$limit = 5;
?>
<div id="top">&nbsp;</div>
<?php 
/**
 * /api/users
 * ---------------------------------------------------------------------------------------------------------------------
 */
$users_endpoint = $client->getApiURI('/users', array('since' => 'last year', 'until' => 'today', 'limit' => $limit, 'offset' => $offset, 'filters' => 'updated'));
echo '<br/><br/><strong>/users: </strong> <a href="' . $users_endpoint . '" target="blank">' . $users_endpoint . '</a>';
?>
<br/><br/><a href="?offset=<?php 
echo $offset + $limit;
?>
">Next page</a><?php 
try {
    $users = $client->api('/users', array('since' => 'last year', 'until' => 'today', 'limit' => $limit, 'offset' => $offset, 'filters' => 'updated'));
} catch (VGS_Client_Exception $e) {
    echo $e->getMessage();
    ?>
        <br/><a href="?refresh=1">Refresh token</a>
        <?php 
}
echo '<pre>' . print_r($users, true) . '</pre>';
echo '<div id="api-user-do-settings">&nbsp;</div><a href="#top">Back To Top</a>';
Exemple #3
0
<h1>SPiD Client user login and authentication example</h1>
<?php 
// May get credential errors
if (isset($_GET['error'])) {
    echo '<h3 id="message" style="color:red">' . $_GET['error'] . '</h3>';
}
$session = isset($_SESSION['sdk']) ? $_SESSION['sdk'] : false;
// If we have session, that means we are logged in.
if ($session) {
    // Authorize the client with the session saved user token
    $client->setAccessToken($session['access_token']);
    // Try since SDK may throw VGS_Client_Exceptions:
    //   For instance if the client is blocked, has exceeded ratelimit or lacks access right
    try {
        // Grab the logged in user's User Object, /me will include the entire User object
        $user = $client->api('/me');
        echo '<h3 id="message">Welcome</h3>
            <h4>Logged in as <span id="name" style="color:blue">' . $user['displayName'] . '</span> <small>id: <span id="userId" style="color:green">' . $user['userId'] . '</span> email: <span id="email" style="color:purple">' . $user['email'] . '</span></h4>';
        if (isset($_GET['order_id'])) {
            echo '<pre>' . print_r($client->api('/order/' . $_GET['order_id']), true) . '</pre>';
        }
    } catch (VGS_Client_Exception $e) {
        if ($e->getCode() == 401) {
            // access denied, in case the access token is expired, try to refresh it
            try {
                // refresh tokens using the session saved refresh token
                $client->refreshAccessToken($session['refresh_token']);
                $_SESSION['sdk']['access_token'] = $client->getAccessToken();
                $_SESSION['sdk']['refresh_token'] = $client->getRefreshToken();
                // Sesssion refreshed with valid tokens
                header("Location: " . $client->getCurrentURI(array(), array('code', 'login', 'error', 'logout', 'order_id', 'spid_page')));
Exemple #4
0
    <title>Paylink App</title>
    <meta charset="utf-8">
</head>
<body>

<?php 
$result = false;
$errors = array();
if ($_POST) {
    require_once '../../src/Client.php';
    require_once '../config.php';
    $client = new VGS_Client($SPID_CREDENTIALS);
    $client->auth();
    $data = array('purchaseFlow' => $_POST['purchaseFlow'], 'title' => $_POST['title'], 'items' => array(array('vat' => 2500, 'price' => $_POST['price'] * 100, 'description' => $_POST['description'])));
    try {
        $result = $client->api('/paylink', 'POST', $data);
    } catch (VGS_Client_Exception $e) {
        $errors = $client->container['meta'] ?: ($client->container['error'] ?: $e->getMessage());
    }
}
if ($result) {
    ?>
    <table>
        <tr><th>title</th><td><?php 
    echo $result['title'];
    ?>
</td></tr>
        <tr><th>expires</th><td><?php 
    echo $result['expires'];
    ?>
</td></tr>
Exemple #5
0
    <title>Paylink App</title>
    <meta charset="utf-8">
</head>
<body>

<?php 
$result = false;
$errors = array();
if ($_POST) {
    require_once '../../src/Client.php';
    require_once '../config.php';
    $client = new VGS_Client($SPID_CREDENTIALS);
    $client->auth();
    $data = array('orderItemId' => $_POST['order_item_id'], 'amount' => $_POST['amount']);
    try {
        $result = $client->api('/order/' . $_POST['order_id'] . '/capture', 'POST', $data);
    } catch (VGS_Client_Exception $e) {
        $errors = $client->container['meta'] ?: ($client->container['error'] ?: $e->getMessage());
    }
}
?>
    <h3>Capture order</h3>
    <form method="POST">
        <label>Order ID<br><input type="text" name="order_id" value="" /></label><br>
        <label>Order Item ID<br><input type="text" name="order_item_id" value="" /></label><br>
        <label>Amount<br><input type="text" name="amount" value="" /></label><br>
        <input type="submit" />
    </form>
    <?php 
if ($errors) {
    echo '<div class="border:1px solid red">';
Exemple #6
0
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
	<link href="css/prettify.css" type="text/css" rel="stylesheet" />	
	<link rel="stylesheet" href="css/default.css" />
	<script src="js/jquery-1.5.2.min.js"></script>
	<script src="js/jquery.tmpl.js"></script>
	<script src="js/format-json.js"></script>			
	<script src="js/global.js"></script>
	<script>
		VG.api.methods = <?php 
try {
    $res = $client->api('/endpoints');
    echo json_encode($res);
} catch (\Exception $e) {
    echo '[]';
}
?>
;
			
		$(document).ready(function () {
			
			
			$('#methodsTemplate').tmpl({'methods': VG.api.methods}).appendTo('#methods');

			$.each(VG.events, function (selector, object) {
				var $element = $(selector);
				$.each(object, function (type, func) {
Exemple #7
0
require_once '../src/Client.php';
require_once 'config.php';
$client = new VGS_Client($SPID_CREDENTIALS);
$skipKeys = array('method', 'httpMethod');
$params = array();
foreach ($_REQUEST as $key => $value) {
    if (empty($value) || in_array($key, $skipKeys)) {
        continue;
    }
    $params[$key] = $value;
}
$path = $_REQUEST['method'];
$method = $_REQUEST['httpMethod'];
try {
    $response = $client->api($path, $method, $params);
} catch (VGS_Client_Exception $e) {
    header('Content-type: application/json');
    if ($container = json_decode($e->getRaw(), true)) {
        echo json_encode(array('request' => $_REQUEST, 'error' => $e->getMessage(), 'result' => $e->getResult(), 'container' => $container));
        exit;
    }
    echo json_encode(array('request' => $_REQUEST, 'error' => $e->getMessage(), 'result' => $e->getResult()));
    exit;
}
header('Content-type: application/json');
if (EXPLORER_SHOW_CONTAINER) {
    echo json_encode($client->container);
} else {
    echo json_encode($response);
}
Exemple #8
0
// START OF SDK EXAMPLE
//$data = $client->parseSignedRequest($post);
// END OF SDK EXAMPLE
/**************************************/
if (!$data) {
    $logger(" BAD SIGNATURE!");
    // for testing negative response, use a different response code
    header('HTTP/1.0 401 Unauthorized', true, 401);
    return;
}
if ($data && is_array($data)) {
    switch ($data['object']) {
        case 'order':
            foreach ($data['entry'] as $object) {
                $logger("Looking up : Order[" . $object['orderId'] . ']');
                $order = $client->api('/order/' . $object['orderId'], 'GET');
                $logger("Order:" . PHP_EOL . print_r($order, true));
            }
            break;
        case 'user':
            foreach ($data['entry'] as $object) {
                $logger("Looking up : User[" . $object['userId'] . ']');
                $user = $client->api('/user/' . $object['userId'], 'GET');
                $logger("User:"******"I dont know this type [{$data['object']}]");
            break;
    }
}