Issues (20)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/MtnMomo.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PatricPoba\MtnMomo;
4
  
5
use GuzzleHttp\ClientInterface;
6
use PatricPoba\MtnMomo\MtnConfig;
7
use PatricPoba\MtnMomo\Http\GuzzleClient;
8
use PatricPoba\MtnMomo\Utilities\Helpers;
9
use PatricPoba\MtnMomo\Exceptions\MtnMomoException;
10
11
abstract class MtnMomo extends GuzzleClient
12
{
13
    use Helpers;
14
    
15
    /**
16
     * @var string the base url of the API 
17
     */ 
18
    const VERSION = '1.0';
19
 
20
    /**
21
     * Current product, would be overriden by the child classes
22
     * Example: 'collection', 'disbursement', 'remittance'
23
     */
24
    const PRODUCT = null; 
25
 
26
27
    public function __construct(MtnConfig $config, ClientInterface $client = null)
28
    { 
29
        parent::__construct($client);
30
 
31
        $this->setConfig($config);
32
    }
33
    
34
35
    public function setConfig(MtnConfig $config)
36
    {
37
        $this->config = $config; 
38
39
        return $this;
40
    }
41
42
    /**
43
     * Get the auth token
44
     * @return string The OAuth Token.
45
     */
46
    public function getToken() : string
47
    {  
48
        $this->config->validate(static::PRODUCT);
49
        
50
        $encodedString = base64_encode(
51
            // $this->config->collectionUserId . ':' . $this->config->collectionApiSecret
52
            $this->config->getValue(static::PRODUCT, 'userId') . ':' . $this->config->getValue(static::PRODUCT, 'apiSecret')
53
        );
54
        
55
        $headers = [
56
            'Authorization'             => 'Basic ' . $encodedString,
57
            'Content-Type'              => 'application/json', 
58
            'Ocp-Apim-Subscription-Key' => $this->config->getValue(static::PRODUCT, 'primaryKey')
59
        ];
60
          
61
        $response = $this->request('post', $url = $this->requestUrl('token'), $params = [], $headers);
62
        // { access_token: "eyJ0eXAi7MRHUfMHikzQNBPAwZ2dVaIVrUgrbhiUb10A", token_type: "access_token", expires_in: 3600 }
63
64
        if ( ! $response->isSuccess() ) {
65
            throw new MtnMomoException("Error in getting token: {$url}");
66
        }
67
68
        return $response->access_token;
69
    }
70
71
72
    public function getBalance()
73
    {  
74
        $headers = [
75
            'Authorization'             => 'Bearer ' . $this->getToken() ,
76
            'Content-Type'              => 'application/json',
77
            "X-Target-Environment"      => $this->config->targetEnvironment,
78
            'Ocp-Apim-Subscription-Key' => $this->config->getValue(static::PRODUCT, 'primaryKey')
79
        ];
80
  
81
        return $this->request('get', $this->requestUrl('balance'), $params = [], $headers);
82
    }
83
84
85 View Code Duplication
    public function getTransaction(string $transactionId)
86
    {
87
        $headers = [
88
            'Authorization'             => 'Bearer ' . $this->getToken() ,
89
            'Content-Type'              => 'application/json',
90
            "X-Target-Environment"      => $this->config->targetEnvironment,
91
            'Ocp-Apim-Subscription-Key' => $this->config->getValue(static::PRODUCT, 'primaryKey')
92
        ];
93
        
94
        $url = $this->requestUrl('getTransaction', ['referenceId'=> $transactionId]);
95
96
        return $this->request('get', $url, $params = [], $headers);
97
    }
98
 
99
    /**
100
     * Make a requestToPay (collection product) or transfer (disbursement product) or transfer (remittance product)
101
     *
102
     * @param array $params amount, mobileNumber,payeeNote,payerMessage,externalId, callbackUrl*
103
     * @param string $transactionUuid
104
     * @throws \Exception
105
     * @return mixed string | PatricPoba\MtnMomo\Http\ApiReponse
106
     */
107
    public function createTransaction(array $data, string $transactionUuid = null)
108
    {
109
        $params = [
110
            "amount"            => $data['amount'],
111
            "currency"          => $data['currency'] ?? $this->config->currency,
112
            "externalId"        => $data['externalId'], 
113
            /** key can be either "payee" or payer depending on the product */
114
            (static::PRODUCT === 'collection' ? 'payer' : 'payee') => [
115
                "partyIdType"   => $data['partyIdType'] ?? 'MSISDN',
116
                "partyId"       => $data['mobileNumber']
117
            ], 
118
            "payerMessage"      => $data['payerMessage'],
119
            "payeeNote"         => $data['payeeNote']
120
        ];
121
122
        $transactionUuid = $transactionUuid ?? static::uuid();
123
124
        $headers = [
125
            'Authorization'             => 'Bearer ' . $this->getToken() ,
126
            'Content-Type'              => 'application/json',
127
            "X-Target-Environment"      => $this->config->targetEnvironment,
128
            'Ocp-Apim-Subscription-Key' => $this->config->getValue(static::PRODUCT, 'primaryKey'), 
129
            "X-Reference-Id"            => $transactionUuid
130
        ];
131
        
132
        $defaultCallbackUrlInEnv = $this->config->getValue(static::PRODUCT, 'callbackUrl');
133
134
        if ( isset($data['callbackUrl']) || is_string($defaultCallbackUrlInEnv) ) {
135
            $headers['X-Callback-Url'] = $params['callbackUrl'] ?? $defaultCallbackUrlInEnv; 
136
        }
137
138
        $response = $this->request('post', $this->requestUrl('createTransaction'), $params, $headers);
139
 
140
        return $response->isSuccess() ? $transactionUuid : $response;
141
    }
142
 
143
    /**
144
     * Undocumented function
145
     *
146
     * @param [type] $mobileNumber
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
147
     * @return void
148
     */
149 View Code Duplication
    public function accountHolderActive($mobileNumber)
150
    {
151
        $headers = [
152
            'Authorization'             => 'Bearer ' . $this->getToken() ,
153
            'Content-Type'              => 'application/json',
154
            "X-Target-Environment"      => $this->config->targetEnvironment,
155
            'Ocp-Apim-Subscription-Key' => $this->config->getValue(static::PRODUCT, 'primaryKey')
156
        ];
157
158
        $url = $this->requestUrl('accountholderActive', ['accountHolderId'=> $mobileNumber]) ;
159
  
160
        return $this->request('get', $url, $params = [], $headers);
161
    }
162
    
163
    
164
    abstract protected function requestUrl(string $endpointName, array $params = []) : string;
165
166
    
167
}
168