-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
executable file
·67 lines (46 loc) · 1.99 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once(dirname(__FILE__).'/../vingd/vingd.php');
// sandbox backend:
$v = new Vingd("test@vingd.com", "123", Vingd::URL_ENDPOINT_SANDBOX, Vingd::URL_FRONTEND_SANDBOX);
// in production use:
//$v = new Vingd("<vingd-login-username>", "<vingd-login-password>");
//
// profile/account
//
$profile = $v->getUserProfile();
print "I ({$profile['name']}) registered on {$profile['timestamp_created']}.\n";
$balance = $v->getAccountBalance();
echo "My balance is VINGD $balance.\n";
//
// voucher rewarding
//
$voucher = $v->createVoucher(1.00, '+7 days');
echo "I'm rewarding you with this 1 vingd voucher ({$voucher['code']}): {$voucher['urls']['redirect']}.\n";
$vouchers = $v->getActiveVouchers();
echo 'Now I have ', count($vouchers), " active vouchers.\n";
//
// selling
//
$oid = $v->createObject("My test object", "http://localhost:666/");
echo "I've just created an object, just for you. OID is $oid.\n";
$oid2 = $v->updateObject($oid, "New object name", "http://localhost:777/");
echo "Object updated.\n";
$object = $v->getObject($oid);
echo "Object last modified at {$object['timestamp_modified']}, new url is {$object['description']['url']}.\n";
$objects = $v->getObjects();
echo 'I have ', count($objects), " registered objects I can sell.\n";
$order = $v->createOrder($oid, 2.00, "some optional context");
echo "I've also created an order (id={$order['id']}) for the object (oid={$order['object']['id']}): {$order['urls']['redirect']}.\n";
echo "After you buy it, enter the Token ID here ('tid' param on callback url): ";
$tid = fgets(STDIN);
$purchase = $v->verifyPurchase(array('oid' => $oid, 'tid' => $tid));
$huid_buyer = $purchase['huid'];
echo "Purchase verified (buyer's HUID = $huid_buyer, context = '{$purchase['context']}').\n";
$commit = $v->commitPurchase($purchase);
echo "Content served, and purchase committed.\n";
//
// direct rewarding
//
$reward = $v->rewardUser($huid_buyer, 0.75, 'Testing direct rewarding');
echo "User rewarded (transfer id = {$reward['transfer_id']}).\n";
?>