CompletePurchaseRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 7
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 4 1
A sendData() 0 16 4
1
<?php
2
3
namespace Omnipay\BPOINT\Message;
4
5
/**
6
 * BPOINT Complete Purchase Request
7
 *
8
 * Example response:
9
 * http://example.com/txnreceipt?ResponseCode=0&ResponseText=Success&ResultKey=13cfa799-8278-4872-a705-7ed49d516c0b
10
 */
11
class CompletePurchaseRequest extends PurchaseRequest
12
{
13
    /** @see PurchaseRequest::$action */
14
    protected $action = 'withauthkey';
15
16 3
    public function getData()
17
    {
18 3
        return $this->httpRequest->request->all();
19
    }
20
21
    /**
22
     * Make request for additional details as per {@see https://www.bpoint.com.au/developers/v3/#!#threepartyrettranres}
23
     */
24 3
    public function sendData($data)
25
    {
26
        // if we have a valid API response and a result key, let's get more detail about the transaction
27 3
        if (isset($data['ResponseCode']) && $data['ResponseCode'] == 0 && isset($data['ResultKey'])) {
28
            // submit request with the returned result key
29 2
            $httpResponse = $this->httpClient->request(
30 2
                'GET',
31 2
                $this->getEndpoint()."/".$data['ResultKey'],
32 2
                ['Authorization' => $this->getAuthHeader()]
33
            );
34 2
            // get response data
35
            $responseData = json_decode($httpResponse->getBody()->getContents(), true);
36 2
            $data = array_merge($data, $responseData['TxnResp']);
37 2
        }
38
        return $this->response = new CompletePurchaseResponse($this, $data);
39 3
    }
40
}
41