Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Mujhtech committed Aug 4, 2021
0 parents commit 1167e67
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
composer.lock
.idea
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Muhideen Mujeeb Adeoye

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "laravel/sendchamp",
"description": "Laravel package for sendchamp api",
"require": {
"guzzlehttp/guzzle": "^7.3",
"php": "^7.2|^8.0",
"illuminate/support": "~6|~7|~8"
},
"authors": [
{
"name": "Mujhtech",
"email": "mujeeb.muhideen@gmail.com"
}
],
"autoload": {
"files": [
"src/Helpers.php"
],
"psr-4": {
"Mujhtech\\SendChamp\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Mujhtech\\SendChamp\\SendChampServiceProvider"
],
"aliases": {
"SendChamp": "Mujhtech\\SendChamp\\Facades\\SendChamp"
}
}
}
}
50 changes: 50 additions & 0 deletions config/sendchamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
*
* (c) Muhideen Mujeeb Adeoye <mujeeb.muhideen@gmail.com>
*
*/

return [

/**
* Mode
*
*/
'mode' => 'test',


/**
* Live API url
*
*/
'baseUrl' => 'https://api.sendchamp.com/api/v1',

/**
* Test Api Url
*
*/
'sandboxUrl' => 'https://sandbox-api.sendchamp.com/api/v1',

/**
* Public Key
*
*/
'publicKey' => getenv('SENDCHAMP_PUBLIC_KEY'),

/**
* Secret Key
*
*/
'secretKey' => getenv('SENDCHAMP_SECRET_KEY'),


/**
* Webhook
*
*/
'webhook' => getenv('SENDCHAMP_WEBHOOK'),


];

24 changes: 24 additions & 0 deletions src/Facades/SendChamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
*
* (c) Muhideen Mujeeb Adeoye <mujeeb.muhideen@gmail.com>
*
*/


namespace Mujhtech\SendChamp\Facades;

use Illuminate\Support\Facades\Facade;

class SendChamp extends Facade
{
/**
* Get the registered name of the component
* @return string
*/
protected static function getFacadeAccessor()
{
return 'laravel-sendchamp';
}
}
15 changes: 15 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/*
*
* (c) Muhideen Mujeeb Adeoye <mujeeb.muhideen@gmail.com>
*
*/

if (! function_exists("sendchamp"))
{
function sendchamp() {

return app()->make('laravel-sendchamp');
}
}
223 changes: 223 additions & 0 deletions src/SendChamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?php

/*
*
* (c) Muhideen Mujeeb Adeoye <mujeeb.muhideen@gmail.com>
*
*/

namespace Mujhtech\SendChamp;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Config;

class SendChamp {

protected $pubicKey;


protected $client;


protected $response;


protected $baseUrl;


public function __construct()
{
$this->getKey();
$this->getBaseUrl();
$this->setRequestOptions();
}

public function getBaseUrl()
{
$this->baseUrl = Config::get('sendchamp.mode') == "live" ? Config::get('sendchamp.baseUrl') : Config::get('sendchamp.sandboxUrl');
}


public function getKey()
{
$this->publicKey = Config::get('sendchamp.mode') == "live" ? Config::get('sendchamp.publicKey') : null;
}

private function setRequestOptions()
{
$authBearer = 'Bearer '. $this->publicKey;

$this->client = new Client(
[
'base_uri' => $this->baseUrl,
'headers' => [
'Authorization' => $authBearer,
'Content-Type' => 'application/json',
'Accept' => 'application/json'
]
]
);

return $this;
}


private function setHttpResponse($url, $method, $body = [])
{
if (is_null($method)) {
throw new IsNullException("Empty method not allowed");
}

$this->response = $this->client->{strtolower($method)}(
$this->baseUrl . $url,
["body" => json_encode($body)]
);

return $this;
}


private function getResponse()
{
return json_decode($this->response->getBody(), true);
}

public function createSmsSender(string $sender_name, string $use_case, string $sample_message){

$data = [
'sample' => $sample_message,
'use_case' => $use_case,
'sender_name' => $sender_name
];


return $this->setRequestOptions()->setHttpResponse('/sms/send', 'POST', $data)->getResponse();

}

public function sendSms(string $message, string $sender_name, array $numbers){

$data = [
'to' => $numbers,
'message' => $message,
'sender_name' => $sender_name
];


return $this->setRequestOptions()->setHttpResponse('/sms/send', 'POST', $data)->getResponse();

}

public function fetchSmsStatus(string $sms_id){

return $this->setRequestOptions()->setHttpResponse('/sms/'.$sms_id.'/report', 'GET', [])->getResponse();

}


public function sendVoice(string $message, string $sender_name, string $numbers){

$data = [
'customer_mobile_number' => $numbers,
'message' => $message,
'sender_name' => $sender_name
];


return $this->setRequestOptions()->setHttpResponse('/voice/send', 'POST', $data)->getResponse();

}


public function sendWhatsappOtp(string $template_code, string $message, string $sender_number, string $recipient){

$data = [
'recipient' => $recipient,
'template_code' => $template_code,
'message' => $message,
'sender' => $sender_number
];


return $this->setRequestOptions()->setHttpResponse('/whatsapp/template/send', 'POST', $data)->getResponse();

}

public function sendOtp(string $channel, string $token_type, int $token_length,
int $expiry_day, string $customer_email, string $customer_mobile_number, array $meta_data, string $sender){

$data = [
'channel' => $channel,
'token_type' => $token_type,
'token_length' => $token_length,
'expiration_time' => $expiry_day,
'customer_email' => $customer_email,
'customer_mobile_number' => $customer_mobile_number,
'meta_data' => $meta_data,
'sender' => $sender
];


return $this->setRequestOptions()->setHttpResponse('/verification/create', 'POST', $data)->getResponse();

}


public function confirmOtp(string $reference, string $otp){

$data = [
'verification_reference' => $reference,
'verification_otp' => $otp
];


return $this->setRequestOptions()->setHttpResponse('/verification/confirm', 'POST', $data)->getResponse();

}


public function getContactList(){

return $this->setRequestOptions()->setHttpResponse('/contacts', 'GET', [])->getResponse();

}


public function createOrUpdateContact(string $lastname, string $firstname, string $phone, string $email, string $reference){

$data = [

'last_name' => $lastname,
'first_name' => $firstname,
'phone_number' => $phone,
'email' => $email,
'external_user_id' => $reference

];

return $this->setRequestOptions()->setHttpResponse('/contacts', 'POST', $data)->getResponse();

}


public function deleteContact(string $id){


return $this->setRequestOptions()->setHttpResponse('/contact/'.$id.'/delete', 'POST', [])->getResponse();

}



/**
* Get wallet report
*
* @return array
*/

public function getWalletReport(){

return $this->setRequestOptions()->setHttpResponse('/report/wallet/list', 'GET', [])->getResponse();

}

}
Loading

0 comments on commit 1167e67

Please sign in to comment.