token billing and refunds with paytrace

This commit is contained in:
David Bomba 2021-07-21 18:18:14 +10:00
parent 1affdd7754
commit 78270a9147
5 changed files with 101 additions and 8 deletions

View File

@ -431,8 +431,8 @@ class BaseDriver extends AbstractPaymentDriver
return false;
}
/*Generic Global unsuccessful transaction method*/
public function processUnsuccessfulTransaction($response)
/*Generic Global unsuccessful transaction method when the client is present*/
public function processUnsuccessfulTransaction($response, $client_present = true)
{
$error = $response['error'];
$error_code = $response['error_code'];
@ -479,7 +479,9 @@ class BaseDriver extends AbstractPaymentDriver
$this->client->company,
);
throw new PaymentFailed($error, 500);
if($client_present)
throw new PaymentFailed($error, 500);
}

View File

@ -15,6 +15,7 @@ use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\PayTrace\CreditCard;
use App\Utils\CurlUtils;
@ -85,12 +86,90 @@ class PaytracePaymentDriver extends BaseDriver
public function refund(Payment $payment, $amount, $return_client_response = false)
{
return $this->payment_method->yourRefundImplementationHere(); //this is your custom implementation from here
$cgt = ClientGatewayToken::where('company_gateway_id', $payment->company_gateway_id)
->where('gateway_type_id', $payment->gateway_type_id)
->first();
$data = [
'amount' => $amount,
'customer_id' => $cgt->token,
'integrator_id' => '959195xd1CuC'
];
$response = $this->gatewayRequest('/v1/transactions/refund/to_customer', $data);
if($response && $response->success)
{
SystemLogger::dispatch(['server_response' => $response, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_PAYTRACE, $this->client, $this->client->company);
return [
'transaction_reference' => $response->transaction_id,
'transaction_response' => json_encode($response),
'success' => true,
'description' => $response->status_message,
'code' => $response->response_code,
];
}
SystemLogger::dispatch(['server_response' => $response, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_PAYTRACE, $this->client, $this->client->company);
return [
'transaction_reference' => null,
'transaction_response' => json_encode($response),
'success' => false,
'description' => $response->status_message,
'code' => 422,
];
}
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$data = [
'customer_id' => $cgt->token,
'integrator_id' => '959195xd1CuC',
'amount' => $amount,
];
$response = $this->gatewayRequest('/v1/transactions/sale/by_customer', $data);
if($response && $response->success)
{
$data = [
'gateway_type_id' => $cgt->gateway_type_id,
'payment_type' => PaymentType::CREDIT_CARD_OTHER,
'transaction_reference' => $response->transaction_id,
'amount' => $amount,
];
$payment = $this->createPayment($data);
$payment->meta = $cgt->meta;
$payment->save();
$payment_hash->payment_id = $payment->id;
$payment_hash->save();
return $payment;
}
$error = $response->status_message;
if(property_exists($response, 'approval_message') && $response->approval_message)
$error .= " - {$response->approval_message}";
$data = [
'response' => $response,
'error' => $error,
'error_code' => 500,
];
$this->processUnsuccessfulTransaction($data, false);
}
public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null)

View File

@ -74,7 +74,7 @@ class Charge
'confirm' => true,
'description' => $description,
];
nlog($data);
$response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth);
// $response = $local_stripe->paymentIntents->create($data);

View File

@ -14,7 +14,19 @@ class ActivatePaytracePaymentDriver extends Migration
*/
public function up()
{
Gateway::query()->where('id', 46)->update(['visible' => true, 'provider' => 'Paytrace']);
$paytrace = Gateway::find(46);
if($paytrace)
{
$fields = $paytrace->fields;
$fields->integratorId = "";
$paytrace->fields = $fields;
$paytrace->provider = 'Paytrace';
$paytrace->visible = true;
$paytrace->save();
}
}
/**

View File

@ -70,7 +70,7 @@ class PaymentLibrariesSeeder extends Seeder
['id' => 43, 'name' => 'Fasapay', 'provider' => 'Fasapay', 'key' => '1b2cef0e8c800204a29f33953aaf3360', 'fields' => ''],
['id' => 44, 'name' => 'Komoju', 'provider' => 'Komoju', 'key' => '7ea2d40ecb1eb69ef8c3d03e5019028a', 'fields' => '{"apiKey":"","accountId":"","paymentMethod":"credit_card","testMode":false,"locale":"en"}'],
['id' => 45, 'name' => 'Paysafecard', 'provider' => 'Paysafecard', 'key' => '70ab90cd6c5c1ab13208b3cef51c0894', 'fields' => '{"username":"","password":"","testMode":false}'],
['id' => 46, 'name' => 'Paytrace', 'provider' => 'Paytrace', 'key' => 'bbd736b3254b0aabed6ad7fda1298c88', 'fields' => '{"username":"","password":"","testMode":false,"endpoint":"https:\/\/paytrace.com\/api\/default.pay"}'],
['id' => 46, 'name' => 'Paytrace', 'provider' => 'Paytrace', 'key' => 'bbd736b3254b0aabed6ad7fda1298c88', 'fields' => '{"username":"","password":"","integratorId":"",testMode":false,"endpoint":"https:\/\/paytrace.com\/api\/default.pay"}'],
['id' => 47, 'name' => 'Secure Trading', 'provider' => 'SecureTrading', 'key' => '231cb401487b9f15babe04b1ac4f7a27', 'fields' => '{"siteReference":"","username":"","password":"","applyThreeDSecure":false,"accountType":"ECOM"}'],
['id' => 48, 'name' => 'SecPay', 'provider' => 'SecPay', 'key' => 'bad8699d581d9fa040e59c0bb721a76c', 'fields' => '{"mid":"","vpnPswd":"","remotePswd":"","usageType":"","confirmEmail":"","testStatus":"true","mailCustomer":"true","additionalOptions":""}'],
['id' => 49, 'name' => 'WePay', 'provider' => 'WePay', 'is_offsite' => false, 'sort_order' => 3, 'key' => '8fdeed552015b3c7b44ed6c8ebd9e992', 'fields' => '{"accountId":"","accessToken":"","type":"goods","testMode":false,"feePayer":"payee"}'],