<?php require_once '../../src/Client.php'; require_once '../config.php'; $result = false; $errors = false; $action_request = false; $client = new VGS_Client($SPID_CREDENTIALS); $client->auth(); 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;
<?php session_start(); require_once '../../src/Client.php'; require_once '../config.php'; $SPID_CREDENTIALS[VGS_Client::REDIRECT_URI] = "http://{$_SERVER['HTTP_HOST']}/examples/api"; $client = new VGS_Client($SPID_CREDENTIALS); if (isset($_GET['refresh']) || !(isset($_SESSION['sdk']) && isset($_SESSION['sdk']['access_token']))) { try { $_SESSION['sdk']['access_token'] = $client->auth(); } catch (VGS_Client_Exception $e) { print_r($e); exit; } if (isset($_GET['refresh'])) { header("Location: " . $SPID_CREDENTIALS[VGS_Client::REDIRECT_URI]); exit; } } $client->setAccessToken($_SESSION['sdk']['access_token']); if (empty($_GET['offset'])) { $offset = 0; } else { $offset = $_GET['offset']; } $limit = 5; ?> <div id="top"> </div> <?php /** * /api/users
<?php // Start Session to save oauth token in session (instead of cookie) session_start(); // Root of php sdk repo define('BASE_DIR', realpath('../..')); // Include PHP SDK Client and a config file with credentials require_once BASE_DIR . '/src/Client.php'; require_once BASE_DIR . '/examples/config.php'; // overwrite redirect url to be HERE $SPID_CREDENTIALS[VGS_Client::REDIRECT_URI] = "http://{$_SERVER['HTTP_HOST']}/examples/client_login"; $SPID_CREDENTIALS[VGS_Client::COOKIE] = false; // disable cookie support for SDK // Instantiate the SDK client $client = new VGS_Client($SPID_CREDENTIALS); $client->argSeparator = '&'; // When a logout redirect comes from SPiD, delete the local session if (isset($_GET['logout'])) { unset($_SESSION['sdk']); } // Code is part of the redirect back from SPiD, redirect to self to remove it from URL // since it may only be used once, and it has been used to create session if (isset($_GET['code'])) { // Get/Check if we have local session, creates ones if code GET param comes $_SESSION['sdk'] = $client->getSession(); header("Location: " . $client->getCurrentURI(array(), array('code', 'login', 'logout'))); exit; } ?> <!doctype html> <html>
<!doctype html> <html> <head> <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
<!doctype html> <html> <head> <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 require_once '../src/Client.php'; require_once 'config.php'; if (!$SPID_CREDENTIALS) { die('ERROR: You must configure $SPID_CREDENTIALS in config.php first!'); } $client = new VGS_Client($SPID_CREDENTIALS); if (isset($_GET['logout'])) { $client->deleteSession(); } $session = $client->getSession(); if ($session && isset($_GET['code'])) { header("Location: " . $client->getCurrentURI(array(), array('code'))); exit; } ?> <!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');
<?php 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);
<?php $logfile = realpath(dirname(__FILE__)) . '/logs/log-' . date("Y-m-d") . '.txt'; $file_handle = fopen($logfile, 'a'); $logger = function ($msg) use($file_handle) { if (!fwrite($file_handle, $msg . PHP_EOL)) { throw new Exception("FILE LOG FAILED"); } }; require_once '../../src/Client.php'; require_once '../config.php'; $client = new VGS_Client($SPID_CREDENTIALS); $client->auth(); $post = file_get_contents("php://input"); $logger("==NEW=="); $logger($_SERVER['REQUEST_URI'] . ' ' . time()); $logger("Payload : {$post}"); $logger(print_r(apache_request_headers(), true)); // USE EITHER VERBOSE EXAMPLE OR SDK EXAMPLE /**************************************/ // START OF VERBOSE EXAMPLE function parse_signed_request($signed_request, $secret) { $arr = explode('.', $signed_request, 2); if (!$arr || count($arr) < 2) { return null; } list($encoded_sig, $payload) = $arr; // decode the data $sig = base64_url_decode($encoded_sig); $data = base64_url_decode($payload);