Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Mujhtech committed Aug 4, 2021
1 parent 761d7b0 commit 63f82ab
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 10 deletions.
266 changes: 266 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
# laravel-sendchamp

> A Laravel Package for sendchamp api
## Installation

[PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required.

To get the latest version of Laravel Paystack, simply require it

```bash
composer require mujhtech/laravel-sendchamp
```

Or add the following line to the require block of your `composer.json` file.

```
"mujhtech/laravel-sendchamp": "1.0.*"
```

Once Laravel Sendchamp is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key.

```php
'providers' => [
...
Mujhtech\SendChamp\SendChampServiceProvider::class,
...
]
```

> If you use **Laravel >= 5.5** you can skip this step and go to [**`configuration`**](https://github.com/mujhtech/laravel-sendchamp#configuration)
- `SendChamp\SendChamp\SendChampServiceProvider::class`

Also, register the Facade like so:

```php
'aliases' => [
...
'SendChamp' => Mujhtech\SendChamp\Facades\SendChamp::class,
...
]
```

## Configuration

You can publish the configuration file using this command:

```bash
php artisan vendor:publish --provider="Mujhtech\SendChamp\SendChampServiceProvider"
```

A configuration-file named `sendchamp.php` with some sensible defaults will be placed in your `config` directory:

```php
<?php

return [

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

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

];
```

## Usage

Open your .env file and add your api key like so:

```php
SENDCHAMP_PUBLIC_KEY=sendchamp_xxxxxxxxxxx
```

_If you are using a hosting service like heroku, ensure to add the above details to your configuration variables._

## Use Case

```php
/**
* Get wallet report
* @return array
*/
SendChamp::getWalletReport()

/**
* Alternatively, use the helper.
*/
sendchamp()->getWalletReport();


/**
* Create or update contact
* @param string $lastname
* @param string $firstname
* @param string $phone
* @param string $email
* @param string $reference
* @return array
*/
SendChamp::createOrUpdateContact($lastname, $firstname, $phone, $email, $reference)

/**
* Alternatively, use the helper.
*/
sendchamp()->createOrUpdateContact($lastname, $firstname, $phone, $email, $reference);


/**
* Delete contact
* @param string $id
* @return array
*/
SendChamp::deleteContact($id)

/**
* Alternatively, use the helper.
*/
sendchamp()->deleteContact($id);


/**
* * Create sms sender
* * @param string $send_name
* * @param string $use_case
* * You should pass either of the following: Transactional, Marketing, or Transactional & Marketing
* * @param string $sample_message
* * @return array
*/
SendChamp::createSmsSender($sender_name, $use_case, $sample_message)

/**
* Alternatively, use the helper.
*/
sendchamp()->createSmsSender($sender_name, $use_case, $sample_message);


/**
* Send sms
* @param string $message
* @param string $sender_name
* Represents the sender of the message.
* This Sender ID must have been requested
* via the dashboard or use "Sendchamp" as default
* @param array $numbers
* This represents the destination phone number.
* The phone number(s) must be in the international format
* (Example: 23490126727). You can also send to multiple numbers.
* To do that put numbers in an array
* (Example: [ '234somenumber', '234anothenumber' ]).
* @return array
*/
SendChamp::sendSms($message, $sender_name, $numbers)


/**
* Get sms status
* @param string $sms_id
* ID of the SMS that was sent
* @return array
*/
SendChamp::fetchSmsStatus($sms_id)

/**
* Alternatively, use the helper.
*/
sendchamp()->fetchSmsStatus($sms_id);



/**
* Send voice
* @param string $message
* @param string $sender_name
* Represents the sender of the message.
* This Sender ID must have been requested via
* the dashboard or use "Sendchamp" as default
* @param string $number
* The number represents the destination phone number.
* The number must be in international format (E.g. 2348012345678)
* @return array
*/
SendChamp::sendVoice($message, $sender_name, $number)

/**
* Alternatively, use the helper.
*/
sendchamp()->sendVoice($message, $sender_name, $number);


/**
* Send whatsapp otp
* @param string $template_code
* You can find this on the template page under Whatsapp Channel of your Sendchamp dashboard
* @param string $sender_number
* Your approved Whatsapp number on Sendchamp.
* You can use our phone number if you have not registered a number 2347067959173
* @param string $recipient
* Whatsapp number of the customer you are sending the message to
* @param string $message
* @return array
*/
SendChamp::sendWhatsappOtp($template_code, $message, $sender_number, $recipient)

/**
* Alternatively, use the helper.
*/
sendchamp()->sendWhatsappOtp($template_code, $message, $sender_number, $recipient);



/**
* Send otp message
* @param string $channel
* @param string $token_type
* @param int $token_length
* The length of the token you want to send to your customer. Minimum is 4
* @param int $expiry_day
* How long you want to the to be active for in minutes. (E.g 10 means 10 minutes )
* @param string $customer_email
* @param string $customer_mobile_number
* @param array $meta_data
* @param string $sender
* Specify the sender you want to use. This is important
* when using SMS OR Whatsapp Channel or we will select a
* default sender from your account. Eg: KUDA OR +234810000000
* @return array
*/
SendChamp::sendOtp($channel, $token_type, $token_length, $expiry_day, $customer_email $customer_mobile_number, $meta_data, $sender)

/**
* Alternatively, use the helper.
*/
sendchamp()->sendOtp($channel, $token_type, $token_length, $expiry_day, $customer_email $customer_mobile_number, $meta_data, $sender);



/**
* Confirm otp
* @param string $reference
* The unique reference that was returned as response when the OTP was created
* @param string $otp
* The OTP that was sent to the customer.
* @return array
*/
SendChamp::confirmOtp($reference, $otp)

/**
* Alternatively, use the helper.
*/
sendchamp()->confirmOtp($reference, $otp);

```

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
8 changes: 1 addition & 7 deletions config/sendchamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Mode
* live or test
*
*/
'mode' => 'test',
Expand All @@ -32,13 +33,6 @@
*/
'publicKey' => getenv('SENDCHAMP_PUBLIC_KEY'),

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


/**
* Webhook
*
Expand Down
21 changes: 18 additions & 3 deletions src/SendChamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function getResponse()
*/

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

if(!in_array( $use_case ,$this->useCase )){

Expand Down Expand Up @@ -262,7 +262,7 @@ public function sendVoice(string $message, string $sender_name, string $number){


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

$data = [
'recipient' => $recipient,
Expand Down Expand Up @@ -296,7 +296,20 @@ public function sendWhatsappOtp(string $template_code, string $message,
*/

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){
int $expiry_day, string $customer_email, string $customer_mobile_number, array $meta_data, string $sender){

if(!in_array($token_type, $this->tokenType)){

throw new SendChampException("Invalid token type");

}

if(!in_array($channel, $this->channel)){

throw new SendChampException("Invalid channel");

}


$data = [
'channel' => $channel,
Expand All @@ -317,7 +330,9 @@ public function sendOtp(string $channel, string $token_type, int $token_length,
/**
* Confirm otp
* @param string $reference
* The unique reference that was returned as response when the OTP was created
* @param string $otp
* The OTP that was sent to the customer.
* @return array
*/

Expand Down

0 comments on commit 63f82ab

Please sign in to comment.