mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Paytrace payment proces
This commit is contained in:
parent
15dd0970d2
commit
211e6560fc
@ -431,6 +431,59 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Generic Global unsuccessful transaction method*/
|
||||||
|
public function processUnsuccessfulTransaction($response)
|
||||||
|
{
|
||||||
|
$error = $response['error'];
|
||||||
|
$error_code = $response['error_code'];
|
||||||
|
|
||||||
|
$this->unWindGatewayFees($this->payment_hash);
|
||||||
|
|
||||||
|
PaymentFailureMailer::dispatch($this->client, $error, $this->client->company, $this->payment_hash->data->amount_with_fee);
|
||||||
|
|
||||||
|
$nmo = new NinjaMailerObject;
|
||||||
|
$nmo->mailable = new NinjaMailer( (new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build() );
|
||||||
|
$nmo->company = $this->client->company;
|
||||||
|
$nmo->settings = $this->client->company->settings;
|
||||||
|
|
||||||
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
|
||||||
|
|
||||||
|
$invoices->each(function ($invoice){
|
||||||
|
|
||||||
|
$invoice->service()->deletePdf();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$invoices->first()->invitations->each(function ($invitation) use ($nmo){
|
||||||
|
|
||||||
|
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||||
|
|
||||||
|
$nmo->to_user = $invitation->contact;
|
||||||
|
NinjaMailerJob::dispatch($nmo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$message = [
|
||||||
|
'server_response' => $response,
|
||||||
|
'data' => $this->payment_hash->data,
|
||||||
|
];
|
||||||
|
|
||||||
|
SystemLogger::dispatch(
|
||||||
|
$message,
|
||||||
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||||
|
SystemLog::EVENT_GATEWAY_FAILURE,
|
||||||
|
$this::SYSTEM_LOG_TYPE,
|
||||||
|
$this->client,
|
||||||
|
$this->client->company,
|
||||||
|
);
|
||||||
|
|
||||||
|
throw new PaymentFailed($error, $error_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function checkRequirements()
|
public function checkRequirements()
|
||||||
{
|
{
|
||||||
if ($this->company_gateway->require_billing_address) {
|
if ($this->company_gateway->require_billing_address) {
|
||||||
|
@ -48,24 +48,23 @@ class CreditCard
|
|||||||
return render('gateways.paytrace.authorize', $data);
|
return render('gateways.paytrace.authorize', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// +"success": true
|
||||||
|
// +"response_code": 160
|
||||||
|
// +"status_message": "The customer profile for PLS5U60OoLUfQXzcmtJYNefPA0gTthzT/11 was successfully created."
|
||||||
|
// +"customer_id": "PLS5U60OoLUfQXzcmtJYNefPA0gTthzT"
|
||||||
|
|
||||||
|
//if(!$response->success)
|
||||||
|
//handle failure
|
||||||
|
|
||||||
public function authorizeResponse($request)
|
public function authorizeResponse($request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
|
||||||
$post_data = [
|
$response = $this->createCustomer($data);
|
||||||
'customer_id' => Str::random(32),
|
|
||||||
'hpf_token' => $data['HPF_Token'],
|
return redirect()->route('client.payment_methods.index');
|
||||||
'enc_key' => $data['enc_key'],
|
|
||||||
'integrator_id' => '959195xd1CuC',
|
}
|
||||||
'billing_address' => [
|
|
||||||
'name' => $this->paytrace_driver->client->present()->name(),
|
|
||||||
'street_address' => $this->paytrace_driver->client->address1,
|
|
||||||
'city' => $this->paytrace_driver->client->city,
|
|
||||||
'state' => $this->paytrace_driver->client->state,
|
|
||||||
'zip' => $this->paytrace_driver->client->postal_code
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
// "_token" => "Vl1xHflBYQt9YFSaNCPTJKlY5x3rwcFE9kvkw71I"
|
// "_token" => "Vl1xHflBYQt9YFSaNCPTJKlY5x3rwcFE9kvkw71I"
|
||||||
// "company_gateway_id" => "1"
|
// "company_gateway_id" => "1"
|
||||||
@ -87,18 +86,19 @@ class CreditCard
|
|||||||
// "state":"WA",
|
// "state":"WA",
|
||||||
// "zip":"85284"
|
// "zip":"85284"
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
private function createCustomer($data)
|
||||||
|
{
|
||||||
|
$post_data = [
|
||||||
|
'customer_id' => Str::random(32),
|
||||||
|
'hpf_token' => $data['HPF_Token'],
|
||||||
|
'enc_key' => $data['enc_key'],
|
||||||
|
'integrator_id' => '959195xd1CuC',
|
||||||
|
'billing_address' => $this->buildBillingAddress(),
|
||||||
|
];
|
||||||
|
|
||||||
$response = $this->paytrace_driver->gatewayRequest('/v1/customer/pt_protect_create', $post_data);
|
$response = $this->paytrace_driver->gatewayRequest('/v1/customer/pt_protect_create', $post_data);
|
||||||
|
|
||||||
// dd($response);
|
|
||||||
|
|
||||||
// +"success": true
|
|
||||||
// +"response_code": 160
|
|
||||||
// +"status_message": "The customer profile for PLS5U60OoLUfQXzcmtJYNefPA0gTthzT/11 was successfully created."
|
|
||||||
// +"customer_id": "PLS5U60OoLUfQXzcmtJYNefPA0gTthzT"
|
|
||||||
|
|
||||||
// if(!$response->success)
|
|
||||||
//handle failure
|
|
||||||
|
|
||||||
$cgt = [];
|
$cgt = [];
|
||||||
$cgt['token'] = $response->customer_id;
|
$cgt['token'] = $response->customer_id;
|
||||||
$cgt['payment_method_id'] = GatewayType::CREDIT_CARD;
|
$cgt['payment_method_id'] = GatewayType::CREDIT_CARD;
|
||||||
@ -116,13 +116,9 @@ class CreditCard
|
|||||||
|
|
||||||
$token = $this->paytrace_driver->storeGatewayToken($cgt, []);
|
$token = $this->paytrace_driver->storeGatewayToken($cgt, []);
|
||||||
|
|
||||||
|
return $response;
|
||||||
// make a cc card out of that bra
|
|
||||||
return redirect()->route('client.payment_methods.index');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function getCustomerProfile($customer_id)
|
private function getCustomerProfile($customer_id)
|
||||||
{
|
{
|
||||||
$profile = $this->paytrace_driver->gatewayRequest('/v1/customer/export', [
|
$profile = $this->paytrace_driver->gatewayRequest('/v1/customer/export', [
|
||||||
@ -135,50 +131,59 @@ class CreditCard
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildBillingAddress()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->paytrace_driver->client->present()->name(),
|
||||||
|
'street_address' => $this->paytrace_driver->client->address1,
|
||||||
|
'city' => $this->paytrace_driver->client->city,
|
||||||
|
'state' => $this->paytrace_driver->client->state,
|
||||||
|
'zip' => $this->paytrace_driver->client->postal_code
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function paymentView($data)
|
public function paymentView($data)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data['client_key'] = $this->paytrace_driver->getAuthToken();
|
$data['client_key'] = $this->paytrace_driver->getAuthToken();
|
||||||
$data['gateway'] = $this->paytrace_driver;
|
$data['gateway'] = $this->paytrace_driver;
|
||||||
|
|
||||||
//do i store the card?
|
|
||||||
//
|
|
||||||
//do i use a token?
|
|
||||||
//
|
|
||||||
//is it a new card?
|
|
||||||
|
|
||||||
return render('gateways.paytrace.pay', $data);
|
return render('gateways.paytrace.pay', $data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function paymentResponse(Request $request)
|
public function paymentResponse(Request $request)
|
||||||
{
|
{
|
||||||
$response_array = $request->all();
|
$response_array = $request->all();
|
||||||
|
|
||||||
if($request->token)
|
if($request->token)
|
||||||
$this->processTokenPayment($request);
|
$this->processTokenPayment($request->token, $request);
|
||||||
|
|
||||||
if ($request->has('store_card') && $request->input('store_card') === true) {
|
if ($request->has('store_card') && $request->input('store_card') === true) {
|
||||||
|
|
||||||
//create customer
|
$response = $this->createCustomer($request->all());
|
||||||
|
|
||||||
|
$this->processTokenPayment($response->customer_id, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
//process a regular charge here:
|
||||||
|
$data = [
|
||||||
|
'hpf_token' => $data['HPF_Token'],
|
||||||
|
'enc_key' => $data['enc_key'],
|
||||||
|
'integrator_id' => '959195xd1CuC',
|
||||||
|
'billing_address' => $this->buildBillingAddress(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->paytrace_driver->gatewayRequest('/v1/transactions/sale/pt_protect', $data);
|
||||||
|
|
||||||
|
if($response->success)
|
||||||
|
return $this->processSuccessfulPayment($response);
|
||||||
|
|
||||||
|
return $this->processUnsuccessfulPayment($response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// charge CC
|
public function processTokenPayment($token, $request)
|
||||||
|
|
||||||
// if($response_array['payment_status'] == 'COMPLETE') {
|
|
||||||
|
|
||||||
// $this->payfast->logSuccessfulGatewayResponse(['response' => $response_array, 'data' => $this->paytrace_driver->payment_hash], SystemLog::TYPE_PAYFAST);
|
|
||||||
|
|
||||||
// return $this->processSuccessfulPayment($response_array);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// $this->processUnsuccessfulPayment($response_array);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function processTokenPayment($request)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -198,42 +203,37 @@ class CreditCard
|
|||||||
return $this->processUnsuccessfulPayment($response);
|
return $this->processUnsuccessfulPayment($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processSuccessfulPayment($response_array)
|
private function processSuccessfulPayment($response)
|
||||||
{
|
{
|
||||||
|
$amount = array_sum(array_column($this->paytrace_driver->payment_hash->invoices(), 'amount')) + $this->paytrace_driver->payment_hash->fee_total;
|
||||||
|
|
||||||
|
$response = $response_array;
|
||||||
|
|
||||||
|
$payment_record = [];
|
||||||
|
$payment_record['amount'] = $amount;
|
||||||
|
$payment_record['payment_type'] = PaymentType::CREDIT_CARD_OTHER;
|
||||||
|
$payment_record['gateway_type_id'] = GatewayType::CREDIT_CARD;
|
||||||
|
$payment_record['transaction_reference'] = $response->transaction_id;
|
||||||
|
|
||||||
$payment = $this->paytrace_driver->createPayment($payment_record, Payment::STATUS_COMPLETED);
|
$payment = $this->paytrace_driver->createPayment($payment_record, Payment::STATUS_COMPLETED);
|
||||||
|
|
||||||
|
return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processUnsuccessfulPayment($server_response)
|
private function processUnsuccessfulPayment($response)
|
||||||
{
|
{
|
||||||
// PaymentFailureMailer::dispatch($this->paytrace_driver->client, $server_response->cancellation_reason, $this->paytrace_driver->client->company, $server_response->amount);
|
|
||||||
|
|
||||||
// PaymentFailureMailer::dispatch(
|
$error = $response->status_message;
|
||||||
// $this->paytrace_driver->client,
|
$error_code = property_exists($response, 'approval_message') ? $response->approval_message : 'Undefined code';
|
||||||
// $server_response,
|
|
||||||
// $this->paytrace_driver->client->company,
|
|
||||||
// $server_response['amount_gross']
|
|
||||||
// );
|
|
||||||
|
|
||||||
// $message = [
|
$data = [
|
||||||
// 'server_response' => $server_response,
|
'response' => $response,
|
||||||
// 'data' => $this->paytrace_driver->payment_hash->data,
|
'error' => $error,
|
||||||
// ];
|
'error_code' => $error_code,
|
||||||
|
];
|
||||||
|
|
||||||
// SystemLogger::dispatch(
|
return $this->paytrace_driver->processUnsuccessfulTransaction($data);
|
||||||
// $message,
|
|
||||||
// SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
||||||
// SystemLog::EVENT_GATEWAY_FAILURE,
|
|
||||||
// SystemLog::TYPE_PAYFAST,
|
|
||||||
// $this->payfast->client,
|
|
||||||
// $this->payfast->client->company,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// throw new PaymentFailed('Failed to process the payment.', 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user