1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Working on token billing

This commit is contained in:
David Bomba 2020-07-13 14:46:16 +10:00
parent 583a92d5bc
commit 5dc0fcca0d
4 changed files with 36 additions and 16 deletions

View File

@ -72,17 +72,17 @@ class UpdatePaymentRequest extends Request
unset($input['amount']);
}
if (isset($input['type_id'])) {
unset($input['type_id']);
}
// if (isset($input['type_id'])) {
// unset($input['type_id']);
// }
if (isset($input['date'])) {
unset($input['date']);
}
// if (isset($input['date'])) {
// unset($input['date']);
// }
if (isset($input['transaction_reference'])) {
unset($input['transaction_reference']);
}
// if (isset($input['transaction_reference'])) {
// unset($input['transaction_reference']);
// }
if (isset($input['number'])) {
unset($input['number']);

View File

@ -254,7 +254,6 @@ class CompanyGateway extends BaseModel
$fee += $pre_tax_fee * $this->fee_tax_rate2 / 100;
}
return $fee;
}

View File

@ -102,6 +102,18 @@ class AuthorizeCreditCard
private function tokenBilling($cgt, $amount, $invoice)
{
$data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amounts);
if($data['response'] != null && $data['response']->getMessages()->getResultCode() == "Ok") {
$payment = $this->createPaymentRecord($data, $amount);
$this->authorize->attachInvoices($payment, $invoice->hashed_id);
//up to here
}
else {
}
}
@ -115,10 +127,11 @@ class AuthorizeCreditCard
return $this->processFailedResponse($data, $request);
}
private function processSuccessfulResponse($data, $request)
private function createPaymentRecord($data, $amount) :?Payment
{
$response = $data['response'];
//create a payment record and fire notifications and then return
//create a payment record
$payment = PaymentFactory::create($this->authorize->client->company_id, $this->authorize->client->user_id);
$payment->client_id = $this->authorize->client->id;
@ -129,11 +142,18 @@ class AuthorizeCreditCard
$payment->currency_id = $this->authorize->client->getSetting('currency_id');
$payment->date = Carbon::now();
$payment->transaction_reference = $response->getTransactionResponse()->getTransId();
$payment->amount = $request->input('amount_with_fee');
$payment->amount = $amount;
$payment->currency_id = $this->authorize->client->getSetting('currency_id');
$payment->client->getNextPaymentNumber($this->authorize->client);
$payment->save();
return $payment;
}
private function processSuccessfulResponse($data, $request)
{
$payment = $this->createPaymentRecord($data, $request->input('amount_with_fee'));
$this->authorize->attachInvoices($payment, $request->hashed_ids);
$payment->service()->updateInvoicePayment();

View File

@ -59,10 +59,11 @@ class AutoBillInvoice extends AbstractService
$amount = $this->invoice->balance + $fee;
}
/* Make sure we remove any stale fees*/
$this->purgeStaleGatewayFees();
if($fee > 0)
$this->purgeStaleGatewayFees()->addFeeToInvoice($fee);
$this->addFeeToInvoice($fee);
$response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);