示例#1
0
$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;
        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());
            }