Viewing file: UddoktaPay.php (3.92 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Modules\PaymentGateway\TopUpProvider;
use App\Models\BillingRequest; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Modules\PaymentGateway\Services\PaymentCredentials;
class UddoktaPay implements PaymentInterface { public $planReq; public $redirect_url; public $error_message; public $return_view; public $will_redirect= false;
public function __construct() {
}
public function pay() { // TODO: Implement pay() method. }
public function getCredentials() { $credentials= PaymentCredentials::get(); if (!isset($credentials->uddoktapay_url) || !isset($credentials->uddoktapay_apikey) || !isset($credentials->uddoktapay_status) || $credentials->uddoktapay_status =='inactive'){ throw new \Exception('Setup gateway credentials first. Please contact with the administrator'); } return $credentials; }
public function topUpRequest($topup_request){ $this->topup_request=$topup_request; return $this; } public function request($request) { $this->request = $request; return $this; }
public function credit($credit) { $this->credit = $credit; return $this; }
public function amount($amount) { $this->amount = $amount; return $this; }
public function creditType($creditType) { $this->credit_type = $creditType; 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() {
$customer= auth('customer')->user(); try {
$credentials = $this->getCredentials(); if(!$credentials || !isset($credentials->uddoktapay_apikey)){ throw new \Exception('Invalid payment request. Please try again'); } $headers = array( 'Content-Type'=> 'application/json', 'RT-UDDOKTAPAY-API-KEY'=> $credentials->uddoktapay_apikey, ); $client = new \GuzzleHttp\Client(); $postBody=[ 'full_name'=> $customer->fullname, 'email'=> $customer->email, 'amount'=> $this->amount, 'metadata'=>[ 'order_id'=>$this->topup_request->id, 'product_id'=>$this->topup_request->id, ], "redirect_url"=> route('paymentgateway::topup.uddoktapay.success'), "cancel_url"=> route('paymentgateway::payment.process.cancel'), "webhook_url"=> route('paymentgateway::payment.process.cancel') ];
$response = $client->request('POST', "$credentials->uddoktapay_url", array( 'headers' => $headers, 'json' => $postBody, ) );
$code=$response->getStatusCode(); $response=$response->getBody()->getContents(); if(!isset(json_decode($response)->payment_url)){ throw new \Exception('Invalid payment request. Please try again'); }
if(isset($code) && $code=='200') { $this->redirect_url = json_decode($response)->payment_url; $this->will_redirect = true; $this->return_view = null; } }catch(\Exception $ex){ Log::error($ex); $this->error_message= $ex->getMessage(); } }
}
|