Viewing file: PayPalPayment.php (5.07 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Modules\PaymentGateway\PaymentGatewayProvider;
use App\Models\BillingRequest; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use PayPal\Api\Payment; use Omnipay\Omnipay;
class PayPalPayment implements PaymentInterface { public $paymentId; public $request; public $redirect_url; public $error_message; public $return_view; public $will_redirect= false;
public function __construct() { $credentials = json_decode(get_settings('payment_gateway'));
if (!isset($credentials) || !isset($credentials->paypal_payment_mode) || !$credentials->paypal_payment_mode || (!$credentials->paypal_client_id || !$credentials->paypal_client_secret)) { throw new \Exception('Credentials not found. Please contact with the administrator'); } $mode=isset($credentials->paypal_payment_mode) && $credentials->paypal_payment_mode && $credentials->paypal_payment_mode=='live'?'false':'true'; $this->gateway = Omnipay::create('PayPal_Rest'); $this->gateway->setClientId($credentials->paypal_client_id); $this->gateway->setSecret($credentials->paypal_client_secret); $this->gateway->setTestMode($mode); }
public function pay() { // TODO: Implement pay() method. }
public function deposit($deposit){ $this->deposit = $deposit; return $this; }
public function request($request) { $this->paymentId = $request->paymentId; $this->request = $request; 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 { $local_settings = json_decode(get_settings('local_setting'));
$response = $this->gateway->purchase(array( 'amount' => $this->request->amount, 'currency' => isset($local_settings->currency_code)?$local_settings->currency_code:'USD', 'returnUrl' => route('paymentgateway::payment.process.success', ['plan' => $this->deposit->id, 'user' => $this->deposit->customer_id]), 'cancelUrl' => route('paymentgateway::payment.process.cancel'), ))->send();
if ($response->isRedirect()) { $this->redirect_url = $response->redirect(); $this->will_redirect = true; $this->return_view = null;
// this will automatically forward the customer } else { Log::error($response->getMessage()); $this->error_message = $response->getMessage(); } } catch (\Exception $e) { Log::error($e->getMessage()); $this->error_message = $e->getMessage();
}
}
//custom functions
// public function paymentSuccess(Request $request) // { // $request = $this->request; // $deposit = $this->deposit; // $credentials = $this->getCredentials(); // $apiContext = $this->getPaypalApiContext($credentials->paypal_client_id, $credentials->paypal_client_secret); // $paymentId = $this->paymentId; // $user = $request->user; // if (!$paymentId) { // return redirect()->route('customer.deposit.index')->withErrors(['msg' => trans('Invalid payment')]); // } // // try { // $payment = Payment::get($paymentId, $apiContext); // } catch (\Exception $ex) { // return redirect()->route('customer.billing.index')->withErrors(['msg' => trans('Invalid payment')]); // } // // if (!$payment) return redirect()->route('customer.deposit.index')->withErrors(['msg' => trans('Invalid payment')]); // // $url = $payment->getRedirectUrls(); // $parsed_url = parse_url($url->getReturnUrl()); // $query_string = $parsed_url["query"]; // parse_str($query_string, $array_of_query_string); // // if ($array_of_query_string['paymentId'] != $paymentId) { // return redirect()->route('customer.deposit.index')->withErrors(['msg' => trans('Invalid payment')]); // } // // $deposit->update(['payment_status' => 'paid']); // return redirect()->route('customer.deposit.index')->with('success', trans('Congratulations! Your requested amount successfully deposit')); // }
}
|