Gateway::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PHPieces\ANZGateway;
4
5
use GuzzleHttp\Client;
6
use PHPieces\ANZGateway\enums\FormFields\MerchantFields;
7
8
class Gateway
9
{
10
11
	/**
12
	 * @param Client
13
	 */
14
	private $client;
15
16
17
	/**
18
	 *
19
	 * @var String
20
	 */
21
	private $merchantID;
22
23
24
	/**
25
	 *
26
	 * @var String
27
	 */
28
	private $merchantAccessCode;
29
30
	/**
31
	 * @var string
32
	 */
33
	private $url;
34
35
36
	/**
37
	 *
38
	 * @var array
39
	 */
40
	private $data = [];
41
42 9
	public function __construct(Client $client, $url = 'https://migs.mastercard.com.au/vpcdps')
43
	{
44 9
		$this->client = $client;
45 9
		$this->url = $url;
46 9
	}
47
48 3
	public static function create() : self
49
	{
50
51 3
		return new self(new Client([
52 3
			'base_uri' => 'https://migs.mastercard.com.au/vpcdps',
53
		]));
54
	}
55
56
	public function setUrl(string $url) : void 
57
	{
58
		$this->url = $url;
59
	}
60
61 3
	public function setMerchantID(string $id) : void
62
	{
63 3
		$this->merchantID = $id;
64 3
	}
65
66 3
	public function setAccessCode(string $code) : void
67
	{
68 3
		$this->merchantAccessCode = $code;
69 3
	}
70
71 3
	public function purchase(array $data) : self
72
	{
73 3
		$this->data = $data;
74 3
		return $this;
75
	}
76
77 3
	public function send() : Charge
78
	{
79 3
		$request = ChargeRequest::create($this->getData());
80 3
		return $this->charge($request);
81
	}
82
83 3 View Code Duplication
	private function getData() : array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
	{
85 3
		return array_merge(
86 3
			$this->data,
87
			[
88 3
				MerchantFields::MERCHANT_ID         => $this->merchantID,
89 3
				MerchantFields::MERCHANT_ACCESSCODE => $this->merchantAccessCode,
90
			]
91
		);
92
	}
93
94 6
	public function charge(ChargeRequest $charge) : Charge
95
	{
96 6
		$response = $this->client->request('POST', $this->url, ['form_params' => $charge->toArray()]);
97
98 6
		return new Charge($response->getBody()->getContents());
99
	}
100
}
101