Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
85.71% |
6 / 7 |
CRAP | |
80.00% |
24 / 30 |
| Mecom\Transaction\Client | |
0.00% |
0 / 1 |
|
85.71% |
6 / 7 |
7.39 | |
80.00% |
24 / 30 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| setToken | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| initialize | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
| fail | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
| process | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
| succeed | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 6 |
|||
| headers | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| <?php | |
| namespace Mecom\Transaction; | |
| use Mecom\Transaction\Models\Transaction; | |
| use GuzzleHttp\Client as HttpClient; | |
| use Mecom\Transaction\Traits\Requestor; | |
| class Client implements TransactionSvc | |
| { | |
| use Requestor; | |
| protected $token; | |
| protected $client; | |
| public function __construct(HttpClient $client, string $token = null) | |
| { | |
| $this->token = $this->setToken($token); | |
| $this->client = $client; | |
| } | |
| public function setToken(string $token = null): void | |
| { | |
| $this->token = $token; | |
| } | |
| public function initialize(array $data) : Transaction | |
| { | |
| $response = $this->request( | |
| 'POST', | |
| '/', | |
| $data, | |
| $this->headers() | |
| ); | |
| return new Transaction($response['data']); | |
| } | |
| public function fail(string $transactionId, array $data) : Transaction | |
| { | |
| $response = $this->request( | |
| 'PUT', | |
| $transactionId . '/fail', | |
| $data, | |
| $this->headers() | |
| ); | |
| return new Transaction($response['data']); | |
| } | |
| public function process(string $transactionId, array $data) : Transaction | |
| { | |
| $response = $this->request( | |
| 'PUT', | |
| $transactionId . '/process', | |
| $data, | |
| $this->headers() | |
| ); | |
| return new Transaction($response['data']); | |
| } | |
| public function succeed(string $transactionId, array $data) : Transaction | |
| { | |
| $response = $this->request( | |
| 'PUT', | |
| $transactionId . '/succeed', | |
| $data, | |
| $this->headers() | |
| ); | |
| return new Transaction($response->toArray()); | |
| } | |
| private function headers() | |
| { | |
| return [ | |
| 'Authorization' => 'Bearer '.$this->token, | |
| ]; | |
| } | |
| } |