<commit_before><?php

/**
 * HTTP method for starting a payment. Requires a user to be logged in.
 * @param {array} $_REQUEST
 * @param {string} $_REQUEST.payments Required. Should be either "authnet" or "stripe"
 *  @param {String} [$_REQUEST.publisherId=Q.Users.communityId] The publisherId of the Assets/product or Assets/service stream
 *  @param {String} [$_REQUEST.streamName] The name of the Assets/product or Assets/service stream
 *  @param {Number} [$_REQUEST.description] A short name or description of the product or service being purchased.
 *  @param {Number} [$_REQUEST.amount] the amount to pay. 
 *  @param {String} [$_REQUEST.currency="usd"] the currency to pay in. (authnet supports only "usd")
 *  @param {String} [$_REQUEST.token] the token obtained from the hosted forms
 */
function Assets_payment_post($params = array())
{
    $req = array_merge($_REQUEST, $params);
	Q_Valid::requireFields(array('payments', 'token', 'amount'), $req, true);
	// to be safe, we only start subscriptions from existing plans
	$publisherId = Q::ifset($req, 'publisherId', Users::communityId());
	$streamName = Q::ifset($req, 'streamName', null);
	if ($publisherId and $streamName) {
		$stream = Streams_Stream::fetch($publisherId, $publisherId, $streamName, true);
	}
	$userId = Users::loggedInUser(true)->id;

	// the currency will always be assumed to be "USD" for now
	// and the amount will always be assumed to be in dollars, for now
	$token = $req['token'];
	$currency = Q::ifset($req, 'currency', 'USD');
	$user = Users::fetch($userId);
	$metadata = array(
		'streamName' => $streamName,
		'publisherId' => $publisherId,
		'userId' => $userId,
		'description' => Q::ifset($req, 'description', null)
	);
	$charge = Assets::charge($req['payments'], $req['amount'], $currency, @compact('token', 'stream',  'metadata', 'user'));
	Q_Response::setSlot('charge', $charge);
}<commit_msg>Fixed Assets/payment/post handler which try to make Assets::charge and set "charge" slot according to charge processed. If "charge" slot == false it means that charge process failed.<commit_after><?php

/**
 * HTTP method for starting a payment. Requires a user to be logged in.
 * @param {array} $_REQUEST
 * @param {string} $_REQUEST.payments Required. Should be either "authnet" or "stripe"
 *  @param {String} [$_REQUEST.publisherId=Q.Users.communityId] The publisherId of the Assets/product or Assets/service stream
 *  @param {String} [$_REQUEST.streamName] The name of the Assets/product or Assets/service stream
 *  @param {Number} [$_REQUEST.description] A short name or description of the product or service being purchased.
 *  @param {Number} [$_REQUEST.amount] the amount to pay. 
 *  @param {String} [$_REQUEST.currency="usd"] the currency to pay in. (authnet supports only "usd")
 *  @param {String} [$_REQUEST.token] the token obtained from the hosted forms
 */
function Assets_payment_post($params = array())
{
    $req = array_merge($_REQUEST, $params);
	Q_Valid::requireFields(array('payments', 'amount'), $req, true);
	// to be safe, we only start subscriptions from existing plans
	$publisherId = Q::ifset($req, 'publisherId', null);
	$streamName = Q::ifset($req, 'streamName', null);
	$stream = null;
	if ($publisherId and $streamName) {
		$stream = Streams_Stream::fetch($publisherId, $publisherId, $streamName, true);
	}
	$userId = Users::loggedInUser(true)->id;

	// the currency will always be assumed to be "USD" for now
	// and the amount will always be assumed to be in dollars, for now
	$currency = Q::ifset($req, 'currency', 'USD');
	$user = Users::fetch($userId, true);
	$description = Q::ifset($req, 'description', null);
	$metadata = array(
		'streamName' => $streamName,
		'publisherId' => $publisherId,
		'userId' => $userId
	);

	// need to set false because null will lead to unset slot because isset(null)=false
	$charge = false;
	try {
		$charge = Assets::charge($req['payments'], $req['amount'], $currency, @compact('user', 'description', 'metadata'));
	} catch (Exception $e) {

	}

	if ($charge && $stream && $stream->type === 'Assets/subscription') {
		$stream->setAttribute('lastChargeTime', time());
		$stream->changed();
	}

	Q_Response::setSlot('charge', $charge);
}
{'fraction_non_alphanumeric': 0.15580399619410085, 'fraction_numerical': 0.0, 'mean_word_length': 5.14766081871345, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4260999', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1314, 'n_words': 425}