diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d22904f --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "akcybex/jazzcash", + "description": "Jazzcash - Laravel Jazzcash Payment Gateway Integration", + "type": "project", + "license": "MIT", + "autoload": { + "psr-4": { + "App\\": "app/", + "AKCybex\\JazzCash\\": "src/" + }, + "classmap": [ + ] + }, + "authors": [ + { + "name": "Rana Tayyab", + "email": "akcybex@gmail.com" + } + ], + "minimum-stability": "dev", + "require": {}, + "extra": { + "laravel": { + "providers": [ + "AKCybex\\JazzCash\\AKJazzCashServiceProvider" + ], + "aliases": { + "JazzCash": "AKCybex\\JazzCash\\Facades\\JazzCash" + } + } + } +} diff --git a/publishable/config/jazzcash.php b/publishable/config/jazzcash.php new file mode 100644 index 0000000..64c702d --- /dev/null +++ b/publishable/config/jazzcash.php @@ -0,0 +1,19 @@ + env('JAZZCASH_ENVIRONMENT', 'sandbox'), + 'sandbox' => [ + 'merchant_id' => env('SANDBOX_JAZZCASH_MERCHANT_ID'), + 'password' => env('SANDBOX_JAZZCASH_PASSWORD'), + 'integerity_salt' => env('SANDBOX_JAZZCASH_INTEGERITY_SALT'), + 'return_url' => env('SANDBOX_JAZZCASH_RETURN_URL'), + 'endpoint' => env('SANDBOX_JAZZCASH_ENDPOINT'), + ], + 'live' => [ + 'merchant_id' => env('JAZZCASH_MERCHANT_ID'), + 'password' => env('JAZZCASH_PASSWORD'), + 'integerity_salt' => env('JAZZCASH_INTEGERITY_SALT'), + 'return_url' => env('JAZZCASH_RETURN_URL'), + 'endpoint' => env('JAZZCASH_ENDPOINT'), + ], +]; diff --git a/src/AKJazzCashServiceProvider.php b/src/AKJazzCashServiceProvider.php new file mode 100644 index 0000000..7076c09 --- /dev/null +++ b/src/AKJazzCashServiceProvider.php @@ -0,0 +1,75 @@ +loadHelpers(); + + $this->registerConfigs(); + + if ($this->app->runningInConsole()) { + $this->registerPublishableResources(); + } + + $this->app->bind('jazzcash', function($app) { + return new JazzCash(); + }); + } + + /** + * Bootstrap services. + * + * @return void + */ + public function boot() + { + + } + + /** + * Load helpers. + */ + protected function loadHelpers() + { + foreach (glob(__DIR__.'/Helpers/*.php') as $filename) { + require_once $filename; + } + } + + /** + * Register the publishable files. + */ + private function registerPublishableResources() + { + $publishablePath = dirname(__DIR__).'/publishable'; + + $publishable = [ + 'config' => [ + "{$publishablePath}/config/jazzcash.php" => config_path('jazzcash.php'), + ], + + ]; + + foreach ($publishable as $group => $paths) { + $this->publishes($paths, $group); + } + } + + public function registerConfigs() + { + $this->mergeConfigFrom( + dirname(__DIR__).'/publishable/config/jazzcash.php', + 'jazzcash' + ); + } +} diff --git a/src/Facades/JazzCash.php b/src/Facades/JazzCash.php new file mode 100644 index 0000000..00ede4b --- /dev/null +++ b/src/Facades/JazzCash.php @@ -0,0 +1,13 @@ +data = [ + 'pp_MerchantID' => config("jazzcash.$environment.merchant_id"), + 'pp_Password' => config("jazzcash.$environment.password"), + 'pp_ReturnURL' => config("jazzcash.$environment.return_url"), + 'pp_HashKey' => config("jazzcash.$environment.integerity_salt"), + 'pp_Amount' => 0, + 'pp_BillReference' => 'billRef', + 'pp_SubMerchantID' => '', + 'pp_Description' => 'Thank you for using Jazz Cash', + 'pp_Language' => 'EN', + 'pp_TxnCurrency' => 'PKR', + 'pp_TxnDateTime' => date('YmdHis'), + 'pp_TxnExpiryDateTime' => date('YmdHis', strtotime('+8 Days')), + 'pp_TxnRefNo' => "T" . date('YmdHis'), + 'pp_TxnType' => 'MWALLET', + 'pp_Version' => '1.1', + 'pp_DiscountedAmount' => '', + 'pp_DiscountedBank' => '', + 'pp_ProductID' => 'RETL', + 'pp_BankID' => 'TBANK', + 'ppmpf_1' => '1', + 'ppmpf_2' => '2', + 'ppmpf_3' => '3', + 'ppmpf_4' => '4', + 'ppmpf_5' => '5', + ]; + } + + /** + * @param $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->data['pp_Amount'] = $amount * 100; + return $this; + } + + /** + * @param $returnURL + * + * @return $this + */ + public function setReturnURL($returnURL) + { + $this->data['pp_ReturnURL'] = $returnURL; + return $this; + } + + /** + * @param $billReference + * + * @return $this + */ + public function setBillReference($billReference) + { + $this->data['pp_BillReference'] = $billReference; + return $this; + } + + /** + * @param $subMerchantID + * + * @return $this + */ + public function setSubMerchantID($subMerchantID) + { + $this->data['pp_SubMerchantID'] = $subMerchantID; + return $this; + } + + /** + * @param $description + * + * @return $this + */ + public function setDescription($description) + { + $this->data['pp_Description'] = $description; + return $this; + } + + /** + * @param $language + * + * @return $this + */ + public function setLanguage($language) + { + $this->data['pp_Language'] = $language; + return $this; + } + + /** + * @param $txnCurrency + * + * @return $this + */ + public function setTransactionCurrency($txnCurrency) + { + $this->data['pp_TxnCurrency'] = $txnCurrency; + return $this; + } + + /** + * @param $txnDateTime + * + * @return $this + */ + public function setTransactionDateTime($txnDateTime) + { + $this->data['pp_TxnDateTime'] = $txnDateTime; + return $this; + } + + /** + * @param $txnExpiryDateTime + * + * @return $this + */ + public function setTransactionExpiryDateTime($txnExpiryDateTime) + { + $this->data['pp_TxnExpiryDateTime'] = $txnExpiryDateTime; + return $this; + } + + /** + * @param $txnReferenceNo + * + * @return $this + */ + public function setTransactionReferenceNumber($txnReferenceNo) + { + $this->data['pp_TxnRefNo'] = $txnReferenceNo; + return $this; + } + + /** + * @param $txnType + * + * @return $this + */ + public function setTransactionType($txnType) + { + $this->data['pp_TxnType'] = $txnType; + return $this; + } + + /** + * @param $version + * + * @return $this + */ + public function setVersion($version) + { + $this->data['pp_Version'] = $version; + return $this; + } + + /** + * @param $discountedAmount + * + * @return $this + */ + public function setDiscountedAmount($discountedAmount) + { + $this->data['pp_DiscountedAmount'] = $discountedAmount; + return $this; + } + + /** + * @param $discountedBank + * + * @return $this + */ + public function setDiscountedBank($discountedBank) + { + $this->data['pp_DiscountedBank'] = $discountedBank; + return $this; + } + + /** + * @param $productID + * + * @return $this + */ + public function setProductID($productID) + { + $this->data['pp_ProductID'] = $productID; + return $this; + } + + /** + * @param $bankID + * + * @return $this + */ + public function setBankID($bankID) + { + $this->data['pp_BankID'] = $bankID; + return $this; + } + + /** + * @param $mpf1 + * + * @return $this + */ + public function setMPF1($mpf1) + { + $this->data['ppmpf_1'] = $mpf1; + return $this; + } + + /** + * @param $mpf2 + * + * @return $this + */ + public function setMPF2($mpf2) + { + $this->data['ppmpf_2'] = $mpf2; + return $this; + } + + /** + * @param $mpf3 + * + * @return $this + */ + public function setMPF3($mpf3) + { + $this->data['ppmpf_3'] = $mpf3; + return $this; + } + + /** + * @param $mpf4 + * + * @return $this + */ + public function setMPF4($mpf4) + { + $this->data['ppmpf_4'] = $mpf4; + return $this; + } + + /** + * @param $mpf5 + * + * @return $this + */ + public function setMPF5($mpf5) + { + $this->data['ppmpf_5'] = $mpf5; + return $this; + } + + /** + * @return array + */ + public function toArray() + { + $this->generateSecureHash(); + return $this->data; + } + + /** + * + */ + private function generateSecureHash() + { + ksort($this->data); + + $str = ''; + foreach ($this->data as $key => $value) { + if (!empty($value)) { + $str = $str . '&' . $value; + } + } + + $str .= $this->data['pp_HashKey'] . $str; + + $this->data['pp_SecureHash'] = hash_hmac('sha256', $str, $this->data['pp_HashKey']); + } +}