Code Duplication    Length = 42-43 lines in 2 locations

src/MtnCollection.php 1 location

@@ 7-49 (lines=43) @@
4
5
use PatricPoba\MtnMomo\Exceptions\MtnMomoException;
6
7
class MtnCollection extends MtnMomo 
8
{
9
    const PRODUCT = 'collection';
10
 
11
12
    protected function requestUrl(string $endpointName, array $params = []) : string
13
    { 
14
        switch ($endpointName) {
15
            case 'token':  
16
                $urlSegment = '/collection/token/' ; // trailing slash mandatory
17
                break;
18
19
            case 'createTransaction': 
20
                $urlSegment = '/collection/v1_0/requesttopay';
21
                break;
22
                 
23
            case 'getTransaction': 
24
                $urlSegment = "/collection/v1_0/requesttopay/{$params['referenceId']}";
25
                break;
26
 
27
            case 'balance': 
28
                $urlSegment = '/collection/v1_0/account/balance';
29
                break;
30
 
31
            case 'accountholderActive': 
32
                $urlSegment = "/collection/v1_0/accountholder/MSISDN/{$params['accountHolderId']}/active";
33
                break;
34
            
35
            default:
36
                throw new MtnMomoException("Unknown Api endpoint - {$endpointName}.");
37
                break;
38
        }
39
 
40
        return $this->config->baseUrl . $urlSegment;
41
    }
42
 
43
   
44
    public function requestToPay(array $data, string $transactionUuid = null)
45
    {
46
        return parent::createTransaction($data, $transactionUuid);
47
    }
48
49
}
50

src/MtnDisbursement.php 1 location

@@ 7-48 (lines=42) @@
4
5
use PatricPoba\MtnMomo\Exceptions\MtnMomoException;
6
7
class MtnDisbursement extends MtnMomo 
8
{
9
    const PRODUCT = 'disbursement';
10
11
12
    protected function requestUrl(string $endpointName, array $params = []) : string
13
    { 
14
        switch ($endpointName) {
15
            case 'token':  
16
                $urlSegment = '/disbursement/token/' ; // trailing slash mandatory
17
                break;
18
19
            case 'postTransaction': 
20
                $urlSegment = '/disbursement/v1_0/transfer';
21
                break;
22
                 
23
            case 'getTransaction': 
24
                $urlSegment = "/disbursement/v1_0/transfer/{$params['referenceId']}";
25
                break;
26
 
27
            case 'balance': 
28
                $urlSegment = '/disbursement/v1_0/account/balance';
29
                break;
30
 
31
            case 'accountholder': 
32
                $urlSegment = "/disbursement/v1_0/accountholder/MSISDN/{$params['accountHolderId']}/active";
33
                break;
34
            
35
            default:
36
                throw new MtnMomoException("Unknown api endpoint - {$endpointName}.");
37
                break;
38
        }
39
 
40
        return $this->config->baseUrl . $urlSegment;
41
    }
42
43
    public function transfer(array $params, string $transactionUuid = null)
44
    {
45
        return parent::createTransaction($params, $transactionUuid);
46
    }
47
    
48
}
49