Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/../Modules/PaymentGateway/PaymentGatewayProvider
الملفات الموجودة في هذا الـ Path:
.
..
AuthorizeNetPayment.php
CashmallPayment.php
IyzicoPayment.php
MolliePayment.php
PayPalPayment.php
Payment.php
PaymentGateway.php
PaymentInterface.php
PaystackPayment.php
PaytmPayment.php
ProcessPayment.php
StripeCheckoutPayment.php
StripePayment.php
مشاهدة ملف: StripePayment.php
<?php
namespace Modules\PaymentGateway\PaymentGatewayProvider;
use App\Models\BillingRequest;
use Illuminate\Support\Facades\Log;
class StripePayment implements PaymentInterface
{
public $planReq;
public $redirect_url;
public $error_message;
public $return_view;
public $total;
public $will_redirect = false;
public function __construct($total)
{
$this->total=$total;
return $this;
}
public function pay()
{
// TODO: Implement pay() method.
}
public function plan_request($planReq)
{
$this->planReq = $planReq;
return $this;
}
public function getCredentials()
{
$credentials = json_decode(get_settings('payment_gateway'));
if (!$credentials->stripe_pub_key || !$credentials->stripe_secret_key) {
throw new \Exception('Credentials not found. Please contact with the administrator');
}
return $credentials;
}
public function request($request)
{
$this->request = $request;
return $this;
}
public function plan($plan)
{
$this->plan = $plan;
return $this;
}
public function will_redirect()
{
// TODO: Implement will_redirect() method.
return $this->will_redirect;
}
public function redirect_url()
{
// TODO: Implement redirect_url() method.
return $this->redirect_url;
}
public function return_view()
{
// TODO: Implement redirect_url() method.
return $this->return_view;
}
public function error_message()
{
// TODO: Implement error_message() method.
return $this->error_message;
}
public function process()
{
try {
$plan = $this->plan;
$request = $this->request;
$payment = $this->stripePayment($plan, $request);
if (isset($payment->id)) {
$planReq = $this->planReq;
$planReq->status = 'accepted';
$planReq->save();
$user = auth('customer')->user();
$customer = $user;
$pre_plan = $customer->plan;
if ($pre_plan) {
$customer->plan()->delete();
}
$customer->plan()->create(['plan_id' => $planReq->plan_id, 'email_limit' => $plan->email_limit,
'available_emails' => $plan->email_limit, 'price' => $plan->price,'contact_limit'=>$plan->contact_limit]);
BillingRequest::where(['customer_id' => $user->id, 'status' => 'pending'])->update(['status' => 'rejected']);
}
$this->redirect_url = null;
$this->return_view = null;
} catch (\Exception $ex) {
Log::error($ex->getMessage());
$this->error_message= $ex->getMessage();
}
}
/*Custom Function*/
function stripePayment($plan, $req)
{
$credentials = json_decode(get_settings('payment_gateway'));
if (!$credentials->stripe_pub_key || !$credentials->stripe_secret_key) {
throw new \Exception(trans('Invalid payment'));
}
$stripe = new \Stripe\StripeClient($credentials->stripe_secret_key);
$currency=get_currency();
return $stripe->charges->create([
'amount' => $this->total * 100,
'currency' => $currency,
'source' => $req->stripeToken,
'description' => 'User:' . auth('customer')->user()->email . ' changed plan to ' . $plan->title,
]);
}
}