Attendize/app/Payment/CardPayment.php

71 lines
2.0 KiB
PHP
Raw Normal View History

2019-08-16 13:04:50 +00:00
<?php
/**
* Created by PhpStorm.
* User: merdan
* Date: 8/15/2019
* Time: 17:47
*/
namespace App\Payment;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Support\Facades\Log;
class CardPayment{
protected $client;
public function __construct()
{
$this->client = new Client(config('payment.card.config'));
}
public function registerPayment($transaction_data){
$params['form_params'] = array_merge($transaction_data,config('payment.card.params'));
$response = new PaymentRegistrationResponse();
//dd($params);
try{
$request = $this->client->post('register.do',$params);
2019-08-16 13:04:50 +00:00
$response->setResponseData($request->getBody());
}
catch (\Exception $ex){
Log::error($ex);
$error = 'Sorry, there was an error processing your payment. Please try again.';
$response->setExceptionMessage($error);
}
return $response;
}
2019-12-04 09:05:21 +00:00
public function registerCard($cardDetails){
$response = new CardRegistrationResponce;
try{
$request = $this->client->post('processform.do',['form_params' =>$cardDetails]);
$response->setResponseData($request->getBody());
}catch (\Exception $ex){
Log::error($ex);
$error = 'Sorry, there was an error processing your payment. Please try again.';
$response->setExceptionMessage($error);
}
}
2019-08-16 13:04:50 +00:00
public function getPaymentStatus($orderId){
$params['form_params'] = config('payment.card.params');
$params['form_params']['orderId'] = $orderId;
$response = new PaymentStatusResponse();
try{
$request = $this->client->post('getOrderStatus.do',$params);
2020-01-09 11:19:35 +00:00
2019-08-16 13:04:50 +00:00
$response->setResponseData($request->getBody());
2020-04-09 09:53:35 +00:00
Log::info($request->getBody());
2019-08-16 13:04:50 +00:00
}
catch (\Exception $ex){
Log::error($ex);
$response->setExceptionMessage($ex->getMessage());
}
return $response;
}
2019-12-04 09:05:21 +00:00
}