Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
Signed-off-by: Muharrem ERİN <[email protected]>
  • Loading branch information
mewebstudio committed Aug 6, 2018
0 parents commit 42a88e5
Show file tree
Hide file tree
Showing 30 changed files with 2,353 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&copy; 2018 Muharrem ERİN ([email protected])

http://www.opensource.org/licenses/mit-license.php The MIT License
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 MeWebStudio - Muharrem ERİN

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.

182 changes: 182 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Türk bankaları için sanal pos paketi (PHP)

Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal pos sistemlerinin kullanılabilmesidir. Şu an için EST altyapısı kullanan bankalar desteklenmektedir.

> Şu an elimde sadece Akbank test API ve kullanıcı bilgileri olduğu için, diğer EST altyapısı kullanan banklarda test yapamadım.
### Özellikler
- Standart E-Commerce modeliyle ödeme (model => regular)
- 3D modeliyle ödeme (model => 3d)
- 3D Pay modeliyle ödeme (model => 3d_pay)
- Sipariş/Ödeme sorgulama (query)
- Sipariş/Ödeme geçmişi sorgulama (history)
- Sipariş/Para iadesi yapma (refund)
- Sipariş iptal etme (cancel)

### Minimum Gereksinimler
- PHP >= 7.1.3
- ext-dom
- ext-json
- ext-SimpleXML

### Kurulum
Test sunucunuz üzerinde;
```sh
$ mkdir pos-test && cd pos-test
$ composer require mews/pos
```

**config.php (Ayar dosyası)**
```php
<?php

require './vendor/autoload.php';

$host_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . "://$_SERVER[HTTP_HOST]";
$path = '/pos-test/';
$base_url = $host_url . $path;

$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$ip = $request->getClientIp();

// API kullanıcı bilgileri
$account = [
'bank' => 'akbank',
'model' => 'regular',
'client_id' => 'XXXXXXXX',
'username' => 'XXXXXXXX',
'password' => 'XXXXXXXX',
'env' => 'test', // test veya production. test ise; API Test Url, production ise; API Production URL kullanılır.
];

// API kullanıcı hesabı ile paket bir değişkene aktarılıyor
try {
$pos = new \Mews\Pos\Pos($account);
} catch (\Mews\Pos\Exceptions\BankNotFoundException $e) {
var_dump($e->getCode(), $e->getMessage());
exit();
} catch (\Mews\Pos\Exceptions\BankClassNullException $e) {
var_dump($e->getCode(), $e->getMessage());
exit();
}
```

**test.php (Test Dosyası)**
```php
<?php

require 'config.php';

// Sipariş bilgileri
$order = [
'id' => 'BENZERSIZ-SIPERIS-ID',
'name' => 'John Doe', // zorunlu değil
'email' => '[email protected]', // zorunlu değil
'user_id' => '12', // zorunlu değil
'amount' => (double) 20, // Sipariş tutarı
'installment' => '0',
'currency' => 'TRY',
'ip' => $ip,
'transaction' => 'pay', // pay => Auth, pre PreAuth (Direkt satış için pay, ön provizyon için pre)
];

// Kredi kartı bilgieri
$card = [
'number' => 'XXXXXXXXXXXXXXXX', // Kredi kartı numarası
'month' => 'XX', // SKT ay
'year' => 'XX', // SKT yıl, son iki hane
'cvv' => 'XXX', // Güvenlik kodu, son üç hane
];

// API kullanıcısı ile oluşturulan $pos değişkenine prepare metoduyla sipariş bilgileri gönderiliyor
try {
$pos->prepare($order);
} catch (\Mews\Pos\Exceptions\UnsupportedTransactionTypeException $e) {
var_dump($e->getCode(), $e->getMessage());
exit();
}

// Ödeme tamamlanıyor
$payment = $pos->payment($card);

// Sonuç çıktısı
var_dump($payment->response);

````

### Farklı Banka Sanal Poslarını Eklemek
Kendi projenizin dizinindeyken
```sh
$ cp ./vendor/mews/pos/config/pos.php ./pos_ayarlar.php
```
ya da;

Projenizde bir ayar dosyası oluşturup (pos_ayarlar.php gibi), paket içerisinde `./config/pos.php` dosyasının içeriğini buraya kopyalayın.

```php
<?php

