1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8
9/**
10 * Performs the second half of a trade - "offer mode" only and also cclite only
11 * The payment system does the first half ($user to manager account), this does manager to destination
12 *
13 * Work in progress
14 *
15 * @param string $main_user
16 * @param string $other_user
17 * @param float $price
18 * @param string $currency
19 * @param string $wanted = 'n'
20 */
21function payment_behavior_perform_trade($params)
22{
23	global $prefs, $cclitelib;
24	$userlib = TikiLib::lib('user');
25	$paymentlib = TikiLib::lib('payment');
26	$smarty = TikiLib::lib('smarty');
27	require_once 'lib/payment/cclitelib.php';
28
29	$default = [ 'wanted' => 'n', 'registry' => '', 'currency' => '' ];
30	$params = array_merge($default, $params);
31
32	$smarty->assign('ccresult_ok', false);
33
34
35	if (! $userlib->user_exists($params['main_user'])) {
36		$smarty->assign('ccresult2', "Perform Trade: Main user {$params['main_user']} not found");
37	}
38
39	if (! $userlib->user_exists($params['other_user'])) {
40		$smarty->assign('ccresult2', "Perform Trade: Other user {$params['other_user']} not found");
41	}
42
43	if (! $params['price'] || (int) $params['price'] === 0) {
44		$smarty->assign('ccresult2', "Perform Trade: price not set");
45	}
46
47	$result = $cclitelib->pay_user(
48		$params['price'],
49		$params['currency'],
50		$params['registry'],
51		$params['other_user'],
52		$params['main_user']
53	);
54
55	if (! empty($result)) {
56		$smarty->assign('ccresult2', $result);
57		$smarty->assign('ccresult_ok', (strpos($result, 'Transaction Accepted') !== false));
58	} else {
59		$smarty->assign('ccresult2', tr('Payment was sent but verification is not currently available (this feature is a work in progress)'));
60	}
61	return $result;
62}
63