Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/plugins/datatables-select/././../ion-rangeslider/less/.././../icheck-bootstrap/../../../Modules/PaymentGateway/Tests/../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
مشاهدة ملف: PayPalPayment.php
<?php
namespace Modules\PaymentGateway\PaymentGatewayProvider;
use App\Models\BillingRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use PayPal\Api\Payment;
class PayPalPayment implements PaymentInterface
{
public $paymentId;
public $request;
public $plan;
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 request($request)
{
$this->paymentId = $request->paymentId;
$this->request = $request;
return $this;
}
public function plan($plan)
{
$this->plan = $plan;
return $this;
}
public function getCredentials()
{
$credentials = json_decode(get_settings('payment_gateway'));
if (!isset($credentials) || (!$credentials->paypal_client_id || !$credentials->paypal_client_secret)) {
throw new \Exception('Credentials not found. Please contact with the administrator');
}
return $credentials;
}
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 {
$payment = $this->PayPalPayment($this->plan, $this->planReq);
if ($payment) {
$this->redirect_url = $payment->getApprovalLink();
$this->will_redirect = true;
$this->return_view = null;
} else{
$this->error_message= trans('Invalid payment');
}
} catch (\Exception $ex) {
Log::error($ex);
$this->error_message= $ex->getMessage();
}
}
//custom functions
function PayPalPayment($plan, $planReq)
{
$credentials = $this->getCredentials();
if(!isset($credentials->paypal_client_id) || !isset($credentials->paypal_client_secret)){
throw new \Exception('Invalid Payment');
}
$apiContext = $this->getPayPalApiContext($credentials->paypal_client_id, $credentials->paypal_client_secret);
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal($this->total);
$currency=get_currency();
$amount->setCurrency($currency); //TODO:: get the currency
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl(route('paymentgateway::payment.process.success', ['plan' => $planReq->id, 'user' => $planReq->customer_id]))
->setCancelUrl(route('paymentgateway::payment.process.cancel'));
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
try {
$payment->create($apiContext);
return $payment;
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
Log::error($ex->getData());
}
return null;
}
function getPayPalApiContext($client_id, $secret_key)
{
return new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$client_id, // ClientID
$secret_key // ClientSecret
)
);
}
}