Skip to content

Commit 797dba7

Browse files
committed
Initialize first version.
1 parent 168cd91 commit 797dba7

27 files changed

+1238
-0
lines changed

composer.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "codexshaper/laravel-paytabs",
3+
"description": "Paytabs API for Laravel.",
4+
"keywords": [
5+
"paytabs",
6+
"creditcard",
7+
"laravel-paytabs",
8+
"paytabs-gateway",
9+
"amex",
10+
"appleypay",
11+
"atfawry",
12+
"knpay",
13+
"mada",
14+
"omannet",
15+
"sadad",
16+
"stcpay",
17+
"stcpayqr",
18+
"valu"
19+
],
20+
"type": "library",
21+
"require": {
22+
"php": "^7.0"
23+
},
24+
"license": "MIT",
25+
"authors": [
26+
{
27+
"name": "Md Abu Ahsan Basir",
28+
"email": "[email protected]"
29+
}
30+
],
31+
"minimum-stability": "dev",
32+
"autoload": {
33+
"psr-4": {
34+
"Paytabs\\": "src/"
35+
}
36+
},
37+
"extra": {
38+
"laravel": {
39+
"providers": [
40+
"Paytabs\\PaytabsServiceProvider"
41+
],
42+
"aliases": {}
43+
}
44+
}
45+
}

config/paytabs.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
return [
4+
5+
/**
6+
*================================================================================
7+
* Profile ID
8+
*================================================================================.
9+
*/
10+
'profile_id' => env('PAYTABS_PROFILE_ID', '77461'),
11+
12+
/**
13+
* Server Key.
14+
*/
15+
'server_key' => env('PAYTABS_SERVER_KEY', 'SRJNWNG2MB-J2G2WMR2WT-BGJZZBWM9W'),
16+
17+
/**
18+
*================================================================================
19+
* Region
20+
*================================================================================.
21+
*/
22+
'region' => env('PAYTABS_REGION', 'GLOBAL'),
23+
24+
/**
25+
*================================================================================
26+
* Paytabs API Version
27+
*================================================================================.
28+
*/
29+
'api_version' => env('PAYTABS_API_VERSION', '2.0'),
30+
];

src/Client.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Paytabs;
4+
5+
/**
6+
* API class which contacts PayTabs server's API
7+
*/
8+
class Client
9+
{
10+
private $baseUrl = 'https://secure-global.paytabs.com/';
11+
private $profileId = null;
12+
private $serverKey = null;
13+
private static $instance = null;
14+
15+
public static function getInstance($profileId, $serverKey, $baseUrl = null)
16+
{
17+
if (self::$instance == null) {
18+
self::$instance = new self($profileId, $serverKey, $region);
19+
}
20+
21+
return self::$instance;
22+
}
23+
24+
public function __construct($profileId = null, $serverKey = null, $baseUrl = null)
25+
{
26+
if ($baseUrl !== null) {
27+
$this->baseUrl = $baseUrl;
28+
}
29+
if ($profileId !== null) {
30+
$this->profileId = $profileId;
31+
}
32+
if ($serverKey !== null) {
33+
$this->serverKey = $serverKey;
34+
}
35+
36+
}
37+
38+
public function sendRequest($requestUrl, $data) {
39+
if (!is_array($data)) {
40+
$data = (array) $data;
41+
}
42+
return json_decode(
43+
$this->execute($requestUrl, $data)
44+
);
45+
}
46+
47+
private function execute($endpoint, $data)
48+
{
49+
try {
50+
$headers = [
51+
'Content-Type: application/json',
52+
"Authorization: {$this->serverKey}"
53+
];
54+
55+
$data['profile_id'] = (int) $this->profileId;
56+
$fields = json_encode($data);
57+
58+
$url = $this->baseUrl . $endpoint;
59+
$ch = curl_init();
60+
curl_setopt($ch, CURLOPT_URL, $url);
61+
curl_setopt($ch, CURLOPT_POST, true);
62+
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
63+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
64+
curl_setopt($ch, CURLOPT_HEADER, false);
65+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
66+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
67+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
68+
curl_setopt($ch, CURLOPT_VERBOSE, true);
69+
// @curl_setopt($ch, CURLOPT_TIMEOUT, 30);
70+
71+
$result = curl_exec($ch);
72+
73+
$error_num = curl_errno($ch);
74+
75+
if ($error_num) {
76+
$error_msg = curl_error($ch);
77+
PaytabsHelper::log("Paytabs Admin: Response [($error_num) $error_msg], [$result]", 3);
78+
79+
$result = json_encode([
80+
'message' => 'Sorry, unable to process your transaction, Contact the site Administrator'
81+
]);
82+
}
83+
84+
curl_close($ch);
85+
86+
87+
} catch (\Exception $ex) {
88+
$result = json_encode([
89+
'message' => $ex->getMessage()
90+
]);
91+
}
92+
93+
return $result;
94+
95+
}
96+
}

src/Contracts/Paytabs.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Paytabs\Contracts;
4+
5+
interface Paytabs
6+
{
7+
public function createPayPage();
8+
9+
public function verifyPayment($tran_id);
10+
11+
public function requestFollowup($data);
12+
13+
public function tokenQuery($token);
14+
15+
public function tokenDelete($token);
16+
}

src/Gateways/All.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Paytab\Gateways;
4+
5+
class All extends BaseGateway
6+
{
7+
protected $code = 'all';
8+
protected $title = 'Online payments powered by PayTabs';
9+
protected $description = 'PayTabs - All supported payment methods';
10+
protected $icon = "paytabs.png";
11+
}

src/Gateways/Amex.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Paytabs\Gateways;
4+
5+
class Amex extends BaseGateway
6+
{
7+
protected $code = 'amex';
8+
protected $title = 'PayTabs - Amex';
9+
protected $description = 'PayTabs - Amex payment method';
10+
}

src/Gateways/Applepay.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Paytabs\Gateways;
4+
5+
class Applepay extends BaseGateway
6+
{
7+
protected $code = 'applepay';
8+
protected $title = 'PayTabs - ApplePay';
9+
protected $description = 'PayTabs - ApplePay payment method';
10+
}

src/Gateways/Atfawry.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Paytabs\Gateways;
4+
5+
class Atfawry extends BaseGateway
6+
{
7+
protected $code = 'atfawry';
8+
protected $title = 'PayTabs - @Fawry';
9+
protected $description = 'PayTabs - @Fawry payment method';
10+
}

src/Gateways/BaseGateway.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Paytabs\Gateways;
4+
5+
use Paytabs\Contracts\Paytabs;
6+
7+
class BaseGateway
8+
{
9+
protected $code = '';
10+
protected $title = '';
11+
protected $description = '';
12+
protected $icon = null;
13+
//
14+
protected $paytabs;
15+
16+
17+
18+
public function __construct(Paytabs $paytabs)
19+
{
20+
$this->paytabs = $paytabs;
21+
}
22+
23+
/**
24+
* We're processing the payments here
25+
**/
26+
public function payment()
27+
{
28+
29+
}
30+
31+
32+
public function scheduled()
33+
{}
34+
35+
public function refund()
36+
{}
37+
}

src/Gateways/Creditcard.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Paytabs\Gateways;
4+
5+
class Creditcard extends BaseGateway
6+
{
7+
protected $code = 'creditcard';
8+
protected $title = 'PayTabs - CreditCard';
9+
protected $description = 'PayTabs - CreditCard payment method';
10+
11+
protected $icon = "creditcard.svg";
12+
}

0 commit comments

Comments
 (0)