<commit_before><?php namespace Tuurbo\AmazonPayment;

use GuzzleHttp;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
use Tuurbo\AmazonPayment\Exceptions;

class AmazonPaymentClient {

	const SERVICE_VERSION = '2013-01-01';

	private $sellerId;
	private $accessKey;
	private $secretKey;
	private $signatureVersion = 2;
	private $signatureMethod = 'HmacSHA256';
	private $serviceUrl;

	public $connect;

	function __construct($sellerId, $accessKey, $secretKey, $sandboxMode)
	{
		$this->sellerId = $sellerId;
		$this->accessKey = $accessKey;
		$this->secretKey = $secretKey;
		$this->connect = new GuzzleHttp\Client();

		if ($sandboxMode === true) {
			$this->serviceUrl = 'https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01';
		} else {
			$this->serviceUrl = 'https://mws.amazonservices.com/OffAmazonPayments/2013-01-01';
		}
	}

	public function setupAmazonCall($actionName, array $parameters)
	{
		$parameters = $this->addRequiredParameters([
			'SellerId' => $this->sellerId,
			'Action' => $actionName
		] + $parameters);

		$response = $this->postToAmazon($parameters);

		return $response['data'];
	}

	private function postToAmazon(array $params)
	{
		// Retry 500 and 503 responses
		$retry = new RetrySubscriber([
			'filter' => RetrySubscriber::createStatusFilter(),
			'max' => 3, // 4x total
			'delay' => function () { return 400; } // 0.4 seconds
		]);

		$client = $this->connect->getEmitter()->attach($retry);
		$resp = $client->post($this->serviceUrl, ['exceptions' => false, 'body' => $params]);

		$statusCode = (int) $resp->getStatusCode();

		if ($statusCode === 500 || $statusCode === 503) {
			throw new AmazonPaymentException(null, 'Internal Server Error', $statusCode);
		}

		$resp = $resp->xml();
		$resp = json_decode(json_encode($resp), true);

		if (isset($resp['Error']) && $resp['Error']['Code']) {
			$requestId = isset($resp['RequestId']) ? $resp['RequestId'] : null;<commit_msg>fix client connection<commit_after><?php namespace Tuurbo\AmazonPayment;

use GuzzleHttp;
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
use Tuurbo\AmazonPayment\Exceptions;

class AmazonPaymentClient {

	const SERVICE_VERSION = '2013-01-01';

	private $sellerId;
	private $accessKey;
	private $secretKey;
	private $signatureVersion = 2;
	private $signatureMethod = 'HmacSHA256';
	private $serviceUrl;

	public $connect;

	function __construct($sellerId, $accessKey, $secretKey, $sandboxMode)
	{
		$this->sellerId = $sellerId;
		$this->accessKey = $accessKey;
		$this->secretKey = $secretKey;
		$this->connect = new GuzzleHttp\Client();

		if ($sandboxMode === true) {
			$this->serviceUrl = 'https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01';
		} else {
			$this->serviceUrl = 'https://mws.amazonservices.com/OffAmazonPayments/2013-01-01';
		}
	}

	public function setupAmazonCall($actionName, array $parameters)
	{
		$parameters = $this->addRequiredParameters([
			'SellerId' => $this->sellerId,
			'Action' => $actionName
		] + $parameters);

		$response = $this->postToAmazon($parameters);

		return $response['data'];
	}

	private function postToAmazon(array $params)
	{
		// Retry 500 and 503 responses
		$retry = new RetrySubscriber([
			'filter' => RetrySubscriber::createStatusFilter(),
			'max' => 3, // 4x total
			'delay' => function () { return 400; } // 0.4 seconds
		]);

		$client = $this->connect;
		$client->getEmitter()->attach($retry);
		$resp = $client->post($this->serviceUrl, ['exceptions' => false, 'body' => $params]);
		$statusCode = (int) $resp->getStatusCode();

		if ($statusCode === 500 || $statusCode === 503) {
			throw new AmazonPaymentException(null, 'Internal Server Error', $statusCode);
		}

		$resp = $resp->xml();
		$resp = json_decode(json_encode($resp), true);

		if (isset($resp['Error']) && $resp['Error']['Code']) {
			$requestId = isset($resp['RequestId']) ? $resp['RequestId'] : null;
{'fraction_non_alphanumeric': 0.17198764160659114, 'fraction_numerical': 0.02420185375901133, 'mean_word_length': 4.824587706146927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '940413', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1292, 'n_words': 256}