-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
15 changed files
with
656 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ APP_KEY= | |
APP_DEBUG=true | ||
APP_DEPLOYED=false | ||
APP_TIMEZONE=UTC | ||
APP_URL=http://localhost:8000 | ||
APP_URL=http://xshop.test | ||
|
||
APP_LOCALE=en | ||
APP_FALLBACK_LOCALE=en | ||
|
@@ -20,12 +20,7 @@ LOG_STACK=single | |
LOG_DEPRECATIONS_CHANNEL=null | ||
LOG_LEVEL=debug | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=laravel | ||
DB_USERNAME=root | ||
DB_PASSWORD= | ||
DB_CONNECTION=sqlite | ||
|
||
SESSION_DRIVER=database | ||
SESSION_LIFETIME=9999999 | ||
|
@@ -45,7 +40,6 @@ MEMCACHED_HOST=127.0.0.1 | |
PANEL_PREFIX=dashboard | ||
PANEL_PAGE_COUNT=30 | ||
|
||
|
||
REDIS_CLIENT=phpredis | ||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
|
@@ -60,7 +54,6 @@ MAIL_ENCRYPTION=null | |
MAIL_FROM_ADDRESS="[email protected]" | ||
MAIL_FROM_NAME="${APP_NAME}" | ||
|
||
|
||
MEDIA_WATERMARK_SIZE=15 | ||
MEDIA_WATERMARK_OPACITY=50 | ||
|
||
|
@@ -72,7 +65,6 @@ AWS_USE_PATH_STYLE_ENDPOINT=false | |
|
||
VITE_APP_NAME="${APP_NAME}" | ||
|
||
|
||
XLANG_ACTIVE=false | ||
XLANG_MAIN=en | ||
XLANG_API_URL="http://5.255.98.77:3001" | ||
|
@@ -83,3 +75,6 @@ CURRENCY_CODE=USD | |
|
||
SIGN_SMS=true | ||
SIGN_DRIVER=Kavenegar | ||
|
||
ZARINPAL_MERCHANT=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ||
PAY_GATEWAY=zarinpal |
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 | ||
|
||
namespace App\Contracts; | ||
|
||
interface Payment | ||
{ | ||
|
||
/** | ||
* Register Payment Service Provider | ||
* | ||
* @return self | ||
*/ | ||
public static function registerService(); | ||
|
||
/** | ||
* Get Payment name | ||
* | ||
* @return string | ||
*/ | ||
public static function getName(): string; | ||
|
||
/** | ||
* Get payment type must be one of: ONLINE, CHEQUE, CARD, CASH, CASH_ON_DELIVERY | ||
* | ||
* @return string | ||
*/ | ||
public static function getType(): string; | ||
|
||
/** | ||
* Is Active To Show user | ||
* | ||
* @return bool | ||
*/ | ||
public static function isActive(): bool; | ||
|
||
/** | ||
* Gateway Logo | ||
* | ||
* @return string | ||
*/ | ||
public static function getLogo(); | ||
|
||
/** | ||
* Request online payment | ||
* | ||
* @param int $amount transaction amount | ||
* @param string $callbackUrl a url that callback user after transaction | ||
* @param array $additionalData additional data to send back | ||
* | ||
* @return array request data like token and order id | ||
* @throws \Throwable | ||
*/ | ||
public function request(int $amount, string $callbackUrl, array $additionalData = []): array; | ||
|
||
/** | ||
* Redirect customer to bank payment page | ||
*/ | ||
public function goToBank(); | ||
|
||
/** | ||
* Verify payment | ||
* | ||
* @return array successful payment have two keys: reference_id , card_number | ||
* @throws \Throwable if payment fail | ||
*/ | ||
public function verify(): array; | ||
} |
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,40 @@ | ||
<?php | ||
|
||
|
||
namespace App\Contracts; | ||
|
||
|
||
interface PaymentStore | ||
{ | ||
/** | ||
* Store payment request | ||
* | ||
* @param int $orderId Payment unique order id | ||
* @param null $token | ||
* @param string $type One of 'ONLINE', 'CHEQUE', 'CASH', 'CARD', 'CASH_ON_DELIVERY' | ||
* | ||
* @return \App\Models\Payment | ||
*/ | ||
public function storePaymentRequest($orderId,$amount, $token = null, $type = 'ONLINE',$bank=null): \App\Models\Payment; | ||
|
||
/** | ||
* Store success payment and update invoice status | ||
* | ||
* @param int $paymentId Payment unique order id | ||
* @param string|int $referenceId Transaction reference id | ||
* @param null $cardNumber | ||
* | ||
* @return \App\Models\Payment | ||
*/ | ||
public function storeSuccessPayment($paymentId, $referenceId, $cardNumber = null): \App\Models\Payment; | ||
|
||
/** | ||
* Store failed payment and update invoice status | ||
* | ||
* @param int $orderId Payment unique order id | ||
* @param null $message Fail reason text to store | ||
* | ||
* @return \App\Models\Payment | ||
*/ | ||
public function storeFailPayment($orderId, $message = null): \App\Models\Payment; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Invoice; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class InvoiceCompleted | ||
{ | ||
use SerializesModels; | ||
|
||
/** | ||
* @var Invoice | ||
*/ | ||
public $invoice; | ||
|
||
public function __construct(Invoice $invoice) | ||
{ | ||
$this->invoice = $invoice; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Invoice; | ||
use App\Models\Payment; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class InvoiceFailed | ||
{ | ||
use SerializesModels; | ||
|
||
/** | ||
* @var Invoice | ||
*/ | ||
public $invoice; | ||
/** | ||
* @var Payment | ||
*/ | ||
public $payment; | ||
|
||
public function __construct(Invoice $invoice,Payment $payment) | ||
{ | ||
$this->invoice = $invoice; | ||
$this->payment = $payment; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\Invoice; | ||
use App\Models\Payment; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class InvoiceSucceed | ||
{ | ||
use SerializesModels; | ||
|
||
/** | ||
* @var Invoice | ||
*/ | ||
public $invoice; | ||
/** | ||
* @var Payment | ||
*/ | ||
public $payment; | ||
|
||
public function __construct(Invoice $invoice,Payment $payment) | ||
{ | ||
$this->invoice = $invoice; | ||
$this->payment = $payment; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Payment; | ||
|
||
use App\Contracts\Payment; | ||
use App\Models\Invoice; | ||
|
||
class GatewayVerifyController | ||
{ | ||
/** | ||
* @param Invoice $invoice | ||
* @param Payment $gateway | ||
*/ | ||
public function __invoke($invoice_hash, $gateway) | ||
{ | ||
try { | ||
$invoice = Invoice::whereHash($invoice_hash)->firstOrFail(); | ||
$payment = null; | ||
$message = null; | ||
$result = true; | ||
$paymentId = self::getPayment($invoice); | ||
$response = $gateway->verify(); | ||
$payment = $invoice->storeSuccessPayment($paymentId, $response['reference_id'], $response['card_number']); | ||
session(['card'=>serialize([])]); | ||
} catch (\Throwable $exception) { | ||
$result = false; | ||
$invoice->storeFailPayment($paymentId, $exception->getMessage()); | ||
$message = $exception->getMessage(); | ||
\Log::debug("Payment RESPONSE Fail For Gateway {$gateway->getName()} :" . $exception->getMessage() . " On Line {$exception->getLine()} Of File {$exception->getFile()}", ['request' => request()->all(), 'session' => request()->session()->all(), 'user' => request()->user(), 'payment_id' => $paymentId]); | ||
\Log::warning($exception->getTraceAsString()); | ||
return redirect()->route('client.card')->withErrors(__("error in payment.").$message); | ||
} | ||
|
||
return redirect()->route('client.profile')->with('message' , __("payment success")); | ||
|
||
} | ||
|
||
/** | ||
* @param Invoice $invoice | ||
* @return integer | ||
*/ | ||
public static function getPayment($invoice) | ||
{ | ||
$paymentId = session('payment_id'); | ||
if (empty($paymentId)) { | ||
$paymentId = $invoice->payments->last()->id; | ||
} | ||
return $paymentId; | ||
} | ||
} |
Oops, something went wrong.