<commit_before><?php

namespace Best365Bundle\Manager;

use Best365Bundle\Entity\PaymentGateway;
use Doctrine\ORM\EntityManager;
use PaymentSuite\FreePaymentBundle\Services\FreePaymentMethodFactory;
use PaymentSuite\PaymentCoreBundle\Services\Interfaces\PaymentBridgeInterface;
use PaymentSuite\PaymentCoreBundle\Services\PaymentEventDispatcher;


class Best365PaymentManager
{

	private $em;
	/**
	 * @var FreePaymentMethodFactory
	 *
	 * PaymentMethodInterface factory
	 */
	private $methodFactory;

	/**
	 * @var PaymentBridgeInterface
	 *
	 * Payment bridge interface
	 */
	private $paymentBridge;

	/**
	 * @var PaymentEventDispatcher
	 *
	 * Payment event dispatcher
	 */
	private $paymentEventDispatcher;

	/**
	 * Construct method for free payment manager.
	 *
	 * @param FreePaymentMethodFactory $methodFactory          PaymentMethodInterface factory
	 * @param PaymentBridgeInterface   $paymentBridge          Payment Bridge
	 * @param PaymentEventDispatcher   $paymentEventDispatcher Event Dispatcher
	 * @param EntityManager			   $em					   Entity Manager
	 */
	public function __construct(
		FreePaymentMethodFactory $methodFactory,
		PaymentBridgeInterface $paymentBridge,
		PaymentEventDispatcher $paymentEventDispatcher,
		EntityManager $em
	)
	{
		$this->em = $em;
		$this->methodFactory = $methodFactory;
		$this->paymentBridge = $paymentBridge;
		$this->paymentEventDispatcher = $paymentEventDispatcher;
	}

	public function generateOrder()
	{
		$paymentMethod = $this
			->methodFactory
			->create();

		/**
		 * At this point, order must be created given a card, and placed in
		 * PaymentBridge.
		 *
		 * So, $this->paymentBridge->getOrder() must return an object
		 */
		$this
			->paymentEventDispatcher
			->notifyPaymentOrderLoad(
				$this->paymentBridge,
				$paymentMethod
			);

		/**
		 * Order exists right here.
		 */
		$this
			->paymentEventDispatcher
			->notifyPaymentOrderCreated(
				$this->paymentBridge,
				$paymentMethod
			);
	}

	/**
	 * Generate Epayment array
	 * @param $request
	 * @return array
	 */
	public function getEpaymentRequestArray($request)
	{
		// get all parameters in request
		$params = $request->request->all();
		$arr = '{"merchant_id":"af54f0607d474924898465b256b1ff7f","increment_id":"96","grandtotal":"0.05","receipt_amount":"0.05","currency":"CNY","trade_no":"4008722001201703274804554623","service":"create_scan_code","rate":"4.8601","notify_time":"2017-03-27 10:49:43","created_at":"2017-03-27 10:49:02","gmt_payment":"2017-03-27 10:49:03","payment_channels":"WECHAT","subject":"Best365","openid":"o4FhqwHgCi1ttWmsVFlKZuPGoMzw","describe":"Best365","trade_status":"TRADE_SUCCESS","signature":"8d5803a6ad65ec3e7dd2b87836d22ee2","sign_type":"MD5"}';
		$params = json_decode($arr, true);
		// construct signature array
		unset($params['signature']);
		unset($params['sign_type']);

		return $params;
	}

	/**
	 * Generate Epayment signature for validation
	 * @param $arr
	 * @param $key
	 * @return string
	 */
	public function generateEpaymentSignature($arr, $key)
	{
		ksort($arr);
		$str = '';
		foreach ($arr as $k => $v) {
			if (strlen($str) > 0) {
				$str .= '&';
			}
			$str .= $k . '=' . $v;
		}<commit_msg>remove test data from code<commit_after><?php

namespace Best365Bundle\Manager;

use Best365Bundle\Entity\PaymentGateway;
use Doctrine\ORM\EntityManager;
use PaymentSuite\FreePaymentBundle\Services\FreePaymentMethodFactory;
use PaymentSuite\PaymentCoreBundle\Services\Interfaces\PaymentBridgeInterface;
use PaymentSuite\PaymentCoreBundle\Services\PaymentEventDispatcher;


class Best365PaymentManager
{

	private $em;
	/**
	 * @var FreePaymentMethodFactory
	 *
	 * PaymentMethodInterface factory
	 */
	private $methodFactory;

	/**
	 * @var PaymentBridgeInterface
	 *
	 * Payment bridge interface
	 */
	private $paymentBridge;

	/**
	 * @var PaymentEventDispatcher
	 *
	 * Payment event dispatcher
	 */
	private $paymentEventDispatcher;

	/**
	 * Construct method for free payment manager.
	 *
	 * @param FreePaymentMethodFactory $methodFactory          PaymentMethodInterface factory
	 * @param PaymentBridgeInterface   $paymentBridge          Payment Bridge
	 * @param PaymentEventDispatcher   $paymentEventDispatcher Event Dispatcher
	 * @param EntityManager			   $em					   Entity Manager
	 */
	public function __construct(
		FreePaymentMethodFactory $methodFactory,
		PaymentBridgeInterface $paymentBridge,
		PaymentEventDispatcher $paymentEventDispatcher,
		EntityManager $em
	)
	{
		$this->em = $em;
		$this->methodFactory = $methodFactory;
		$this->paymentBridge = $paymentBridge;
		$this->paymentEventDispatcher = $paymentEventDispatcher;
	}

	public function generateOrder()
	{
		$paymentMethod = $this
			->methodFactory
			->create();

		/**
		 * At this point, order must be created given a card, and placed in
		 * PaymentBridge.
		 *
		 * So, $this->paymentBridge->getOrder() must return an object
		 */
		$this
			->paymentEventDispatcher
			->notifyPaymentOrderLoad(
				$this->paymentBridge,
				$paymentMethod
			);

		/**
		 * Order exists right here.
		 */
		$this
			->paymentEventDispatcher
			->notifyPaymentOrderCreated(
				$this->paymentBridge,
				$paymentMethod
			);
	}

	/**
	 * Generate Epayment array
	 * @param $request
	 * @return array
	 */
	public function getEpaymentRequestArray($request)
	{
		// get all parameters in request
		$params = $request->request->all();
		
		// construct signature array
		unset($params['signature']);
		unset($params['sign_type']);

		return $params;
	}

	/**
	 * Generate Epayment signature for validation
	 * @param $arr
	 * @param $key
	 * @return string
	 */
	public function generateEpaymentSignature($arr, $key)
	{
		ksort($arr);
		$str = '';
		foreach ($arr as $k => $v) {
			if (strlen($str) > 0) {
				$str .= '&';
			}
			$str .= $k . '=' . $v;
		}
{'fraction_non_alphanumeric': 0.12517193947730398, 'fraction_numerical': 0.026478679504814306, 'mean_word_length': 4.098159509202454, 'pattern_counts': {'":': 18, '<': 5, '<?xml version=': 0, '>': 39, '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': '6196954', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1692, 'n_words': 364}