|
1
|
|
|
<?php |
|
2
|
|
|
namespace Goodoneuz\PayUz\Http\Classes\Stripe; |
|
3
|
|
|
|
|
4
|
|
|
use Session; |
|
5
|
|
|
use Stripe as StripeGateway; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Goodoneuz\PayUz\Models\Transaction; |
|
8
|
|
|
use Goodoneuz\PayUz\Models\PaymentSystem; |
|
9
|
|
|
use Goodoneuz\PayUz\Http\Classes\DataFormat; |
|
10
|
|
|
use Goodoneuz\PayUz\Services\PaymentService; |
|
11
|
|
|
use Goodoneuz\PayUz\Http\Classes\BaseGateway; |
|
12
|
|
|
use Goodoneuz\PayUz\Models\PaymentSystemParam; |
|
13
|
|
|
use Goodoneuz\PayUz\Services\PaymentSystemService; |
|
14
|
|
|
use Goodoneuz\PayUz\Http\Classes\PaymentException; |
|
15
|
|
|
|
|
16
|
|
|
class Stripe extends BaseGateway |
|
17
|
|
|
{ |
|
18
|
|
|
public $config; |
|
19
|
|
|
public $request; |
|
20
|
|
|
public $response; |
|
21
|
|
|
public $merchant; |
|
22
|
|
|
public $payment_system; |
|
23
|
|
|
const CUSTOM_FORM = 'pay-uz::merchant.stripe'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Payme constructor. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->config = PaymentSystemService::getPaymentSystemParamsCollect(PaymentSystem::STRIPE); |
|
31
|
|
|
$this->request = request(); |
|
32
|
|
|
} |
|
33
|
|
|
/** |
|
34
|
|
|
* success response method. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Illuminate\Http\Response |
|
37
|
|
|
*/ |
|
38
|
|
|
public function run(){ |
|
39
|
|
|
StripeGateway\Stripe::setApiKey($this->config['secret_key']); |
|
40
|
|
|
if (!empty($this->config['proxy'])){ |
|
41
|
|
|
$curl = new StripeGateway\HttpClient\CurlClient([CURLOPT_PROXY => $this->config['proxy']]); |
|
42
|
|
|
// tell Stripe to use the tweaked client |
|
43
|
|
|
StripeGateway\ApiRequestor::setHttpClient($curl); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$charge = StripeGateway\Charge::create ([ |
|
|
|
|
|
|
47
|
|
|
"amount" => (int)$this->request->amount, |
|
48
|
|
|
"currency" => "USD", |
|
49
|
|
|
"source" => $this->request->stripeToken, |
|
50
|
|
|
"description" => "Pay for service" |
|
51
|
|
|
]); |
|
52
|
|
|
$model = PaymentService::convertKeyToModel($this->request->key); |
|
53
|
|
|
$create_time = DataFormat::timestamp(true); |
|
54
|
|
|
$transaction = Transaction::create([ |
|
55
|
|
|
'payment_system' => PaymentSystem::STRIPE, |
|
56
|
|
|
'system_transaction_id' => (int)rand()*1000, |
|
57
|
|
|
'amount' =>(int)$model->total, |
|
58
|
|
|
'currency_code' => Transaction::CURRENCY_CODE_UZS, |
|
59
|
|
|
'state' => Transaction::STATE_COMPLETED, |
|
60
|
|
|
'updated_time' => 1*$create_time, |
|
61
|
|
|
'comment' => '', |
|
62
|
|
|
'detail' => '', |
|
63
|
|
|
'transactionable_type' => get_class($model), |
|
64
|
|
|
'transactionable_id' => $model->id |
|
65
|
|
|
]); |
|
66
|
|
|
Session::flash('success', 'Payment successful!'); |
|
67
|
|
|
//todo: create transaction for stripe |
|
68
|
|
|
PaymentService::payListener(null,$transaction,'after-pay'); |
|
69
|
|
|
header("Location: ". $this->request->url); |
|
70
|
|
|
echo "<script>window.location.href='".$this->request->url."';</script>"; |
|
71
|
|
|
} |
|
72
|
|
|
public function getRedirectParams($model, $amount, $currency, $url){ |
|
73
|
|
|
return [ |
|
74
|
|
|
'config' => $this->config, |
|
75
|
|
|
'url' => $url, |
|
76
|
|
|
'amount' => $amount, |
|
77
|
|
|
'currency' => $currency, |
|
78
|
|
|
'key' => PaymentService::convertModelToKey($model), |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.