mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Merge pull request #7746 from kishanmnpatel/refund_feature_added_for_forte
Refund feature added for Forte
This commit is contained in:
commit
e0c1d0d29e
@ -11,6 +11,8 @@
|
||||
|
||||
namespace App\PaymentDrivers;
|
||||
|
||||
use App\Models\Payment;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\SystemLog;
|
||||
use App\Models\GatewayType;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -60,31 +62,130 @@ class FortePaymentDriver extends BaseDriver
|
||||
|
||||
public function authorizeView(array $data)
|
||||
{
|
||||
return $this->payment_method->authorizeView($data); //this is your custom implementation from here
|
||||
return $this->payment_method->authorizeView($data);
|
||||
}
|
||||
|
||||
public function authorizeResponse($request)
|
||||
{
|
||||
return $this->payment_method->authorizeResponse($request); //this is your custom implementation from here
|
||||
return $this->payment_method->authorizeResponse($request);
|
||||
}
|
||||
|
||||
public function processPaymentView(array $data)
|
||||
{
|
||||
return $this->payment_method->paymentView($data); //this is your custom implementation from here
|
||||
return $this->payment_method->paymentView($data);
|
||||
}
|
||||
|
||||
public function processPaymentResponse($request)
|
||||
{
|
||||
return $this->payment_method->paymentResponse($request); //this is your custom implementation from here
|
||||
return $this->payment_method->paymentResponse($request);
|
||||
}
|
||||
|
||||
// public function refund(Payment $payment, $amount, $return_client_response = false)
|
||||
// {
|
||||
// return $this->payment_method->yourRefundImplementationHere(); //this is your custom implementation from here
|
||||
// }
|
||||
public function refund(Payment $payment, $amount, $return_client_response = false)
|
||||
{
|
||||
$forte_base_uri = "https://sandbox.forte.net/api/v3/";
|
||||
if($this->company_gateway->getConfigField('testMode') == false){
|
||||
$forte_base_uri = "https://api.forte.net/v3/";
|
||||
}
|
||||
$forte_api_access_id = $this->company_gateway->getConfigField('apiAccessId');
|
||||
$forte_secure_key = $this->company_gateway->getConfigField('secureKey');
|
||||
$forte_auth_organization_id = $this->company_gateway->getConfigField('authOrganizationId');
|
||||
$forte_organization_id = $this->company_gateway->getConfigField('organizationId');
|
||||
$forte_location_id = $this->company_gateway->getConfigField('locationId');
|
||||
|
||||
try {
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $forte_base_uri.'organizations/'.$forte_organization_id.'/locations/'.$forte_location_id.'/transactions',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS =>'{
|
||||
"action":"reverse",
|
||||
"authorization_amount":'.$amount.',
|
||||
"original_transaction_id":"'.$payment->transaction_reference.'",
|
||||
"authorization_code": "9ZQ754"
|
||||
}',
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/json',
|
||||
'X-Forte-Auth-Organization-Id: '.$forte_organization_id,
|
||||
'Authorization: Basic '.base64_encode($forte_api_access_id.':'.$forte_secure_key)
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
$response=json_decode($response);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$message = [
|
||||
'action' => 'error',
|
||||
'data' => $th,
|
||||
];
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$message,
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_FAILURE,
|
||||
SystemLog::TYPE_FORTE,
|
||||
$this->client,
|
||||
$this->client->company,
|
||||
);
|
||||
}
|
||||
|
||||
$message = [
|
||||
'action' => 'refund',
|
||||
'server_message' => $response->response->response_desc,
|
||||
'server_response' => $response,
|
||||
'data' => $payment->paymentables,
|
||||
];
|
||||
|
||||
if ($httpcode>299) {
|
||||
SystemLogger::dispatch(
|
||||
$message,
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_FAILURE,
|
||||
SystemLog::TYPE_FORTE,
|
||||
$this->client,
|
||||
$this->client->company,
|
||||
);
|
||||
|
||||
return [
|
||||
'transaction_reference' => $payment->transaction_reference,
|
||||
'transaction_response' => $response,
|
||||
'success' => false,
|
||||
'description' => $payment->paymentables,
|
||||
'code' => 422,
|
||||
];
|
||||
}
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$message,
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_SUCCESS,
|
||||
SystemLog::TYPE_FORTE,
|
||||
$this->client,
|
||||
$this->client->company,
|
||||
);
|
||||
|
||||
return [
|
||||
'transaction_reference' => $payment->transaction_reference,
|
||||
'transaction_response' => $response,
|
||||
'success' => $response->response->response_code == 'A01' ? true : false,
|
||||
'description' => $payment->paymentables,
|
||||
'code' => $httpcode,
|
||||
];
|
||||
}
|
||||
|
||||
// public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
||||
// {
|
||||
// return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here
|
||||
// return $this->payment_method->yourTokenBillingImplmentation();
|
||||
// }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user