-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bank and receipt API is added to this module to pay invoices of a tenant
- Loading branch information
hadi
committed
Nov 29, 2017
1 parent
83aa3b7
commit 35205e0
Showing
11 changed files
with
470 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
class Tenant_BankBackend extends Bank_Backend | ||
{ | ||
|
||
function init() | ||
{ | ||
parent::init(); | ||
$this->_a['multitenant'] = false; | ||
$this->_a['cols'] = array_merge($this->_a['cols'], array( | ||
'tenant' => array( | ||
'type' => 'Pluf_DB_Field_Foreignkey', | ||
'model' => 'Pluf_Tenant', | ||
'blank' => false, | ||
'unique' => true, | ||
'editable' => false | ||
) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pluf Framework, a simple PHP Application Framework. | ||
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* ساختارهای دادهای برای رسید را ایجاد میکند. | ||
* | ||
* رسید عبارت است از یک مجموعه از دادهها که برای پرداخت به بانک ارسال | ||
* میشود. این رسید زمانی که بانک تایید کند به روز شده و اطلاعات دریافتی | ||
* از بانک نیز به آن اضافه می شود. | ||
* | ||
* رسید در اینجا مثل رسید در ماژول بانک است با این تفاوت که این رسید تنها برای پرداختهای مربوط به tenant است. | ||
* | ||
* @author hadi | ||
* | ||
*/ | ||
class Tenant_BankReceipt extends Bank_Receipt | ||
{ | ||
|
||
/** | ||
* @see Bank_Receipt::init() | ||
*/ | ||
function init() | ||
{ | ||
parent::init(); | ||
// Change class type of backend foreingkey from Bank_Backend to Tenant_BankBackend | ||
$this->_a['cols'] = array_merge($this->_a['cols'], array( | ||
'backend' => array( | ||
'type' => 'Pluf_DB_Field_Foreignkey', | ||
'model' => 'Tenant_BankBackend', | ||
'blank' => false, | ||
'relate_name' => 'backend' | ||
) | ||
)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
class Tenant_BankService | ||
{ | ||
|
||
/** | ||
* یک پرداخت جدید ایجاد میکند | ||
* | ||
* روالی که برای ایجاد یک پرداخت دنبال میشه میتونه خیلی متفاوت باشه | ||
* و ساختارهای رو برای خودش ایجاد کنه. برای همین ما پارامترهای ارسالی در | ||
* در خواست رو هم ارسال میکنیم. | ||
* | ||
* پرداخت ایجاد شده بر اساس اطلاعاتی است که با متغیر $reciptParam ارسال | ||
* میشود. این پارامترها | ||
* باید به صورت یک آرایه بوده و شامل موارد زیر باشد: | ||
* | ||
* <pre><code> | ||
* $param = array( | ||
* 'amount' => 1000, // مقدار پرداخت به ریال | ||
* 'title' => 'payment title', | ||
* 'description' => 'description', | ||
* 'email' => '[email protected]', | ||
* 'phone' => '0917222222', | ||
* 'callbackURL' => 'http://.....', | ||
* 'backend' => 2 | ||
* ); | ||
* </code></pre> | ||
* | ||
* <ul> | ||
* <li>*amount: مقدار بر اساس ریال</li> | ||
* <li>*title: عنوان پرداخت</li> | ||
* <li>*description: توضیحات</li> | ||
* <li>email: رایانامه مشتری</li> | ||
* <li>phone: شماره تماس مشتری</li> | ||
* <li>callbackURL: آدرسی که بعد از تکمیل باید فراخوانی شود</li> | ||
* <li>*backend: درگاه پرداخت مورد نظر</li> | ||
* </ul> | ||
* | ||
* در نهایت باید موجودیتی تعیین بشه که این پرداخت رو میخواهیم براش ایجاد | ||
* کنیم. | ||
* | ||
* نکته مهم اینکه در این پیادهسازی backend باید مربوط به ملک اصلی باشه. | ||
* | ||
* @param array $param | ||
* @param Pluf_Model $owner | ||
* @return Bank_Receipt | ||
*/ | ||
public static function create ($param, $owner = null, $ownerId = null) | ||
{ | ||
$form = new Tenant_Form_BankReceiptNew($param); | ||
$receipt = $form->save(false); | ||
// $backend = Pluf::factory('Tenant_BankBackend', $receipt->backend); | ||
$backend = $receipt->get_backend(); | ||
$engine = $backend->get_engine(); | ||
$engine->create($receipt); | ||
if ($owner instanceof Pluf_Model) { // Pluf module | ||
$receipt->owner_class = $owner->getClass(); | ||
$receipt->owner_id = $owner->getId(); | ||
} elseif (! is_null($owner)) { // module | ||
$receipt->owner_class = $owner; | ||
$receipt->owner_id = $ownerId; | ||
} | ||
$receipt->create(); | ||
return $receipt; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pluf Framework, a simple PHP Application Framework. | ||
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* This form is same as Bank_Form_RecieptNew form except that in this form given backend | ||
* sould blong to main tenant | ||
* | ||
* @author hadi <[email protected]> | ||
* | ||
*/ | ||
class Tenant_Form_BankReceiptNew extends Bank_Form_ReceiptNew | ||
{ | ||
|
||
function clean_backend() | ||
{ | ||
$backend = Pluf::factory('Tenant_BankBackend', $this->cleaned_data['backend']); | ||
if ($backend->isAnonymous()) { | ||
throw new Pluf_Exception('backend not found'); | ||
} | ||
// Check if backend blong to main tenant | ||
$mainTenant = Tenant_Shortcuts_GetMainTenant(); | ||
if ($backend->tenant !== $mainTenant->getId()) { | ||
throw new Pluf_Exception('backend is not valid for this payment'); | ||
} | ||
// XXX: maso, 1395: گرفتن پشتوانه | ||
return $backend->id; | ||
} | ||
|
||
/** | ||
* | ||
* @param string $commit | ||
* @throws Pluf_Exception | ||
* @return Tenant_BankBackend | ||
*/ | ||
function save ($commit = true) | ||
{ | ||
if (! $this->isValid()) { | ||
// TODO: maso, 1395: باید از خطای مدل فرم استفاده شود. | ||
throw new Pluf_Exception( | ||
'Cannot save a receipt from an invalid form.'); | ||
} | ||
// Set attributes | ||
$receipt = new Tenant_BankReceipt(); | ||
$receipt->setFromFormData($this->cleaned_data); | ||
$receipt->secure_id = $this->getSecureKey(); | ||
// موجودیت قرار گیرد. | ||
if ($commit) { | ||
if (! $receipt->create()) { | ||
throw new Pluf_Exception('fail to create the recipt.'); | ||
} | ||
} | ||
return $receipt; | ||
} | ||
|
||
/** | ||
* یک کد جدید برای موجودیت ایجاد میکند. | ||
* | ||
* @return Tenant_BankReceipt | ||
*/ | ||
private function getSecureKey () | ||
{ | ||
$recipt = new Tenant_BankReceipt(); | ||
while (1) { | ||
$key = sha1( | ||
microtime() . rand(0, 123456789) . Pluf::f('secret_key')); | ||
$sess = $recipt->getList( | ||
array( | ||
'filter' => 'secure_id=\'' . $key . '\'' | ||
)); | ||
if (count($sess) == 0) { | ||
break; | ||
} | ||
} | ||
return $key; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
function Tenant_Shortcuts_GetMainTenant () | ||
{ | ||
$subdomain = Pluf::f('tenant_default', null); | ||
if($subdomain === null){ | ||
throw new Pluf_Exception_DoesNotExist('tenant_default is not set!'); | ||
} | ||
$tenant = Pluf_Tenant::bySubDomain($subdomain); | ||
if ($tenant == null || $tenant->id <= 0) { | ||
throw new Pluf_Exception_DoesNotExist( | ||
"Tenant not found (subdomain:" . $subdomain . ")"); | ||
} | ||
return $tenant; | ||
} | ||
|
||
function Tenant_Shortcuts_NormalizeItemPerPage ($request) | ||
{ | ||
$count = array_key_exists('_px_c', $request->REQUEST) ? intval($request->REQUEST['_px_c']) : 30; | ||
if($count > 30) | ||
$count = 30; | ||
return $count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Pluf Framework, a simple PHP Application Framework. | ||
* Copyright (C) 2010-2020 Phoinex Scholars Co. (http://dpq.co.ir) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* | ||
* @author hadi <[email protected]> | ||
* | ||
*/ | ||
class Tenant_Views_BankBackend | ||
{ | ||
|
||
/** | ||
* Returns bank-backend determined by given id. | ||
* This method returns backend if and only if backend with given id blongs to main tenant | ||
* else it throws not found exception | ||
* | ||
* @param Pluf_HTTP_Request $request | ||
* @param array $match | ||
* @param array $p | ||
*/ | ||
public function get($request, $match, $p) | ||
{ | ||
$backend = Pluf_Views::getObject($request, $match, $p); | ||
if ($backend->tenant !== Tenant_Shortcuts_GetMainTenant()->id) { | ||
throw new Pluf_HTTP_Error404("Object not found (" . $p['model'] . "," . $backend->id . ")"); | ||
; | ||
} | ||
return $backend; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.