/home/techb158/ileadtechnology.com/vendor/smodav/mpesa/src/Mpesa/C2B
Edit: /home/techb158/ileadtechnology.com/vendor/smodav/mpesa/src/Mpesa/C2B/Registrar.php (3640B)
shortCode = $shortCode;
return $this;
}
/**
* Submit the callback to be used for validation.
*
* @param $validationURL
*
* @return self
*/
public function onValidation($validationURL)
{
$this->validationURL = $validationURL;
return $this;
}
/**
* Submit the callback to be used for confirmation.
*
* @param $confirmationURL
*
* @return self
*/
public function onConfirmation($confirmationURL)
{
$this->confirmationURL = $confirmationURL;
return $this;
}
/**
* Set the transaction status on timeout.
*
* @param string $onTimeout
*
* @return self
*/
public function onTimeout($onTimeout = 'Completed')
{
if ($onTimeout != 'Completed' && $onTimeout != 'Cancelled') {
throw new InvalidArgumentException('Invalid timeout argument. Use Completed or Cancelled');
}
$this->onTimeout = $onTimeout;
return $this;
}
/**
* Set the account to be used.
*
* @param string $account
*
* @return self
*/
public function usingAccount($account)
{
$this->account = $account;
return $this;
}
/**
* Initiate the registration process.
*
* @param string|null $shortCode
* @param string|null $confirmationURL
* @param string|null $validationURL
* @param string|null $onTimeout
* @param string|null $account
*
* @return mixed
*
* @throws \Exception
*/
public function submit($shortCode = null, $confirmationURL = null, $validationURL = null, $onTimeout = null, $account = null)
{
if ($onTimeout) {
$this->onTimeout($onTimeout);
}
$this->core->useAccount($account ?: $this->account);
$body = [
'ShortCode' => $shortCode ?: $this->shortCode,
'ResponseType' => $this->onTimeout,
'ConfirmationURL' => $confirmationURL ?: $this->confirmationURL,
'ValidationURL' => $validationURL ?: $this->validationURL
];
try {
$response = $this->clientRequest(
$body,
$this->core->configRepository()->url(Endpoint::MPESA_REGISTER)
);
return json_decode($response->getBody());
} catch (RequestException $exception) {
$message = $exception->getResponse() ?
$exception->getResponse()->getReasonPhrase() :
$exception->getMessage();
throw new Exception($message);
}
}
}