Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
mwamodo authored and github-actions[bot] committed Oct 10, 2022
1 parent 933e86d commit f256919
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/Models/MpesaB2CTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class MpesaB2CTransaction extends Model
{
protected $primaryKey = 'originator_conversation_id';

protected $keyType = 'string';

public $incrementing = false;
}
24 changes: 12 additions & 12 deletions src/MpesaB2C.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MpesaB2C extends Service
public static function send($phone_number, int $amount, string $command, string $remarks, $occasion = '', $callback = null)
{
$env = parent::$config->env;
$phone_number = ($env == "live") ? parent::formatPhoneNumber($phone_number) : "254708374149";
$phone_number = ($env == 'live') ? parent::formatPhoneNumber($phone_number) : '254708374149';
$amount = ($amount / 100);

$endpoint = ($env == 'live')
Expand All @@ -18,19 +18,19 @@ public static function send($phone_number, int $amount, string $command, string
$publicKey = file_get_contents(__DIR__."/certs/{$env}/cert.cer");

openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_PKCS1_PADDING);
$password = ($env == "live") ? base64_encode($encrypted) : config('mpesa-b2c.generated_password');
$password = ($env == 'live') ? base64_encode($encrypted) : config('mpesa-b2c.generated_password');

$curl_post_data = [
"InitiatorName" => parent::$config->username,
"SecurityCredential" => $password,
"CommandID" => $command,
"Amount" => $amount,
"PartyA" => parent::$config->shortcode,
"PartyB" => $phone_number,
"Remarks" => $remarks,
"QueueTimeOutURL" => parent::$config->timeout_url,
"ResultURL" => parent::$config->results_url,
"Occasion" => $occasion,
'InitiatorName' => parent::$config->username,
'SecurityCredential' => $password,
'CommandID' => $command,
'Amount' => $amount,
'PartyA' => parent::$config->shortcode,
'PartyB' => $phone_number,
'Remarks' => $remarks,
'QueueTimeOutURL' => parent::$config->timeout_url,
'ResultURL' => parent::$config->results_url,
'Occasion' => $occasion,
];

$response = parent::post($endpoint, $curl_post_data);
Expand Down
18 changes: 9 additions & 9 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public static function init($configs): void
$base = (isset($_SERVER['HTTPS']) ? 'https' : 'http').'://'.($_SERVER['SERVER_NAME'] ?? '');

$defaults = [
"env" => config('mpesa-b2c.env'),
"type" => 4,
"shortcode" => config('mpesa-b2c.shortcode'),
"key" => config('mpesa-b2c.key'),
"secret" => config('mpesa-b2c.secret'),
"username" => config('mpesa-b2c.username'),
"password" => config('mpesa-b2c.password'),
"results_url" => config('mpesa-b2c.results_url'),
"timeout_url" => config('mpesa-b2c.timeout_url'),
'env' => config('mpesa-b2c.env'),
'type' => 4,
'shortcode' => config('mpesa-b2c.shortcode'),
'key' => config('mpesa-b2c.key'),
'secret' => config('mpesa-b2c.secret'),
'username' => config('mpesa-b2c.username'),
'password' => config('mpesa-b2c.password'),
'results_url' => config('mpesa-b2c.results_url'),
'timeout_url' => config('mpesa-b2c.timeout_url'),
];

foreach ($defaults as $key => $value) {
Expand Down

0 comments on commit f256919

Please sign in to comment.