return [
// Para birimleri
'currencies' => [
'TRY' => 949,
'USD' => 840,
'EUR' => 978,
'GBP' => 826,
'JPY' => 392,
'RUB' => 643,
],

// Banka sanal pos tanımlamaları
'banks' => [
'akbank' => [
'name' => 'AKBANK T.A.S.',
'class' => \Mews\Pos\EstPos::class,
'urls' => [
'production' => 'https://www.sanalakpos.com/fim/api',
'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api',
'gateway' => [
'production' => 'https://www.sanalakpos.com/fim/est3Dgate',
'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate',
],
]
],

// Yeni eklenen banka
'isbank' => [
'name' => 'İŞ BANKASI .A.S.',
'class' => \Mews\Pos\EstPos::class, // Altyapı sınıfı
'urls' => [
'production' => 'xxxx', // API Url
'test' => 'xxxx', // API Test Url
'gateway' => [
'production' => 'xxxx', // 3d Kapı Url
'test' => 'xxxx', // 3d Test Kapı Url
],
]
],
]
];

```

Bundan sonra nesnemizi, yeni ayarlarımıza göre oluşturup kullanmamız gerekir. Örnek:
```php
$yeni_ayarlar = require './pos_ayarlar.php';
$pos = new \Mews\Pos\Pos($account, $yeni_ayarlar);
```

### Örnek Kodlar
`./pos/examples` dizini içerisinde.

### Yol Haritası
- Dökümantasyon hazırlanacak
- EST harici altyapılar için de geliştirme yapılacak
- UnitTest yazılacak -> Bu hiçbir zaman olmayabilir, birisi el atarsa sevinirim :)

> Değerli yorum, öneri ve katkılarınızı bekliyorum.
License
----

MIT
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "mews/pos",
"description": "Türk bankaları için sanal pos kütüphanesi",
"keywords": ["pos", "sanal pos", "est", "est pos", "akbank"],
"homepage": "https://github.com/mewebstudio/pos",
"license": "MIT",
"authors": [
{
"name": "Muharrem ERİN",
"email": "[email protected]"
}
],
"require": {
"php": "^7.1.3",
"ext-dom": "*",
"ext-json": "*",
"ext-SimpleXML": "*",
"guzzlehttp/guzzle": "^6.3",
"symfony/http-foundation": "^4.1"
},
"autoload": {
"psr-4": {
"Mews\\Pos\\": "src/"
}
}
}
27 changes: 27 additions & 0 deletions config/pos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

return [
'currencies' => [
'TRY' => 949,
'USD' => 840,
'EUR' => 978,
'GBP' => 826,
'JPY' => 392,
'RUB' => 643,
],

'banks' => [
'akbank' => [
'name' => 'AKBANK T.A.S.',
'class' => \Mews\Pos\EstPos::class,
'urls' => [
'production' => 'https://www.sanalakpos.com/fim/api',
'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api',
'gateway' => [
'production' => 'https://www.sanalakpos.com/fim/est3Dgate',
'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate',
],
]
],
]
];
63 changes: 63 additions & 0 deletions examples/akbank/3d-pay/_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

require '../../../vendor/autoload.php';

$host_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . "://$_SERVER[HTTP_HOST]";
$path = '/pos/examples/akbank/3d-pay/';
$base_url = $host_url . $path;

$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$ip = $request->getClientIp();

$account = [
'bank' => 'akbank',
'model' => '3d_pay',
'client_id' => 'xxx',
'store_key' => 'xxx',
'env' => 'test',
];

try {
$pos = new \Mews\Pos\Pos($account);
} catch (\Mews\Pos\Exceptions\BankNotFoundException $e) {
var_dump($e->getCode(), $e->getMessage());
} catch (\Mews\Pos\Exceptions\BankClassNullException $e) {
var_dump($e->getCode(), $e->getMessage());
}

$amount = (double) 100;
$instalment = '0';

$ok_url = $base_url . 'response.php';
$fail_url = $base_url . 'response.php';

$transaction = 'pay'; // pay => Auth, pre PreAuth
$transaction_type = $pos->bank->types[$transaction];

$rand = microtime();

$order = [
'id' => 'unique-order-id-006',
'email' => '[email protected]', // optional
'name' => 'John Doe', // optional
'amount' => $amount,
'installment' => $instalment,
'currency' => 'TRY',
'ip' => $ip,
'ok_url' => $ok_url,
'fail_url' => $fail_url,
'transaction' => $transaction,
'transaction_type' => $transaction_type,
'lang' => 'tr',
'rand' => $rand,
];

$pos->prepare($order);

$hash = $pos->bank->create3DHash();
$order['hash'] = $hash;

$currency = $pos->config['currencies'][$order['currency']];
$gateway = $pos->bank->gateway;

$template_title = '3D Pay Model Payment';
70 changes: 70 additions & 0 deletions examples/akbank/3d-pay/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

require '_config.php';

require '../../template/_header.php';

?>

<form method="post" action="<?php echo $gateway; ?>" role="form">
<div class="row">
<div class="form-group col-sm-3">
<label for="cardType">Card Type</label>
<select name="cardType" id="cardType" class="form-control input-lg">
<option value="">Type</option>
<option value="1">Visa</option>
<option value="2">MasterCard</option>
</select>
</div>
<div class="form-group col-sm-9">
<label for="pan">Card Number</label>
<input type="text" name="pan" id="pan" class="form-control input-lg" placeholder="Credit card number">
</div>
<div class="form-group col-sm-4">
<label for="Ecom_Payment_Card_ExpDate_Month">Expire Month</label>
<select name="Ecom_Payment_Card_ExpDate_Month" id="Ecom_Payment_Card_ExpDate_Month" class="form-control input-lg">
<option value="">Month</option>
<?php for ($i = 1; $i <= 12; $i++): ?>
<option value="<?php echo $i; ?>"><?php echo str_pad($i, 2, 0, STR_PAD_LEFT); ?></option>
<?php endfor; ?>
</select>
</div>
<div class="form-group col-sm-4">
<label for="Ecom_Payment_Card_ExpDate_Year">Expire Year</label>
<select name="Ecom_Payment_Card_ExpDate_Year" id="Ecom_Payment_Card_ExpDate_Year" class="form-control input-lg">
<option value="">Year</option>
<?php for ($i = date('y'); $i <= date('y') + 20; $i++): ?>
<option value="<?php echo $i; ?>"><?php echo 2000 + $i; ?></option>
<?php endfor; ?>
</select>
</div>
<div class="form-group col-sm-4">
<label for="cv2">Cvv</label>
<input type="text" name="cv2" id="cv2" class="form-control input-lg" placeholder="Cvv">
</div>
</div>
<?php if (isset($order['name'])): ?>
<input type="hidden" name="firmaadi" value="<?php echo $order['name']; ?>">
<?php endif; ?>
<?php if (isset($order['email'])): ?>
<input type="hidden" name="Email" value="<?php echo $order['email']; ?>">
<?php endif; ?>
<input type="hidden" name="clientid" value="<?php echo $account['client_id']; ?>" />
<input type="hidden" name="amount" value="<?php echo $order['amount']; ?>" />
<input type="hidden" name="islemtipi" value="<?php echo $order['transaction_type']; ?>" />
<input type="hidden" name="taksit" value="<?php echo $order['installment']; ?>" />
<input type="hidden" name="oid" value="<?php echo $order['id']; ?>" />
<input type="hidden" name="okUrl" value="<?php echo $order['ok_url']; ?>" />
<input type="hidden" name="failUrl" value="<?php echo $order['fail_url']; ?>" />
<input type="hidden" name="rnd" value="<?php echo $rand; ?>" />
<input type="hidden" name="hash" value="<?php echo $hash; ?>" />
<input type="hidden" name="storetype" value="<?php echo $account['model']; ?>" />
<input type="hidden" name="lang" value="<?php echo $order['lang']; ?>" />
<input type="hidden" name="currency" value="<?php echo $currency; ?>" />
<hr>
<div class="form-group text-center">
<button type="submit" class="btn btn-lg btn-block btn-success">Payment</button>
</div>
</form>

<?php require '../../template/_footer.php'; ?>
Loading

0 comments on commit 42a88e5

Please sign in to comment.