mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Working on token payments with Authorize.net
This commit is contained in:
parent
2d2a5c0812
commit
2ffe799c04
@ -36,6 +36,7 @@ class SystemLog extends Model
|
||||
const TYPE_LEDGER = 302;
|
||||
const TYPE_FAILURE = 303;
|
||||
const TYPE_CHECKOUT = 304;
|
||||
const TYPE_AUTHORIZE = 305;
|
||||
|
||||
const TYPE_QUOTA_EXCEEDED = 400;
|
||||
const TYPE_UPSTREAM_FAILURE = 401;
|
||||
|
@ -12,12 +12,15 @@
|
||||
|
||||
namespace App\PaymentDrivers\Authorize;
|
||||
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\PaymentDrivers\AuthorizePaymentDriver;
|
||||
use App\PaymentDrivers\Authorize\AuthorizeCreateCustomer;
|
||||
use App\PaymentDrivers\Authorize\ChargePaymentProfile;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Class AuthorizeCreditCard
|
||||
@ -79,11 +82,41 @@ class AuthorizeCreditCard
|
||||
{
|
||||
$client_gateway_token = ClientGatewayToken::find($this->decodePrimaryKey($request->token));
|
||||
|
||||
$response = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($client_gateway_token->gateway_customer_reference, $client_gateway_token->token, $request->input('amount'));
|
||||
|
||||
$data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($client_gateway_token->gateway_customer_reference, $client_gateway_token->token, $request->input('amount'));
|
||||
|
||||
$this->handleResponse($data, $request);
|
||||
}
|
||||
|
||||
private function handleResponse($response)
|
||||
private function handleResponse($data, $request)
|
||||
{
|
||||
//info(print_r( $response->getTransactionResponse()->getMessages(),1));
|
||||
|
||||
$response = $data['response'];
|
||||
|
||||
if($response != null && $response->getMessages()->getResultCode() == "Ok")
|
||||
return $this->processSuccessfulResponse($data, $request);
|
||||
|
||||
return $this->processFailedResponse($data, $request);
|
||||
}
|
||||
|
||||
private function processSuccessfulResponse($data, $request)
|
||||
{
|
||||
//create a payment record and fire notifications and then return
|
||||
|
||||
$payment = PaymentFactory::create($this->authorize->client->company_id, $this->authorize->client->user_id);
|
||||
$payment->client_id = $this->client->id;
|
||||
$payment->company_gateway_id = $this->authorize->company_gateway->id;
|
||||
$payment->status_id = Payment::STATUS_PAID;
|
||||
$payment->currency_id = $this->authorize->client->getSetting('currency_id');
|
||||
$payment->date = Carbon::now();
|
||||
|
||||
$this->authorize->attachInvoices($payment, $request->hashed_ids);
|
||||
|
||||
return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
|
||||
|
||||
}
|
||||
|
||||
private function processFailedResponse($data)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -70,8 +70,14 @@ class ChargePaymentProfile
|
||||
info( "Charge Customer Profile APPROVED :" );
|
||||
info(" Charge Customer Profile AUTH CODE : " . $tresponse->getAuthCode() );
|
||||
info(" Charge Customer Profile TRANS ID : " . $tresponse->getTransId() );
|
||||
info(" Code : " . $tresponse->getMessages()[0]->getCode());
|
||||
info(" Description : " . $tresponse->getMessages()[0]->getDescription());
|
||||
//info(" Charge Customer Profile TRANS STATUS : " . $tresponse->getTransactionStatus() );
|
||||
//info(" Charge Customer Profile Amount : " . $tresponse->getAuthAmount());
|
||||
|
||||
info(" Code : " . $tresponse->getMessages()[0]->getCode() );
|
||||
info(" Description : " . $tresponse->getMessages()[0]->getDescription() );
|
||||
info(print_r($tresponse->getMessages()[0],1));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -80,6 +86,7 @@ class ChargePaymentProfile
|
||||
{
|
||||
info(" Error code : " . $tresponse->getErrors()[0]->getErrorCode() );
|
||||
info(" Error message : " . $tresponse->getErrors()[0]->getErrorText() );
|
||||
info(print_r($tresponse->getErrors()[0],1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,6 +98,7 @@ class ChargePaymentProfile
|
||||
{
|
||||
info(" Error code : " . $tresponse->getErrors()[0]->getErrorCode() );
|
||||
info(" Error message : " . $tresponse->getErrors()[0]->getErrorText() );
|
||||
info(print_r($tresponse->getErrors()[0],1));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -99,7 +107,13 @@ class ChargePaymentProfile
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
return [
|
||||
'response' => $response,
|
||||
'amount' => $amount,
|
||||
'profile_id' => $profile_id,
|
||||
'payment_profile_id' => $payment_profile_id
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,8 @@ namespace App\PaymentDrivers;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\PaymentDrivers\AbstractPaymentDriver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
@ -94,5 +96,25 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
*/
|
||||
public function setPaymentMethod($payment_method_id){}
|
||||
|
||||
/**
|
||||
* Helper method to attach invoices to a payment
|
||||
*
|
||||
* @param Payment $payment The payment
|
||||
* @param array $hashed_ids The array of invoice hashed_ids
|
||||
* @return Payment The payment object
|
||||
*/
|
||||
public function attachInvoices(Payment $payment, $hashed_ids): Payment
|
||||
{
|
||||
$transformed = $this->transformKeys($hashed_ids);
|
||||
$array = is_array($transformed) ? $transformed : [$transformed];
|
||||
|
||||
$invoices = Invoice::whereIn('id', $array)
|
||||
->whereClientId($this->client->id)
|
||||
->get();
|
||||
|
||||
$payment->invoices()->sync($invoices);
|
||||
$payment->save();
|
||||
|
||||
return $payment;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user