1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Pay with CC paytrace

This commit is contained in:
David Bomba 2021-07-21 17:44:35 +10:00
parent 211e6560fc
commit 1affdd7754
3 changed files with 28 additions and 15 deletions

View File

@ -479,7 +479,7 @@ class BaseDriver extends AbstractPaymentDriver
$this->client->company,
);
throw new PaymentFailed($error, $error_code);
throw new PaymentFailed($error, 500);
}

View File

@ -17,6 +17,7 @@ use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType;
@ -168,10 +169,12 @@ class CreditCard
//process a regular charge here:
$data = [
'hpf_token' => $data['HPF_Token'],
'enc_key' => $data['enc_key'],
'hpf_token' => $response_array['HPF_Token'],
'enc_key' => $response_array['enc_key'],
'integrator_id' => '959195xd1CuC',
'billing_address' => $this->buildBillingAddress(),
'amount' => $request->input('amount_with_fee'),
'invoice_id' => $this->harvestInvoiceId(),
];
$response = $this->paytrace_driver->gatewayRequest('/v1/transactions/sale/pt_protect', $data);
@ -202,13 +205,22 @@ class CreditCard
return $this->processUnsuccessfulPayment($response);
}
private function harvestInvoiceId()
{
$_invoice = collect($this->paytrace_driver->payment_hash->data->invoices)->first();
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id));
if($invoice)
return ctrans('texts.invoice_number') . "# " . $invoice->number;
return ctrans('texts.invoice_number') . "####";
}
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;
@ -223,8 +235,12 @@ class CreditCard
private function processUnsuccessfulPayment($response)
{
$error = $response->status_message;
if(property_exists($response, 'approval_message') && $response->approval_message)
$error .= " - {$response->approval_message}";
$error_code = property_exists($response, 'approval_message') ? $response->approval_message : 'Undefined code';
$data = [
@ -234,6 +250,7 @@ class CreditCard
];
return $this->paytrace_driver->processUnsuccessfulTransaction($data);
}
}

View File

@ -15,7 +15,7 @@
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}"/>
<input type="txt" id=HPF_Token name= HPF_Token hidden>
<input type="txt" id=enc_key name= enc_key hidden>
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@ -52,14 +52,13 @@
@include('portal.ninja2020.gateways.includes.save_card')
<div class="w-screen items-center" id="paytrace--credit-card-container">
<div id='pt_hpf_form'><!--iframe sensitive data payment fields inserted here--></div>
</div>
@include('portal.ninja2020.gateways.includes.pay_now')
@include('portal.ninja2020.gateways.includes.pay_now', ['type' => 'submit'])
</form>
@endsection
@section('gateway_footer')
@ -82,9 +81,6 @@
.getElementById('token').value = e.target.dataset.token;
}));
var tokens = document.getElementsByClassName('toggle-payment-with-token');
tokens[0].click();
let payWithCreditCardToggle = document.getElementById('toggle-payment-with-credit-card');
if (payWithCreditCardToggle) {
@ -97,12 +93,12 @@
document
.getElementById('token').value = null;
token_payment = false;
});
}
var tokens = document.getElementsByClassName('toggle-payment-with-token');
tokens[0].click();
// Minimal Protect.js setup call
PTPayment.setup({